Skip to content

Commit e6b618b

Browse files
authored
refactor: merge Homepage with Page (#996)
1 parent fb87ab1 commit e6b618b

File tree

4 files changed

+4
-64
lines changed

4 files changed

+4
-64
lines changed

bullet/web/templates/web/homepage.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

bullet/web/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
r"^(?P<b_country>[a-z]{2})/(?P<b_language>[a-z\-]+)/",
1515
include(
1616
[
17-
path("", views.HomepageView.as_view(), name="homepage"),
17+
path("", page.PageView.as_view(), name="homepage"),
1818
path("", include("competitions.urls")),
1919
path("", include("problems.urls")),
2020
path("", include("gallery.urls")),

bullet/web/views/__init__.py

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
from competitions.models import Competition
21
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
513

524

535
class AdminRedirectView(RedirectView):

bullet/web/views/page.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PageView(TemplateView):
1212
template_name = "web/page.html"
1313

1414
def get(self, request, *args, **kwargs):
15-
if kwargs["slug"] == "_homepage_":
15+
if kwargs.get("slug") == "_homepage_":
1616
return HttpResponseRedirect(country_reverse("homepage"))
1717
return super().get(request, *args, **kwargs)
1818

@@ -27,7 +27,7 @@ def get_context_data(self, **kwargs):
2727
branch=self.request.BRANCH,
2828
language=translation.get_language(),
2929
countries__contains=[self.request.COUNTRY_CODE.upper()],
30-
slug=kwargs["slug"],
30+
slug=kwargs.get("slug", "_homepage_"),
3131
)
3232
context["page"] = page
3333

0 commit comments

Comments
 (0)