-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext_processors.py
More file actions
64 lines (46 loc) · 2.3 KB
/
Copy pathcontext_processors.py
File metadata and controls
64 lines (46 loc) · 2.3 KB
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
63
# The context processor function
# http://matthewphiong.com/django-global-template-variable
import datetime
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings as setting ## must use "as", only settings did not work
from .models import Transport, TransportLocation, TransportUserGetFet, TransportUserLocation
from .forms import UserState
def userstate(request):
# get users current getfet state and form to change it
if request.user.id :
# must try if user has not set state yet...
try:
userstate = TransportUserGetFet.objects.get( user = request.user.id )
except ObjectDoesNotExist:
userstate = TransportUserGetFet()
userstateform = UserState(request.POST or None, instance=userstate )
# change users possibility to fetch or hand over transports
if request.POST.get('getfet') :
userstate.getfet = request.POST['getfet']
userstate.user = request.user
userstate.changed = datetime.datetime.now()
userstate.save()
return { 'requestUserStatestate' : userstate.getfet , 'userstateform' : userstateform }
# anonymus
else:
return { 'requestUserStatestate' : '' , 'userstateform' : '' , }
def usersLocations(request):
if request.POST.get('checkin') and request.user:
try:
transportuserlocations = TransportUserLocation.objects.get( user = request.user.id )
except ObjectDoesNotExist :
transportuserlocations = TransportUserLocation()
transportlocation = TransportLocation.objects.get( pk = request.POST['checkin'] )
transportuserlocations.user = request.user
transportuserlocations.location = transportlocation
transportuserlocations.geoLat = transportlocation.geoLat
transportuserlocations.geoLon = transportlocation.geoLon
transportuserlocations.changed = datetime.datetime.now()
transportuserlocations.save()
try:
usersLocations = TransportUserLocation.objects.get( user = request.user.id )
return { 'usersLocations': usersLocations , }
except ObjectDoesNotExist: ## catch anonymus and user without location
return { 'usersLocations': '' , }
def settings(request):
return { 'setting' : setting }