Skip to content

Commit

Permalink
feat(views): replace utils with views
Browse files Browse the repository at this point in the history
The `utils` module is a remnant from other Django apps where it
contained additional logic. It now only contains one method for fetching
the imprint. The imprint logic is not used anywhere else, so it can be
part of its own individual view, which is a more Django standardized way
of implementing the imprint functionality.

Closes: #134
  • Loading branch information
b1rger committed Dec 5, 2024
1 parent 62ac303 commit f49ba90
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions apis_acdhch_default_settings/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.urls import path
from django.views.generic import TemplateView

from apis_acdhch_default_settings import utils
from apis_acdhch_default_settings.views import Imprint

from apis_core.apis_entities.api_views import GetEntityGeneric

Expand All @@ -25,4 +25,4 @@
)

urlpatterns.append(path("", TemplateView.as_view(template_name="base.html")))
urlpatterns.append(path("imprint", TemplateView.as_view(template_name="imprint.html", extra_context={"imprint": utils.get_imprint()}), name="imprint"))
urlpatterns.append(path("imprint", Imprint.as_view(), name="imprint"))
22 changes: 0 additions & 22 deletions apis_acdhch_default_settings/utils.py

This file was deleted.

29 changes: 29 additions & 0 deletions apis_acdhch_default_settings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import requests
import os
from django.views.generic import TemplateView
from django.views.decorators.cache import cache_page
from django.utils.decorators import method_decorator

from django.conf import settings


@method_decorator(cache_page(60 * 5), name='dispatch')
class Imprint(TemplateView):
template_name = "imprint.html"

def get_context_data(self) -> str:
ctx = super().get_context_data()
base_url = getattr(settings, "ACDH_IMPRINT_URL", "https://imprint.acdh.oeaw.ac.at/")
redmine_id = getattr(settings, "REDMINE_ID", os.getenv("SERVICE_ID", ""))

r = requests.get(f"{base_url}{redmine_id}")

if r and redmine_id:
ctx["imprint"] = r.text
else:
ctx["imprint"] = """
One of our services is currently not available. Please try it later or write
an email to acdh@oeaw.ac.at; if you are service provider, make sure that you
provided ACDH_IMPRINT_URL and REDMINE_ID.
"""
return ctx

0 comments on commit f49ba90

Please sign in to comment.