fix view logic
This commit is contained in:
parent
db051986a2
commit
7776bc844c
@ -23,13 +23,11 @@
|
|||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
<span class="icon-bar"></span>
|
<span class="icon-bar"></span>
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="#">Billard</a>
|
<a class="navbar-brand" href="/">Billard</a>
|
||||||
</div>
|
</div>
|
||||||
<div id="navbar" class="collapse navbar-collapse">
|
<div id="navbar" class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="active"><a href="/billard/">Tische</a></li>
|
<li class="active"><a href="/billard/">Tische</a></li>
|
||||||
<li><a href="#ueber">Über</a></li>
|
|
||||||
<li><a href="#kontakt">Kontakt</a></li>
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li><a href="{% url 'logout' %}">Abmelden</a></li>
|
<li><a href="{% url 'logout' %}">Abmelden</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from billard.serializers import *
|
from billard.serializers import *
|
||||||
from .models import LocationData
|
from .models import LocationData
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render, redirect
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.views.generic.detail import DetailView
|
from django.views.generic.detail import DetailView
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.db.models import Min
|
||||||
|
|
||||||
|
|
||||||
class ClientViewSet(viewsets.ModelViewSet):
|
class ClientViewSet(viewsets.ModelViewSet):
|
||||||
@ -37,17 +38,28 @@ class LocationDataDetailView(DetailView):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def index(request):
|
def index(request):
|
||||||
loc = 1
|
if request.method == 'GET':
|
||||||
if request.POST:
|
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')
|
||||||
|
resp['Location'] += '?loc={}'.format(str(min_loc))
|
||||||
|
return resp
|
||||||
|
if loc is None:
|
||||||
|
loc = min_loc
|
||||||
|
locations = Location.objects.filter(users__id=request.user.id).order_by('code')
|
||||||
|
clients = Client.objects.filter(location_id=loc).order_by('id')
|
||||||
|
context = {
|
||||||
|
'range': range(1, 3),
|
||||||
|
'locations': locations,
|
||||||
|
'clients': clients,
|
||||||
|
'location_id': int(loc),
|
||||||
|
}
|
||||||
|
return render(request, 'billard/index.html', context=context)
|
||||||
|
if request.method == 'POST':
|
||||||
loc = request.POST['location-selector']
|
loc = request.POST['location-selector']
|
||||||
|
resp = redirect('carom_index')
|
||||||
locations = Location.objects.order_by('code')
|
resp['Location'] += '?loc={}'.format(str(loc))
|
||||||
clients = Client.objects.filter(location_id=loc).order_by('id')
|
return resp
|
||||||
|
|
||||||
context = {
|
|
||||||
'range': range(1, 3),
|
|
||||||
'locations': locations,
|
|
||||||
'clients': clients,
|
|
||||||
'location_id': int(loc),
|
|
||||||
}
|
|
||||||
return render(request, 'billard/index.html', context=context)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user