fix error in view.py

This commit is contained in:
Robert Einsle 2017-02-26 12:20:50 +01:00
parent e22a153201
commit f9c483c8d3

View File

@ -35,16 +35,18 @@ class LocationDataDetailView(DetailView):
def index(request): def index(request):
if request.method == 'GET': if request.method == 'GET':
template = 'billard/index.html' template = 'billard/index.html'
loc = None
if request.is_ajax(): if request.is_ajax():
template = 'billard/index_ajax.html' template = 'billard/index_ajax.html'
loc = request.session.get('loc')
min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min'] min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min']
loc = None
if 'loc' in request.GET: if 'loc' in request.GET:
loc = request.GET['loc'] loc = request.GET['loc']
if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists(): if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists():
resp = redirect('carom_index') resp = redirect('carom_index')
if min_loc is not None: if min_loc is not None:
resp['Location'] += '?loc={}'.format(str(min_loc)) resp['Location'] += '?loc={}'.format(str(min_loc))
request.session['loc'] = str(min_loc)
return resp return resp
else: else:
return render(request, template) return render(request, template)
@ -61,6 +63,7 @@ def index(request):
return render(request, template, context=context) return render(request, template, context=context)
if request.method == 'POST': if request.method == 'POST':
loc = request.POST['location-selector'] loc = request.POST['location-selector']
request.session['loc'] = str(loc)
resp = redirect('carom_index') resp = redirect('carom_index')
resp['Location'] += '?loc={}'.format(str(loc)) resp['Location'] += '?loc={}'.format(str(loc))
return resp return resp