Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved internalportal to separate app #771

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added internalportal/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions internalportal/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class InternalportalConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "internalportal"
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<div class="row">
<div class="col s12">
<h4>{% trans "Internportal" %}</h4>
<p>{{ greeting }}</p>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions internalportal/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path

from . import views

app_name = "internalportal"

urlpatterns = [
path("", views.InternalPortalView.as_view(), name="internalportal"),
]
33 changes: 33 additions & 0 deletions internalportal/views.py
Original file line number Diff line number Diff line change
@@ -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
12 changes: 1 addition & 11 deletions website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"social_django",
"inventory",
"watchlist",
"internalportal",
"projectarchive",
"markdownx",
"django_crontab",
Expand Down Expand Up @@ -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 #
#################################
Expand Down
4 changes: 2 additions & 2 deletions website/templates/website/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
</li>
{% if user.is_authenticated and perms.userprofile.is_active_member %}
<li>
<a class="waves-effect" href="{% url 'internalportal' %}">
<a class="waves-effect" href="{% url 'internalportal:internalportal' %}">
<i class="material-icons">dashboard</i>{% trans "Internportal" %}
</a>
</li>
Expand Down Expand Up @@ -230,7 +230,7 @@
</li>
{% if user.is_authenticated and perms.userprofile.is_active_member %}
<li class="tooltipped" data-position="left" data-tooltip="{% trans "Dashbord for medlemmer av Hackerspace" %}">
<a href="{% url 'internalportal' %}">
<a href="{% url 'internalportal:internalportal' %}">
<i class="material-icons small">dashboard</i>{% trans "Internportal" %}
</a>
</li>
Expand Down
3 changes: 1 addition & 2 deletions website/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
AcceptTosView,
AdminView,
IndexView,
InternalPortalView,
RuleDetailsView,
RulesView,
)
Expand Down Expand Up @@ -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")),
]
Expand Down
40 changes: 0 additions & 40 deletions website/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
Loading