Skip to content

Commit 5943858

Browse files
authored
Merge pull request #770 from MetaCell/feature/ch-59
CH-59 Update/Refactor the django application template
2 parents e76fc02 + e11608f commit 5943858

36 files changed

Lines changed: 438 additions & 129 deletions

File tree

application-templates/django-app/api/templates/main.jinja2

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ from fastapi.staticfiles import StaticFiles
1414

1515
{{imports | replace(".","openapi.")}}
1616

17-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "__APP_NAME__.settings")
17+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_baseapp.settings")
1818
apps.populate(settings.INSTALLED_APPS)
1919

2020
# migrate the Django models
2121
os.system("python manage.py migrate")
2222

23-
from api.controllers import *
23+
from __APP_NAME__.controllers import *
2424

2525
app = FastAPI(
2626
{% if info %}
@@ -66,10 +66,12 @@ async def add_process_time_header(request: Request, call_next):
6666

6767
if os.environ.get('KUBERNETES_SERVICE_HOST', None):
6868
# init the auth service when running in/for k8s
69-
from cloudharness_django.services import init_services, get_auth_service
70-
init_services()
69+
from cloudharness_django.services import init_services_in_background, get_auth_service
70+
init_services_in_background()
71+
7172
# start the kafka event listener when running in/for k8s
72-
import cloudharness_django.services.events
73+
from cloudharness_django.services.events import init_listener_in_background
74+
init_listener_in_background()
7375

7476
async def has_access():
7577
"""

application-templates/django-app/backend/api/admin.py renamed to application-templates/django-app/backend/__APP_NAME__/admin.py

File renamed without changes.

application-templates/django-app/backend/api/apps.py renamed to application-templates/django-app/backend/__APP_NAME__/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
class ApiConfig(AppConfig):
55
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'api'
6+
name = '__APP_NAME__'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import __APP_NAME__.controllers.test as test_controller

application-templates/django-app/backend/api/controllers/test.py renamed to application-templates/django-app/backend/__APP_NAME__/controllers/test.py

File renamed without changes.
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
import os
2-
31
from django.db import migrations
42

53

6-
def create_kc_client_and_roles(apps, schema_editor):
7-
if os.environ.get("KUBERNETES_SERVICE_HOST", None):
8-
# running in K8S so create the KC client and roles
9-
from cloudharness_django.services import get_auth_service, get_user_service, init_services
10-
11-
init_services()
12-
get_auth_service().create_client()
13-
get_user_service().sync_kc_users_groups()
14-
15-
164
class Migration(migrations.Migration):
175

186
dependencies = [
19-
("cloudharness_django", "0001_initial"),
7+
("django_baseapp", "0001_initial"),
208
]
219

22-
operations = [
23-
migrations.RunPython(create_kc_client_and_roles),
24-
]
10+
operations = []

application-templates/django-app/backend/api/tests.py renamed to application-templates/django-app/backend/__APP_NAME__/tests.py

File renamed without changes.
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
import mimetypes
2-
from pathlib import Path
1+
from django.shortcuts import render
32

4-
from django.conf import settings
5-
from django.http import FileResponse, HttpResponseRedirect
6-
from django.urls import reverse
7-
from django.utils._os import safe_join
8-
9-
10-
def view_404(request, exception=None):
11-
return HttpResponseRedirect(reverse("index"))
12-
13-
14-
def index(request, path=""):
15-
if path == "":
16-
path = "index.html"
17-
fullpath = Path(safe_join(settings.STATIC_ROOT, "www", path))
18-
content_type, encoding = mimetypes.guess_type(str(fullpath))
19-
content_type = content_type or "application/octet-stream"
20-
try:
21-
fullpath.open("rb")
22-
except FileNotFoundError:
23-
return index(request, "") # index.html
24-
return FileResponse(fullpath.open("rb"), content_type=content_type)
3+
# Create your views here.

application-templates/django-app/backend/api/controllers/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

application-templates/django-app/backend/api/views.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)