forked from pycontw/pycon.tw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_processors.py
62 lines (46 loc) · 1.77 KB
/
context_processors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import itertools
import operator
from django.conf import settings
from django.urls import get_script_prefix
from django.utils.translation import get_language
from sponsors.models import Sponsor
def _build_google_form_url(uid):
return 'https://docs.google.com/forms/d/e/{uid}/viewform'.format(uid=uid)
def script_prefix(request):
return {
'SCRIPT_PREFIX': get_script_prefix(),
}
def pycontw(request):
lang = get_language()
if lang and lang.startswith('zh'):
sponsor_id = '1FAIpQLScEIeCrTHNvwbdNbZt4nK1mteC6NzHtXgF5bVn1KTtR0_sorA'
volun_id = '1FAIpQLScYhMAg4_T4Shi-W0vt9EkGyrpTMHemvcY55ZKc2-MfVqDzGg'
else:
sponsor_id = '1FAIpQLScEIeCrTHNvwbdNbZt4nK1mteC6NzHtXgF5bVn1KTtR0_sorA'
volun_id = '1FAIpQLScYhMAg4_T4Shi-W0vt9EkGyrpTMHemvcY55ZKc2-MfVqDzGg'
return {
'GTM_TRACK_ID': settings.GTM_TRACK_ID,
'KKTIX_URL': {
'RSVD': 'https://pycontw.kktix.cc/events/20200905-reserved',
'INDI': 'https://pycontw.kktix.cc/events/20200905-individual',
'CORP': 'https://pycontw.kktix.cc/events/20200905-corporate',
},
'SPONSOR_FORM_URL': _build_google_form_url(sponsor_id),
'VOLUNTEER_FORM_URL': _build_google_form_url(volun_id),
}
def _iter_sponsor_section():
groups = itertools.groupby(
Sponsor.objects.order_by('level'),
key=operator.methodcaller('get_level_display'),
)
for k, v in groups:
yield k, list(v)
def sponsors(request):
return {
'sponsors': Sponsor.objects.order_by('level'),
'sponsor_sections': _iter_sponsor_section(),
}
def events(request):
return {'schedule_redirect_url': settings.SCHEDULE_REDIRECT_URL}
def frontend_host(request):
return {'FRONTEND_HOST': settings.FRONTEND_HOST}