Skip to content

Commit

Permalink
feat: backend template (#123)
Browse files Browse the repository at this point in the history
* simplify project setup

* added common installed apps

* templates

* remove assertion

* remove duplicate settings
  • Loading branch information
SKairinos authored Jul 4, 2024
1 parent 940c41a commit 9924fee
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
53 changes: 51 additions & 2 deletions codeforlife/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_databases(base_dir: Path): # pragma: no cover
# URLs
# https://docs.djangoproject.com/en/3.2/ref/settings/#root-urlconf

ROOT_URLCONF = "src.urls"
ROOT_URLCONF = "api.urls"

# App
# https://docs.djangoproject.com/en/3.2/ref/settings/#wsgi-application
Expand Down Expand Up @@ -183,9 +183,58 @@ def get_databases(base_dir: Path): # pragma: no cover
# https://docs.djangoproject.com/en/3.2/ref/settings/#installed-apps

INSTALLED_APPS = [
"src.api",
"django.contrib.admin",
"django.contrib.admindocs",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.sites",
"django.contrib.staticfiles",
"aimmo", # TODO: remove
"game", # TODO: remove
"portal", # TODO: remove
"common", # TODO: remove
"api",
"codeforlife.user",
"corsheaders",
"rest_framework",
"django_filters",
]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/


def get_static_root(base_dir: Path):
"""Get the static root for the Django project.
Args:
base_dir: The base directory of the Django project.
Returns:
The static root for the django project.
"""
return base_dir / "static"


STATIC_URL = "/static/"

# Templates
# https://docs.djangoproject.com/en/3.2/ref/templates/

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
6 changes: 0 additions & 6 deletions codeforlife/tests/model_view_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,6 @@ def list(
"""
# pylint: enable=line-too-long

assert self._model_class.objects.difference(
self._model_class.objects.filter(
pk__in=[model.pk for model in models]
)
).exists(), "List must exclude some models for a valid test."

response: Response = self.get(
(
self._test_case.reverse_action("list", kwargs=reverse_kwargs)
Expand Down
4 changes: 2 additions & 2 deletions codeforlife/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def get_urlpatterns(
api_urls_path: str = "src.api.urls",
api_url_patterns: UrlPatterns,
include_user_urls: bool = True,
) -> UrlPatterns:
"""Generate standard url patterns for each service.
Expand Down Expand Up @@ -61,7 +61,7 @@ def get_urlpatterns(
),
path(
"api/",
include(api_urls_path),
include(api_url_patterns),
name="api",
),
]
Expand Down
23 changes: 1 addition & 22 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,7 @@

ROOT_URLCONF = "codeforlife.user.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}
DATABASES = get_databases(BASE_DIR)

if __name__ == "__main__":
import os
Expand Down

0 comments on commit 9924fee

Please sign in to comment.