Ajaxify views

This commit is contained in:
Alexander Werner
2017-02-20 19:11:48 +01:00
parent 61ff97a8b2
commit b100c15a82
8 changed files with 157 additions and 115 deletions

View File

@@ -17,14 +17,26 @@ class LocationDataViewSet(viewsets.ModelViewSet):
class IndexView(generic.ListView):
model = LocationData
def get_template_names(self):
if self.request.is_ajax():
return ('billard/locationdata_list_ajax.html',)
return super().get_template_names()
class LocationDataDetailView(DetailView):
model = LocationData
def get_template_names(self):
if self.request.is_ajax():
return ('billard/locationdata_detail_ajax.html',)
return super().get_template_names()
@login_required
def index(request):
if request.method == 'GET':
template = 'billard/index.html'
if request.is_ajax():
template = 'billard/index_ajax.html'
min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min']
loc = None
if 'loc' in request.GET:
@@ -35,7 +47,7 @@ def index(request):
resp['Location'] += '?loc={}'.format(str(min_loc))
return resp
else:
return render(request, 'billard/index.html')
return render(request, template)
if loc is None:
loc = min_loc
locations = Location.objects.filter(users__id=request.user.id).order_by('code')
@@ -46,7 +58,7 @@ def index(request):
'clients': clients,
'location_id': int(loc),
}
return render(request, 'billard/index.html', context=context)
return render(request, template, context=context)
if request.method == 'POST':
loc = request.POST['location-selector']
resp = redirect('carom_index')