Source code for superdjango.contrib.releases.views

# Imports

from django.conf import settings
from django.urls import reverse, NoReverseMatch
from django.utils.translation import gettext_lazy as _
from superdjango.conf import SUPERDJANGO
from superdjango.patterns import PATTERN_VERSION
from superdjango.views import AccessMixin, BreadcrumbsMixin, TemplateView, ViewSet
from .library.releases import factory, get_releases

# Mixins


[docs]class LoginMayBeRequiredMixin(AccessMixin): """An authenticated user may or may not be required.""" login_required = SUPERDJANGO.SUPPORT_REQUIRES_LOGIN
# Views
[docs]class ReleaseIndex(BreadcrumbsMixin, LoginMayBeRequiredMixin, TemplateView): """Display a list of release information.""" pattern_name = "release_index" pattern_value = "" template_name = "releases/release_index.html"
[docs] def get_base_template(self): """Use support base if installed.""" if "superdjango.contrib.support.apps.DefaultConfig" in settings.INSTALLED_APPS: return "support/support_base.html" return "base.html"
[docs] def get_breadcrumbs(self): crumbs = super().get_breadcrumbs() try: url = reverse("support_home") crumbs.add(_("Help"), url) except NoReverseMatch: pass crumbs.add(_("Releases"), reverse("release_index")) return crumbs
[docs] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['releases'] = get_releases() return context
[docs]class ReleaseDetail(BreadcrumbsMixin, LoginMayBeRequiredMixin, TemplateView): """Display information regarding a specific release.""" pattern_name = "release_detail" pattern_value = "%s/" % PATTERN_VERSION template_name = "releases/release_detail.html"
[docs] def get_base_template(self): """Use support base if installed.""" if "superdjango.contrib.support.apps.DefaultConfig" in settings.INSTALLED_APPS: return "support/support_base.html" return "base.html"
[docs] def get_breadcrumbs(self): crumbs = super().get_breadcrumbs() try: url = reverse("support_home") crumbs.add(_("Help"), url) except NoReverseMatch: pass crumbs.add(_("Releases"), reverse("release_index")) crumbs.add(self.kwargs['slug'], "") return crumbs
[docs] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['releases'] = factory(self.kwargs['slug']) return context
# View Sets
[docs]class ReleasesViewSet(ViewSet): views = [ ReleaseDetail, ReleaseIndex, ]