mirror of
https://github.com/ae-utbm/sith.git
synced 2026-10-10 12:50:29 +00:00
TimetableTabMixin
This commit is contained in:
1 parent
ead76e49b9
commit
33289c1c04
2 files changed
+47
-4
No files matched your search
+16
-2
@@ -1,6 +1,14 @@
|
||||
import copy
|
||||
import inspect
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, LiteralString, Protocol, Unpack
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
ClassVar,
|
||||
LiteralString,
|
||||
Protocol,
|
||||
TypedDict,
|
||||
Unpack,
|
||||
)
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.template.loader import render_to_string
|
||||
@@ -12,11 +20,17 @@ if TYPE_CHECKING:
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
|
||||
class TabItem(TypedDict):
|
||||
url: str
|
||||
slug: str
|
||||
name: str
|
||||
|
||||
|
||||
class TabedViewMixin(View):
|
||||
"""Basic functions for displaying tabs in the template."""
|
||||
|
||||
current_tab: ClassVar[str | None] = None
|
||||
list_of_tabs: ClassVar[list | None] = None
|
||||
list_of_tabs: ClassVar[list[TabItem] | None] = None
|
||||
tabs_title: ClassVar[str | None] = None
|
||||
|
||||
def get_tabs_title(self):
|
||||
|
||||
+31
-2
@@ -1,18 +1,47 @@
|
||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import TemplateView
|
||||
from django.views.generic.detail import DetailView
|
||||
|
||||
from core.models import User
|
||||
from core.views import TabedViewMixin
|
||||
|
||||
|
||||
class GeneratorView(TemplateView):
|
||||
class TimetableTabsMixin(TabedViewMixin):
|
||||
tabs_title = _("Timetables")
|
||||
|
||||
def get_list_of_tabs(self):
|
||||
res = [
|
||||
{
|
||||
"url": reverse("timetable:generator"),
|
||||
"slug": "generator",
|
||||
"name": _("Generator"),
|
||||
}
|
||||
]
|
||||
if self.request.user.timetables.exists():
|
||||
res.append(
|
||||
{
|
||||
"url": reverse(
|
||||
"core:user_timetable", kwargs={"user_id": self.request.user.id}
|
||||
),
|
||||
"slug": "saved",
|
||||
"name": _("My timetables"),
|
||||
}
|
||||
)
|
||||
return res
|
||||
|
||||
|
||||
class GeneratorView(TimetableTabsMixin, TemplateView):
|
||||
template_name = "timetable/generator.jinja"
|
||||
current_tab = "generator"
|
||||
|
||||
|
||||
class UserTimetableView(UserPassesTestMixin, DetailView):
|
||||
class UserTimetableView(UserPassesTestMixin, TimetableTabsMixin, DetailView):
|
||||
model = User
|
||||
pk_url_kwarg = "user_id"
|
||||
template_name = "timetable/user_timetable.jinja"
|
||||
current_tab = "saved"
|
||||
|
||||
def test_func(self) -> bool | None:
|
||||
return self.request.user.id == self.kwargs[
|
||||
|
||||
Reference in new issue
Block a user