Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from django.conf import settings
4from django.urls import reverse, NoReverseMatch
5from django.utils.translation import gettext_lazy as _
6from superdjango.conf import SUPERDJANGO
7from superdjango.patterns import PATTERN_VERSION
8from superdjango.views import AccessMixin, BreadcrumbsMixin, TemplateView, ViewSet
9from .library.releases import factory, get_releases
11# Mixins
14class LoginMayBeRequiredMixin(AccessMixin):
15 """An authenticated user may or may not be required."""
16 login_required = SUPERDJANGO.SUPPORT_REQUIRES_LOGIN
18# Views
21class ReleaseIndex(BreadcrumbsMixin, LoginMayBeRequiredMixin, TemplateView):
22 """Display a list of release information."""
23 pattern_name = "release_index"
24 pattern_value = ""
25 template_name = "releases/release_index.html"
27 def get_base_template(self):
28 """Use support base if installed."""
29 if "superdjango.contrib.support.apps.DefaultConfig" in settings.INSTALLED_APPS:
30 return "support/support_base.html"
32 return "base.html"
34 def get_breadcrumbs(self):
35 crumbs = super().get_breadcrumbs()
37 try:
38 url = reverse("support_home")
39 crumbs.add(_("Help"), url)
40 except NoReverseMatch:
41 pass
43 crumbs.add(_("Releases"), reverse("release_index"))
45 return crumbs
47 def get_context_data(self, **kwargs):
48 context = super().get_context_data(**kwargs)
50 context['releases'] = get_releases()
52 return context
55class ReleaseDetail(BreadcrumbsMixin, LoginMayBeRequiredMixin, TemplateView):
56 """Display information regarding a specific release."""
57 pattern_name = "release_detail"
58 pattern_value = "%s/" % PATTERN_VERSION
59 template_name = "releases/release_detail.html"
61 def get_base_template(self):
62 """Use support base if installed."""
63 if "superdjango.contrib.support.apps.DefaultConfig" in settings.INSTALLED_APPS:
64 return "support/support_base.html"
66 return "base.html"
68 def get_breadcrumbs(self):
69 crumbs = super().get_breadcrumbs()
71 try:
72 url = reverse("support_home")
73 crumbs.add(_("Help"), url)
74 except NoReverseMatch:
75 pass
77 crumbs.add(_("Releases"), reverse("release_index"))
78 crumbs.add(self.kwargs['slug'], "")
80 return crumbs
82 def get_context_data(self, **kwargs):
83 context = super().get_context_data(**kwargs)
85 context['releases'] = factory(self.kwargs['slug'])
87 return context
90# View Sets
93class ReleasesViewSet(ViewSet):
94 views = [
95 ReleaseDetail,
96 ReleaseIndex,
97 ]