diff --git a/billard/views.py b/billard/views.py index 9601f70..553ab9c 100644 --- a/billard/views.py +++ b/billard/views.py @@ -35,16 +35,18 @@ class LocationDataDetailView(DetailView): def index(request): if request.method == 'GET': template = 'billard/index.html' + loc = None if request.is_ajax(): 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'] - loc = None if 'loc' in request.GET: loc = request.GET['loc'] if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists(): resp = redirect('carom_index') if min_loc is not None: resp['Location'] += '?loc={}'.format(str(min_loc)) + request.session['loc'] = str(min_loc) return resp else: return render(request, template) @@ -61,6 +63,7 @@ def index(request): return render(request, template, context=context) if request.method == 'POST': loc = request.POST['location-selector'] + request.session['loc'] = str(loc) resp = redirect('carom_index') resp['Location'] += '?loc={}'.format(str(loc)) return resp