Ajaxify views
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user