|
1 | | -from competitions.models import Competition |
2 | 1 | from django.shortcuts import render |
3 | | -from django.utils import translation |
4 | | -from django.views.generic import RedirectView, TemplateView |
5 | | - |
6 | | -from web.models import Page |
7 | | - |
8 | | - |
9 | | -class BranchSpecificTemplateMixin: |
10 | | - def get_template_names(self): |
11 | | - previous = super().get_template_names() |
12 | | - |
13 | | - if self.request.BRANCH is None: |
14 | | - return previous |
15 | | - |
16 | | - templates = [] |
17 | | - for template in previous: |
18 | | - templates.append(f"{self.request.BRANCH.identifier}/{template}") |
19 | | - templates.append(template) |
20 | | - return templates |
21 | | - |
22 | | - |
23 | | -class HomepageView(BranchSpecificTemplateMixin, TemplateView): |
24 | | - template_name = "web/homepage.html" |
25 | | - |
26 | | - def get_context_data(self, **kwargs): |
27 | | - context = super().get_context_data(**kwargs) |
28 | | - self.branch = self.request.BRANCH |
29 | | - |
30 | | - context["competition"] = ( |
31 | | - competition |
32 | | - ) = Competition.objects.get_current_competition(self.branch) |
33 | | - |
34 | | - page = Page.objects.filter( |
35 | | - branch=self.request.BRANCH, |
36 | | - language=translation.get_language(), |
37 | | - countries__contains=[self.request.COUNTRY_CODE.upper()], |
38 | | - slug="_homepage_", |
39 | | - ).first() |
40 | | - if page: |
41 | | - current_state = competition.state |
42 | | - get_state = self.request.GET.get("state", "") |
43 | | - if self.request.user.is_authenticated and get_state.isnumeric(): |
44 | | - current_state = get_state |
45 | | - |
46 | | - context["page_blocks"] = page.pageblock_set.filter( |
47 | | - states__contains=[current_state] |
48 | | - ).all() |
49 | | - |
50 | | - return context |
| 2 | +from django.views.generic import RedirectView |
51 | 3 |
|
52 | 4 |
|
53 | 5 | class AdminRedirectView(RedirectView): |
|
0 commit comments