Skip to content

Commit 2119578

Browse files
VishvajitPBojan Jovanovic
authored andcommitted
[middleware] Added middleware
1 parent ae6ddf5 commit 2119578

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pyconbalkan.conference.models import Conference
2+
3+
4+
class ConferenceSelectionMiddleware:
5+
def __init__(self, get_response):
6+
self.get_response = get_response
7+
8+
def __call__(self, request):
9+
# Code to be executed for each request before
10+
# the view (and later middleware) are called.
11+
12+
# Domain format : 2019.pyconbalkan.com
13+
domain = request.META['HTTP_HOST']
14+
conference = Conference.objects.get(year=domain.split('.')[0])
15+
# Every request will have an atribute `conference` in it
16+
# `conference` is the conference.models.Conference object for the
17+
# respective year fetched from it's domain
18+
request.conference = conference
19+
response = self.get_response(request)
20+
return response

0 commit comments

Comments
 (0)