From 5477a26cbb161edf4534b826a4871e59b9ca48e6 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 10:35:10 +0200 Subject: [PATCH] rebuild location index and detail view --- billard/migrations/0022_auto_20170427_0835.py | 21 +++++++++ billard/models.py | 2 +- billard/templates/billard/base.html | 4 +- billard/templates/billard/index.html | 5 +++ .../templates/billard/location_detail.html | 25 +++++++++++ .../billard/location_detail_ajax.html | 12 +++++ ...location_list.html => location_index.html} | 13 +++--- billard/urls.py | 6 +-- billard/views.py | 44 ++++++++++--------- 9 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 billard/migrations/0022_auto_20170427_0835.py create mode 100644 billard/templates/billard/location_detail.html create mode 100644 billard/templates/billard/location_detail_ajax.html rename billard/templates/billard/{location_list.html => location_index.html} (69%) diff --git a/billard/migrations/0022_auto_20170427_0835.py b/billard/migrations/0022_auto_20170427_0835.py new file mode 100644 index 0000000..96e686e --- /dev/null +++ b/billard/migrations/0022_auto_20170427_0835.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-04-27 08:35 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('billard', '0021_accounting_account_user'), + ] + + operations = [ + migrations.AlterField( + model_name='client', + name='location', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='clients', to='billard.Location', verbose_name='Standort'), + ), + ] diff --git a/billard/models.py b/billard/models.py index 689289e..0a7e356 100644 --- a/billard/models.py +++ b/billard/models.py @@ -48,7 +48,7 @@ class Location(models.Model): class Client(models.Model): uuid = models.UUIDField(unique=True, default=uuid.uuid4, verbose_name="Identifier") - location = models.ForeignKey(Location, verbose_name="Standort") + location = models.ForeignKey(Location, related_name="clients", verbose_name="Standort") report_user = models.ForeignKey(User, blank=True, null=True, verbose_name="Reporting Benutzer", related_name='reporting_clients') def __str__(self): diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index b88fc67..4b084df 100644 --- a/billard/templates/billard/base.html +++ b/billard/templates/billard/base.html @@ -28,9 +28,9 @@ {% endif %} + + + +
{% include 'billard/index_ajax.html' %}
{% endblock %} + {% block js %} +{% endblock %} \ No newline at end of file diff --git a/billard/templates/billard/location_detail_ajax.html b/billard/templates/billard/location_detail_ajax.html new file mode 100644 index 0000000..cef9821 --- /dev/null +++ b/billard/templates/billard/location_detail_ajax.html @@ -0,0 +1,12 @@ +{% load display_client %} +{% if location.clients.all %} +{% for cli in location.clients.all %} +{% for i in "12345678" %} + {{ cli|display_client:i }} +{% endfor %} +{% endfor %} +{% else %} +
+
Keine Tische angelegt!
+
+{% endif %} diff --git a/billard/templates/billard/location_list.html b/billard/templates/billard/location_index.html similarity index 69% rename from billard/templates/billard/location_list.html rename to billard/templates/billard/location_index.html index a568105..2816b8b 100644 --- a/billard/templates/billard/location_list.html +++ b/billard/templates/billard/location_index.html @@ -1,10 +1,11 @@ {% extends 'billard/base.html' %} -{% block title %}Location List{% endblock %} +{% block title %}Standortliste{% endblock %} {% block content %} {% if location_list %} +

Bitte Standort auswählen:

@@ -15,11 +16,11 @@ {% for loc in location_list %} - - - - - + + + + + {% endfor %}
Code
{{ loc.code }}{{ loc.name }}{{ loc.street }}{{ loc.plz }}{{ loc.city }}{{ loc.code|default_if_none:"" }}{{ loc.name|default_if_none:"" }}{{ loc.street|default_if_none:"" }}{{ loc.plz|default_if_none:"" }}{{ loc.city|default_if_none:"" }}
diff --git a/billard/urls.py b/billard/urls.py index 020de52..4a71067 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -9,7 +9,7 @@ router.register(r'location_data', views.LocationDataViewSet) app_name = 'billard' urlpatterns = [ # ex. /billard/ - url(r'^$', login_required(views.LocationListView.as_view()), name='location_list'), + url(r'^$', login_required(views.LocationIndexView.as_view()), name='location_index'), # ex. /billard/1/ url(r'^(?P[0-9]+)/$', login_required(views.LocationDetailView.as_view()), name='location_detail'), # ex. /billard/1/accounting/ @@ -21,7 +21,7 @@ urlpatterns = [ #url(r'api/v1/', include(router.urls)), #url(r'process_locationdata', views.process_locationdata, name='process_locationdata'), #url(r'^accounting/$', views.AccountingView.as_view(), name='accounting'), - #url(r'accountmodal$', views.accountmodalview, name='accountmodal'), - #url(r'accoutmodal/confirm/(?P[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm") + url(r'^accountmodal$', views.accountmodalview, name='accountmodal'), + url(r'^accoutmodal/confirm/(?P[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm") # (?P[0-9]+) ] diff --git a/billard/views.py b/billard/views.py index 57d658a..6a89687 100644 --- a/billard/views.py +++ b/billard/views.py @@ -8,10 +8,11 @@ from django.views.generic.detail import DetailView from django.contrib.auth.decorators import login_required, permission_required from django.db.models import Min, Sum from django.http import HttpResponse +from django.utils.decorators import method_decorator -class LocationListView(generic.ListView): - template_name = 'billard/location_list.html' +class LocationIndexView(generic.ListView): + template_name = 'billard/location_index.html' context_object_name = 'location_list' def get_queryset(self): @@ -19,13 +20,26 @@ class LocationListView(generic.ListView): return Location.objects.filter(users__id=self.request.user.id).order_by('code') -class LocationDetailView(generic.ListView): - template_name = 'billard/location_list.html' - context_object_name = 'location_list' +class LocationDetailView(generic.DetailView): + model = Location + template_name = 'billard/location_detail.html' + + def dispatch(self, request, *args, **kwargs): + if request.is_ajax(): + context = { + 'location': self.get_object(), + } + return render(request, template_name='billard/location_detail_ajax.html', context=context) + return super(LocationDetailView, self).dispatch(request, *args, **kwargs) + + +@method_decorator(login_required, name='dispatch') +class AccountingView(generic.ListView): + template_name = 'billard/accounting.html' + context_object_name = 'accounting' def get_queryset(self): - """Return the last five published questions.""" - return Location.objects.filter(users__id=self.request.user.id).order_by('code') + return Accounting.objects.filter(billed=False).exclude(time_to__isnull=True) # TODO OLD CODE, CLEAN UP @@ -59,7 +73,7 @@ def accountmodalview(request): try: uuids = Client.objects.filter(report_user=request.user).values_list('uuid') account = Accounting.objects.filter(reporter_uuid__in=uuids).first - #TODO: support multiple account objects + # TODO: support multiple account objects except Client.DoesNotExist: account = None context = { @@ -96,7 +110,7 @@ def accounting(request): if loc is None: loc = min_loc locations = Location.objects.filter(users__id=request.user.id).order_by('code') - acc = Accounting.objects.filter(billed=False).exclude(time_to__isnull=True).\ + acc = Accounting.objects.filter(billed=False).exclude(time_to__isnull=True). \ filter(desk__client__location_id=loc).order_by('-time_from') acc_sum = acc.aggregate(Sum('prize')) acc_ids = list() @@ -164,18 +178,6 @@ def index(request): return resp -#@login_required -#@permission_required('billard.change_accounting') -class AccountingView(generic.ListView): - template_name = 'billard/accounting.html' - context_object_name = 'accounting' - - def get_queryset(self): - return Accounting.objects.filter(billed=False).exclude(time_to__isnull=True)\ - #.\ - #filter(desk__client__location_id=loc).order_by('-time_from') - - def process_locationdata(request): process_location_data() return HttpResponse('DONE')