-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(views): replace utils with views
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
Showing
3 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |