Skip to content

Commit

Permalink
#1 remove custom app
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal committed Sep 24, 2023
1 parent 88adb22 commit 4ab5d13
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 51 deletions.
46 changes: 0 additions & 46 deletions src/siteplan/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,9 @@ def update_settings_from_module(settings, module):
return settings

class App(object):
def __init__(self, conf, urls=None):
self.urls = urls
base_conf = update_settings_from_module({}, "siteplan.settings")

default_conf = {
"ALLOWED_HOSTS": [

],
"DEBUG": True,
"ROOT_URLCONF": "siteplan.urls",
"STATIC_ROOT": os.path.join(os.getcwd(), "public"),
"STATICFILES_DIRS": [
os.path.join(os.getcwd(), "static"),
],
"STATIC_URL": "/static/",
"TEMPLATES": [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(os.getcwd(), "templates"),
],
"APP_DIRS": True,
}
],
}

default_conf.update(conf)
base_conf.update(default_conf)

if not settings.configured:
settings.configure(**base_conf)



def __call__(self, environ, start_response):
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
import siteplan.urls
from django.urls import path
from django.contrib import admin
base_patterns = [
path('admin/', admin.site.urls),
]

if self.urls is not None:
urlpatterns = self.urls + base_patterns
else:
urlpatterns = base_patterns
siteplan.urls.urlpatterns = urlpatterns
return application(environ, start_response)


Expand Down
9 changes: 7 additions & 2 deletions src/siteplan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
@click.pass_context
@click.option('--debug/--no-debug', default=False)
@click.option('--app', default=None)
def cli(ctx, debug=False, app=None):
@click.option('--settings', default="siteplan.settings")
def cli(ctx, debug=False, app=None, settings=None):
sys.path.insert(0, os.getcwd())
ctx.ensure_object(dict)
if app is not None:
app = gunicorn.util.import_app(app)
print("Got custom app,", app)
else:
app = App({})
app = App()

ctx.obj["siteplan_app"] = app
ctx.obj["siteplan_settings"] = settings
click.echo(debug)

@cli.command(
Expand All @@ -38,6 +40,8 @@ def manage(ctx, manage_args):
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc

os.environ["DJANGO_SETTINGS_MODULE"] = ctx.obj["siteplan_settings"]
execute_from_command_line(["manage"] + list(manage_args))


Expand All @@ -48,6 +52,7 @@ def manage(ctx, manage_args):
@click.pass_context
def run(ctx, address, serve_static=False, reload_=False):
from .server import run as server_run
os.environ["DJANGO_SETTINGS_MODULE"] = ctx.obj["siteplan_settings"]
return server_run(ctx.obj["siteplan_app"], address, serve_static, reload_)


Expand Down
9 changes: 6 additions & 3 deletions src/siteplan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand Down Expand Up @@ -49,12 +51,14 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'test.urls'
ROOT_URLCONF = 'siteplan.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
"DIRS": [
os.path.join(os.getcwd(), "templates"),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand All @@ -80,7 +84,6 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

Expand Down

0 comments on commit 4ab5d13

Please sign in to comment.