generated from bisco/codex-bootstrap
feat: add Django backend skeleton
This commit is contained in:
1
backend/azionelab/__init__.py
Normal file
1
backend/azionelab/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
8
backend/azionelab/asgi.py
Normal file
8
backend/azionelab/asgi.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azionelab.settings")
|
||||
|
||||
application = get_asgi_application()
|
||||
114
backend/azionelab/settings.py
Normal file
114
backend/azionelab/settings.py
Normal file
@@ -0,0 +1,114 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import dj_database_url
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
DEBUG = os.environ.get("DJANGO_DEBUG", "false").lower() == "true"
|
||||
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY")
|
||||
if not SECRET_KEY:
|
||||
if DEBUG:
|
||||
SECRET_KEY = "insecure-development-key"
|
||||
else:
|
||||
raise ImproperlyConfigured("DJANGO_SECRET_KEY must be set when DJANGO_DEBUG is false.")
|
||||
|
||||
|
||||
def csv_env(name, default=""):
|
||||
return [item.strip() for item in os.environ.get(name, default).split(",") if item.strip()]
|
||||
|
||||
|
||||
ALLOWED_HOSTS = csv_env("DJANGO_ALLOWED_HOSTS", "localhost,127.0.0.1")
|
||||
CSRF_TRUSTED_ORIGINS = csv_env("DJANGO_CSRF_TRUSTED_ORIGINS")
|
||||
CORS_ALLOWED_ORIGINS = csv_env("CORS_ALLOWED_ORIGINS")
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"rest_framework",
|
||||
"corsheaders",
|
||||
"shows",
|
||||
"bookings",
|
||||
"checkins",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "azionelab.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = "azionelab.wsgi.application"
|
||||
|
||||
DATABASES = {
|
||||
"default": dj_database_url.config(
|
||||
default=(
|
||||
f"postgres://{os.environ.get('POSTGRES_USER', 'azionelab')}:"
|
||||
f"{os.environ.get('POSTGRES_PASSWORD', 'azionelab')}"
|
||||
f"@{os.environ.get('POSTGRES_HOST', 'postgres')}:"
|
||||
f"{os.environ.get('POSTGRES_PORT', '5432')}/"
|
||||
f"{os.environ.get('POSTGRES_DB', 'azionelab')}"
|
||||
),
|
||||
conn_max_age=60,
|
||||
)
|
||||
}
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
||||
},
|
||||
{
|
||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
||||
},
|
||||
]
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
TIME_ZONE = os.environ.get("TIME_ZONE", "Europe/Rome")
|
||||
USE_I18N = True
|
||||
USE_TZ = True
|
||||
|
||||
STATIC_URL = "static/"
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
"DEFAULT_RENDERER_CLASSES": [
|
||||
"rest_framework.renderers.JSONRenderer",
|
||||
],
|
||||
"DEFAULT_PARSER_CLASSES": [
|
||||
"rest_framework.parsers.JSONParser",
|
||||
],
|
||||
}
|
||||
10
backend/azionelab/tests.py
Normal file
10
backend/azionelab/tests.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.test import SimpleTestCase
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class HealthEndpointTests(SimpleTestCase):
|
||||
def test_health_endpoint_returns_ok(self):
|
||||
response = self.client.get(reverse("health"))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(), {"status": "ok"})
|
||||
15
backend/azionelab/urls.py
Normal file
15
backend/azionelab/urls.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
|
||||
|
||||
@api_view(["GET"])
|
||||
def health(request):
|
||||
return Response({"status": "ok"})
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("api/health/", health, name="health"),
|
||||
]
|
||||
8
backend/azionelab/wsgi.py
Normal file
8
backend/azionelab/wsgi.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azionelab.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
1
backend/bookings/__init__.py
Normal file
1
backend/bookings/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
6
backend/bookings/apps.py
Normal file
6
backend/bookings/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BookingsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "bookings"
|
||||
1
backend/bookings/models.py
Normal file
1
backend/bookings/models.py
Normal file
@@ -0,0 +1 @@
|
||||
# Domain models will be added when booking behavior is implemented.
|
||||
1
backend/checkins/__init__.py
Normal file
1
backend/checkins/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
6
backend/checkins/apps.py
Normal file
6
backend/checkins/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class CheckinsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "checkins"
|
||||
1
backend/checkins/models.py
Normal file
1
backend/checkins/models.py
Normal file
@@ -0,0 +1 @@
|
||||
# Domain models will be added when check-in behavior is implemented.
|
||||
14
backend/manage.py
Normal file
14
backend/manage.py
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "azionelab.settings")
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
backend/shows/__init__.py
Normal file
1
backend/shows/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
6
backend/shows/apps.py
Normal file
6
backend/shows/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ShowsConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "shows"
|
||||
1
backend/shows/models.py
Normal file
1
backend/shows/models.py
Normal file
@@ -0,0 +1 @@
|
||||
# Domain models will be added when show management is implemented.
|
||||
Reference in New Issue
Block a user