From 329648dfdafbb099186e54b946886af4a146a574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nj=C3=A5l=20Telst=C3=B8?= Date: Wed, 27 Sep 2023 22:46:33 +0200 Subject: [PATCH] Moved internalportal to separate app --- internalportal/__init__.py | 0 internalportal/apps.py | 6 +++ internalportal/migrations/__init__.py | 0 .../internalportal}/internalportal.html | 1 - internalportal/urls.py | 9 +++++ internalportal/views.py | 33 +++++++++++++++ website/settings.py | 12 +----- website/templates/website/header.html | 4 +- website/urls.py | 3 +- website/views.py | 40 ------------------- 10 files changed, 52 insertions(+), 56 deletions(-) create mode 100644 internalportal/__init__.py create mode 100644 internalportal/apps.py create mode 100644 internalportal/migrations/__init__.py rename {website/templates/website => internalportal/templates/internalportal}/internalportal.html (99%) create mode 100644 internalportal/urls.py create mode 100644 internalportal/views.py diff --git a/internalportal/__init__.py b/internalportal/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/internalportal/apps.py b/internalportal/apps.py new file mode 100644 index 000000000..f55a9a8fe --- /dev/null +++ b/internalportal/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class InternalportalConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "internalportal" diff --git a/internalportal/migrations/__init__.py b/internalportal/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/website/templates/website/internalportal.html b/internalportal/templates/internalportal/internalportal.html similarity index 99% rename from website/templates/website/internalportal.html rename to internalportal/templates/internalportal/internalportal.html index a004f8e79..9427535ed 100644 --- a/website/templates/website/internalportal.html +++ b/internalportal/templates/internalportal/internalportal.html @@ -8,7 +8,6 @@

{% trans "Internportal" %}

-

{{ greeting }}

diff --git a/internalportal/urls.py b/internalportal/urls.py new file mode 100644 index 000000000..1640ce79d --- /dev/null +++ b/internalportal/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +app_name = "internalportal" + +urlpatterns = [ + path("", views.InternalPortalView.as_view(), name="internalportal"), +] diff --git a/internalportal/views.py b/internalportal/views.py new file mode 100644 index 000000000..862ff9d3b --- /dev/null +++ b/internalportal/views.py @@ -0,0 +1,33 @@ +from datetime import datetime + +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.views.generic import TemplateView + +from inventory.models.item_loan import ItemLoan +from news.models import Article, Event + + +class InternalPortalView(PermissionRequiredMixin, TemplateView): + template_name = "internalportal/internalportal.html" + permission_required = "userprofile.is_active_member" + + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + + context["current_date"] = datetime.now() + + # Find the 5 loan apps that have gone unapproved the longest + context["loan_app_list"] = ItemLoan.objects.filter( + approver__isnull=True, + ).order_by("-loan_from")[:5] + + # Same as in the index view + context["event_list"] = Event.objects.filter(internal=True).order_by( + "-time_start" + )[:5] + + context["article_list"] = Article.objects.filter( + internal=True, draft=False + ).order_by("-pub_date")[:5] + + return context diff --git a/website/settings.py b/website/settings.py index 89218ed7c..b50fe10c0 100644 --- a/website/settings.py +++ b/website/settings.py @@ -65,6 +65,7 @@ "social_django", "inventory", "watchlist", + "internalportal", "projectarchive", "markdownx", "django_crontab", @@ -343,17 +344,6 @@ "DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",) } -# Random greetings that are displayed to the user on the internalportal page -# Just for fun. The user's first name is formatted in -INTERNALPORTAL_GREETINGS = [ - "Hei, {}", # zzz - "Heisann, {}", # zzzzzz - "Halla, {}", # zzzzzzzzzzzzzzzzz - "Og et rungende tjo-bing til deg, {}!", # real shit? - "Husket å skru av ovnen, {}?", - "Dette er en tilfeldig melding. Plukket tilfeldig, altså. Selve meldingen er ikke tilfeldig generert ved å drive å plukke bokstaver og sånt. Du skjønner hva jeg mener, {}.", - "Lorem ipsum dolor sit amet, consectetur adipiscing elit... Oi, vent, dette er jo i produksjon!", -] ################################# # Website-specific # ################################# diff --git a/website/templates/website/header.html b/website/templates/website/header.html index c0d5bd078..7d2216541 100644 --- a/website/templates/website/header.html +++ b/website/templates/website/header.html @@ -146,7 +146,7 @@ {% if user.is_authenticated and perms.userprofile.is_active_member %}
  • - + dashboard{% trans "Internportal" %}
  • @@ -230,7 +230,7 @@ {% if user.is_authenticated and perms.userprofile.is_active_member %}
  • - + dashboard{% trans "Internportal" %}
  • diff --git a/website/urls.py b/website/urls.py index a07eea354..a5fe749a4 100644 --- a/website/urls.py +++ b/website/urls.py @@ -24,7 +24,6 @@ AcceptTosView, AdminView, IndexView, - InternalPortalView, RuleDetailsView, RulesView, ) @@ -92,7 +91,7 @@ ), path("inventory/", include("inventory.urls")), path("vaktliste/", include("watchlist.urls")), - path("internalportal/", InternalPortalView.as_view(), name="internalportal"), + path("internalportal/", include("internalportal.urls")), path("projectarchive/", include("projectarchive.urls"), name="projectarchive"), path("markdownx/", include("markdownx.urls")), ] diff --git a/website/views.py b/website/views.py index c64f05081..c170b7ed7 100644 --- a/website/views.py +++ b/website/views.py @@ -1,5 +1,4 @@ from datetime import datetime -from random import randint from urllib import parse as urlparse from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin @@ -11,12 +10,10 @@ from applications.models import ApplicationPeriod from committees.models import Committee from door.models import DoorStatus -from inventory.models.item_loan import ItemLoan from news.models import Article, Event from userprofile.models import Profile, TermsOfService from .models import Card, FaqQuestion, Rule -from .settings import INTERNALPORTAL_GREETINGS class AcceptTosView(TemplateView): @@ -257,43 +254,6 @@ def get_context_data(self, **kwargs): } -class InternalPortalView(PermissionRequiredMixin, TemplateView): - template_name = "website/internalportal.html" - permission_required = "userprofile.is_active_member" - - def get_context_data(self, *args, **kwargs): - context = super().get_context_data(*args, **kwargs) - - context["current_date"] = datetime.now() - - # Random greeting for the internalportal header banner. Just for fun - greeting = INTERNALPORTAL_GREETINGS[ - randint(0, len(INTERNALPORTAL_GREETINGS) - 1) - ] - # cba doing a regex or some other fancy stuff to check if the string has formatting - # just break it till it works - try: - context["greeting"] = greeting.format(self.request.user.first_name) - except IndexError: - context["greeting"] = greeting - - # Find the 5 loan apps that have gone unapproved the longest - context["loan_app_list"] = ItemLoan.objects.filter( - approver__isnull=True, - ).order_by("-loan_from")[:5] - - # Same as in the index view - context["event_list"] = Event.objects.filter(internal=True).order_by( - "-time_start" - )[:5] - - context["article_list"] = Article.objects.filter( - internal=True, draft=False - ).order_by("-pub_date")[:5] - - return context - - def handler404(request, exception=None): return render(request, "website/404.html", status=404)