forked from KSET/kset-org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctx.py
40 lines (27 loc) · 873 Bytes
/
ctx.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
from datetime import datetime
import os
import random
from django.conf import settings
from events.models import Event
def header(request):
ctx = {}
try:
files = os.listdir(os.path.join(settings.STATIC_ROOT, 'frontend', 'images', 'headers'))
ctx['header_bg'] = random.choice(files)
except Exception as e:
pass
ctx['header_events'] = Event.objects.filter(date__gte=datetime.now()).order_by('date')
try:
if ctx['header_events'][0].date == datetime.now().date():
ctx['today_active'] = True
except:
pass
return ctx
def baseurl(request):
if request.is_secure():
scheme = 'https://'
else:
scheme = 'http://'
return {'BASE_URL': scheme + request.get_host(),}
def authenticated(request):
return {'is_member': request.session.get('members_user_id', False)}