Skip to content

Commit

Permalink
migrate a handful of core views to django_twc_toolbox.views (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuadavidthomas authored Aug 2, 2024
1 parent 817d53f commit 6d5be3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Changed

- Now using `django_twc_toolbox.views` for some core views. See the removed section below.

### Fixed

- Fixed reference to correct `lock` command in `just docs upgrade` just command.
- Changed the `default-app` build target from `app` to `dev`. This fixes an error running the stack in development where the worker container does not have the development dependencies installed.

### Removed

- Removed all views except the `index` view from the template project's `core/views.py`, in favor of `django_twc_toolbox.views`.

## [2024.40]

### Changed
Expand Down
31 changes: 0 additions & 31 deletions src/django_twc_project/{{ module_name }}/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,9 @@
from django.http import HttpRequest
from django.http import HttpResponse
from django.shortcuts import render
from django.utils import timezone
from django.views.decorators.cache import cache_control
from django.views.decorators.http import require_GET


def custom_error_404(
request: HttpRequest, exception: Exception | None = None, *args, **kwargs
) -> HttpResponse:
return render(request, "404.html", context={}, status=404)


def custom_error_500(request: HttpRequest, *args, **kwargs) -> HttpResponse:
return render(request, "500.html", context={}, status=500)


@require_GET
@cache_control(max_age=60 * 60 * 24, immutable=True, public=True) # one day
def robots_txt(request: HttpRequest) -> HttpResponse:
return render(request, "robots.txt", content_type="text/plain")


@require_GET
@cache_control(max_age=60 * 60 * 24, immutable=True, public=True) # one day
def security_txt(request: HttpRequest) -> HttpResponse:
return render(
request,
".well-known/security.txt",
context={
"year": timezone.now().year + 1,
},
content_type="text/plain",
)


@require_GET
@login_required
def index(request: HttpRequest) -> HttpResponse:
Expand Down
13 changes: 7 additions & 6 deletions src/django_twc_project/{{ module_name }}/urls.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from django.conf import settings
from django.contrib import admin
from django.urls import include
from django.urls import path
from django_twc_toolbox import views as toolbox_views
from health_check.views import MainView

from {{ module_name }} import __version__
Expand All @@ -15,19 +16,19 @@ admin.site.site_header = admin_header
admin.site.site_title = admin_header

urlpatterns = [
path(".well-known/security.txt", core_views.security_txt),
path("robots.txt", core_views.robots_txt),
path(".well-known/security.txt", toolbox_views.security_txt),
path("robots.txt", toolbox_views.robots_txt),
path("", include("django_twc_ui.favicons.urls")),
path("404/", core_views.custom_error_404, name="404"),
path("500/", core_views.custom_error_500, name="500"),
path("404/", toolbox_views.custom_error_404, name="404"),
path("500/", toolbox_views.custom_error_500, name="500"),
path("accounts/", include("allauth.urls")),
path("admin/", admin.site.urls),
path("health/", MainView.as_view()),
path("", core_views.index, name="index"),
]

handler404 = "{{ module_name }}.core.views.custom_error_404" # noqa: F811
handler500 = "{{ module_name }}.core.views.custom_error_500" # noqa: F811
handler404 = "django_twc_toolbox.views.custom_error_404" # noqa: F811
handler500 = "django_twc_toolbox.views.custom_error_500" # noqa: F811


if settings.DEBUG:
Expand Down

0 comments on commit 6d5be3a

Please sign in to comment.