Newer
Older
from django.http import Http404
from django.views.generic import ListView, DetailView
from AKModel.models import AK, AKType, AKTag
from AKModel.views import FilterByEventSlugMixin
from django.utils.translation import gettext_lazy as _
class SubmissionOverviewView(FilterByEventSlugMixin, ListView):
model = AK
context_object_name = "AKs"
template_name = "AKSubmission/submission_overview.html"
ordering = ["type"]
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class AKDetailView(DetailView):
model = AK
context_object_name = "ak"
template_name = "AKSubmission/ak_detail.html"
class AKListView(FilterByEventSlugMixin, ListView):
model = AK
context_object_name = "AKs"
template_name = "AKSubmission/ak_list.html"
filter_condition_string = ""
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs)
context["types"] = AKType.objects.all()
context["tags"] = AKTag.objects.all()
context["filter_condition_string"] = self.filter_condition_string
return context
class AKListByTypeView(AKListView):
type = None
def get_queryset(self):
# Find type based on event slug
try:
self.type = AKType.objects.get(pk=self.kwargs['type_pk'])
self.filter_condition_string = f"{_('Type')} = {self.type.name}"
except AKType.DoesNotExist:
raise Http404
return super().get_queryset().filter(type=self.type)
class AKListByTagView(AKListView):
tag = None
def get_queryset(self):
# Find type based on event slug
try:
self.tag = AKTag.objects.get(pk=self.kwargs['tag_pk'])
self.filter_condition_string = f"{_('Tag')} = {self.tag.name}"
except AKTag.DoesNotExist:
raise Http404
return super().get_queryset().filter(tags=self.tag)