Skip to content

Commit 054546a

Browse files
author
Bojan Jovanovic
committed
Started adding some logic to how conference should be decyphered
1 parent b858435 commit 054546a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

pyconbalkan/conference/middleware.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from urllib.parse import urljoin
2+
3+
from django.conf import settings
4+
from django.http import HttpResponseRedirect
5+
16
from pyconbalkan.conference.models import Conference
27

38

@@ -11,7 +16,24 @@ def __call__(self, request):
1116

1217
# Domain format : 2019.pyconbalkan.com
1318
domain = request.META['HTTP_HOST']
14-
conference = Conference.objects.get(year=domain.split('.')[0])
19+
try:
20+
domain_year = int(domain.split('.')[0])
21+
q = {
22+
"year": domain_year
23+
}
24+
if not request.user.is_superuser:
25+
q['active'] = True
26+
27+
conference = Conference.objects.get(**q)
28+
except (Conference.DoesNotExist, ValueError):
29+
conference = Conference.objects.filter(active=True).first()
30+
31+
conference_domain = conference.year + "." + settings.META_SITE_DOMAIN
32+
if conference_domain != request.META['HTTP_HOST']:
33+
return HttpResponseRedirect(
34+
urljoin()
35+
)
36+
1537
# Every request will have an atribute `conference` in it
1638
# `conference` is the conference.models.Conference object for the
1739
# respective year fetched from it's domain

pyconbalkan/settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767
]
6868

6969
MIDDLEWARE = [
70-
# Custom middlewares
71-
'pyconbalkan.conference.middleware.ConferenceSelectionMiddleware',
72-
7370
# Django middlewares
7471
'django.middleware.security.SecurityMiddleware',
7572
'django.contrib.sessions.middleware.SessionMiddleware',
@@ -78,7 +75,8 @@
7875
'django.contrib.auth.middleware.AuthenticationMiddleware',
7976
'django.contrib.messages.middleware.MessageMiddleware',
8077
'django.middleware.clickjacking.XFrameOptionsMiddleware',
81-
78+
# Custom middlewares
79+
'pyconbalkan.conference.middleware.ConferenceSelectionMiddleware',
8280
]
8381

8482
ROOT_URLCONF = 'pyconbalkan.urls'

0 commit comments

Comments
 (0)