From c7efbffc8fdc773a2fab362b73bc4f19b43c138a Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 12 Apr 2017 13:35:18 +0200 Subject: [PATCH 01/24] update version info --- billard/templates/billard/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index 07d5217..137ddb3 100644 --- a/billard/templates/billard/base.html +++ b/billard/templates/billard/base.html @@ -47,7 +47,7 @@ {% endif %} From 52d515b05e77d5a07145b4314312499b5c6786ff Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 26 Apr 2017 10:06:25 +0200 Subject: [PATCH 02/24] update requirements --- .../0021_accounting_account_user.py | 22 +++++++++++++++++++ billard/models.py | 4 +--- billard/views.py | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 billard/migrations/0021_accounting_account_user.py diff --git a/billard/migrations/0021_accounting_account_user.py b/billard/migrations/0021_accounting_account_user.py new file mode 100644 index 0000000..789da72 --- /dev/null +++ b/billard/migrations/0021_accounting_account_user.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-04-26 09:57 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('billard', '0020_auto_20170410_1853'), + ] + + operations = [ + migrations.AddField( + model_name='accounting', + name='account_user', + field=models.ManyToManyField(related_name='accountings', to=settings.AUTH_USER_MODEL, verbose_name='Abr. Benutzer'), + ), + ] diff --git a/billard/models.py b/billard/models.py index 33aedfe..f343e24 100644 --- a/billard/models.py +++ b/billard/models.py @@ -2,8 +2,6 @@ import uuid import logging from django.db import models from django.contrib.auth.models import User -from datetime import datetime, timezone -from billard import utils from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver @@ -70,7 +68,6 @@ class Desk(models.Model): prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour") - def __str__(self): return '{}, {}'.format(self.client.uuid, self.name) @@ -88,6 +85,7 @@ class Accounting(models.Model): reporter_uuid = models.UUIDField(blank=True, null=True, verbose_name='Reporter UUID') prize_normal = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Normalzeit") prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour") + account_user = models.ManyToManyField(User, related_name='accountings', verbose_name="Abr. Benutzer") def __str__(self): return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed) diff --git a/billard/views.py b/billard/views.py index d9b091e..0d4a040 100644 --- a/billard/views.py +++ b/billard/views.py @@ -98,6 +98,7 @@ def accounting(request): if 'accountings' in request.POST: acc_ids = request.POST['accountings'].split(',') Accounting.objects.filter(id__in=acc_ids).update(billed=True) + Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user) request.session['loc'] = str(loc) resp = redirect('accounting') resp['Location'] += '?loc={}'.format(str(loc)) From 6135c7c61a2a7aac44c5c6a5b3476afd07e72d0d Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 26 Apr 2017 10:10:07 +0200 Subject: [PATCH 03/24] add accounting user to admin view --- billard/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/admin.py b/billard/admin.py index 2caca6d..92dddd1 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -57,4 +57,4 @@ class DeskAdmin(admin.ModelAdmin): @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): - list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed') + list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') From 55cf6101a86f6622a4b3096b8a01a9d186fb9c4e Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 26 Apr 2017 10:14:49 +0200 Subject: [PATCH 04/24] update accounting model --- billard/migrations/0021_accounting_account_user.py | 5 +++-- billard/models.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/billard/migrations/0021_accounting_account_user.py b/billard/migrations/0021_accounting_account_user.py index 789da72..08094d5 100644 --- a/billard/migrations/0021_accounting_account_user.py +++ b/billard/migrations/0021_accounting_account_user.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2017-04-26 09:57 +# Generated by Django 1.11 on 2017-04-26 10:14 from __future__ import unicode_literals from django.conf import settings from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): @@ -17,6 +18,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='accounting', name='account_user', - field=models.ManyToManyField(related_name='accountings', to=settings.AUTH_USER_MODEL, verbose_name='Abr. Benutzer'), + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='accountings', to=settings.AUTH_USER_MODEL, verbose_name='Abr. Benutzer'), ), ] diff --git a/billard/models.py b/billard/models.py index f343e24..8360638 100644 --- a/billard/models.py +++ b/billard/models.py @@ -85,7 +85,7 @@ class Accounting(models.Model): reporter_uuid = models.UUIDField(blank=True, null=True, verbose_name='Reporter UUID') prize_normal = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Normalzeit") prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour") - account_user = models.ManyToManyField(User, related_name='accountings', verbose_name="Abr. Benutzer") + account_user = models.OneToOneField(User, related_name='accountings', verbose_name="Abr. Benutzer", blank=True, null=True) def __str__(self): return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed) From 867788cd59b59b6c5c8a7d781aa6164be1431f89 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 26 Apr 2017 10:17:19 +0200 Subject: [PATCH 05/24] update accounting model --- billard/migrations/0021_accounting_account_user.py | 7 ++----- billard/models.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/billard/migrations/0021_accounting_account_user.py b/billard/migrations/0021_accounting_account_user.py index 08094d5..a36ff21 100644 --- a/billard/migrations/0021_accounting_account_user.py +++ b/billard/migrations/0021_accounting_account_user.py @@ -1,16 +1,13 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2017-04-26 10:14 +# Generated by Django 1.11 on 2017-04-26 10:17 from __future__ import unicode_literals -from django.conf import settings from django.db import migrations, models -import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), ('billard', '0020_auto_20170410_1853'), ] @@ -18,6 +15,6 @@ class Migration(migrations.Migration): migrations.AddField( model_name='accounting', name='account_user', - field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='accountings', to=settings.AUTH_USER_MODEL, verbose_name='Abr. Benutzer'), + field=models.CharField(blank=True, max_length=128, null=True, verbose_name='Abr. Benutzer'), ), ] diff --git a/billard/models.py b/billard/models.py index 8360638..689289e 100644 --- a/billard/models.py +++ b/billard/models.py @@ -85,7 +85,7 @@ class Accounting(models.Model): reporter_uuid = models.UUIDField(blank=True, null=True, verbose_name='Reporter UUID') prize_normal = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Normalzeit") prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour") - account_user = models.OneToOneField(User, related_name='accountings', verbose_name="Abr. Benutzer", blank=True, null=True) + account_user = models.CharField(blank=True, null=True, max_length=128, verbose_name="Abr. Benutzer") def __str__(self): return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed) From b04e642daa774f14eaa73a75f967d8a5c36b5bb0 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Wed, 26 Apr 2017 10:36:31 +0200 Subject: [PATCH 06/24] update views --- billard/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/views.py b/billard/views.py index 0d4a040..c78c742 100644 --- a/billard/views.py +++ b/billard/views.py @@ -98,7 +98,7 @@ def accounting(request): if 'accountings' in request.POST: acc_ids = request.POST['accountings'].split(',') Accounting.objects.filter(id__in=acc_ids).update(billed=True) - Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user) + Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username) request.session['loc'] = str(loc) resp = redirect('accounting') resp['Location'] += '?loc={}'.format(str(loc)) From dc09be5a43c63b64fa0a039589c7dfdac96274ba Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 08:04:44 +0200 Subject: [PATCH 07/24] move code to use generic views --- billard/templates/billard/base.html | 4 +-- billard/templates/billard/location_list.html | 30 ++++++++++++++++++ billard/urls.py | 25 ++++++++++----- billard/views.py | 33 ++++++++++++++++++++ 4 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 billard/templates/billard/location_list.html diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index 137ddb3..b88fc67 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') From cae1ee197e760ebc51d2aaa6eeca9f5ed48aa282 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 12:24:38 +0200 Subject: [PATCH 10/24] update accounting dialog --- billard/templates/billard/accounting.html | 12 ------------ billard/templates/billard/base.html | 3 --- billard/templates/billard/location_index.html | 6 ++++++ billard/urls.py | 2 +- billard/views.py | 10 ++++++++++ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/billard/templates/billard/accounting.html b/billard/templates/billard/accounting.html index 112beae..b6dedd1 100644 --- a/billard/templates/billard/accounting.html +++ b/billard/templates/billard/accounting.html @@ -4,18 +4,6 @@ {% block title %}Accounting Data{% endblock %} {% block content %} -{% if not locations|length_is:"1" %} -
-{% csrf_token %} -
- -
-
-{% endif %} diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index 4b084df..dded387 100644 --- a/billard/templates/billard/base.html +++ b/billard/templates/billard/base.html @@ -29,9 +29,6 @@ diff --git a/billard/templates/billard/location_detail.html b/billard/templates/billard/location_detail.html index 6925e3f..726bd90 100644 --- a/billard/templates/billard/location_detail.html +++ b/billard/templates/billard/location_detail.html @@ -20,6 +20,12 @@ $(document).ready(function() { function refresh_page() { $('#desk_data').load('#'); + $('#modal-wrapper').load('{% url 'billard:account_modal' %}', function() { + if ( $('#accountsmodal').length ) { + window.clearInterval(interval); + $('#accountsmodal').modal('show'); + } + }); } {% endblock %} \ No newline at end of file diff --git a/billard/urls.py b/billard/urls.py index f06ab1c..09a5f40 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -16,6 +16,10 @@ urlpatterns = [ url(r'^(?P[0-9]+)/accounting/$', views.AccountingView.as_view(), name='accounting_detail'), # ex. /billard/1/accounting/confirm url(r'^(?P[0-9]+)/accounting/confirm/$', views.accounting_confirm, name='accounting_detail_confirm'), + # ex. /billard/1/account_modal/ + url(r'^account_modal/$', views.account_modal_view, name='account_modal'), + # ex. /billard/1/account_modal/confirm/ + url(r'^account_modal/(?P[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'), # rest api url(r'api/v1/', include(router.urls)), @@ -23,7 +27,7 @@ urlpatterns = [ #url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), #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 1040b72..d33eedb 100644 --- a/billard/views.py +++ b/billard/views.py @@ -67,6 +67,28 @@ def accounting_confirm(request, pk): return resp +@login_required +def account_modal_view(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 + except Client.DoesNotExist: + account = None + context = { + 'account': account + } + return render(request, 'billard/accountmodal.html', context=context) + + +@login_required +def account_modal_confirm_view(request, pk): + account = Accounting.objects.get(pk=pk) + account.reporter_uuid = None + account.save() + return redirect('billard:location_detail', pk=account.desk.client.location_id) + + # TODO OLD CODE, CLEAN UP @@ -93,26 +115,6 @@ class LocationDataDetailView(DetailView): return super().get_template_names() -@login_required -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 - except Client.DoesNotExist: - account = None - context = { - 'account': account - } - return render(request, 'billard/accountmodal.html', context=context) - - -@login_required -def accountmodalconfirmview(request, pk): - account = Accounting.objects.get(pk=pk) - account.reporter_uuid = None - account.save() - return redirect('billard:location_detail', pk=pk) @login_required From 361183966400f4bbd6a1e786ce4caba333c72423 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 13:59:36 +0200 Subject: [PATCH 13/24] cleanup code --- billard/urls.py | 10 +---- billard/views.py | 113 +---------------------------------------------- 2 files changed, 3 insertions(+), 120 deletions(-) diff --git a/billard/urls.py b/billard/urls.py index 09a5f40..721198a 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -22,12 +22,6 @@ urlpatterns = [ url(r'^account_modal/(?P[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'), # rest api url(r'api/v1/', include(router.urls)), - - #url(r'^$', views.index, name='carom_index'), - #url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), - #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") - # (?P[0-9]+) + # ex. /billard/process_location_data/ + url(r'^process_location_data/$', views.process_location_data, name='process_location_data'), ] diff --git a/billard/views.py b/billard/views.py index d33eedb..d93b75c 100644 --- a/billard/views.py +++ b/billard/views.py @@ -89,122 +89,11 @@ def account_modal_confirm_view(request, pk): return redirect('billard:location_detail', pk=account.desk.client.location_id) -# TODO OLD CODE, CLEAN UP - - class LocationDataViewSet(viewsets.ModelViewSet): queryset = LocationData.objects.all() serializer_class = LocationDataSerializer -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 -@permission_required('billard.change_accounting') -def accounting(request): - if request.method == 'GET': - template = 'billard/accounting.html' - loc = None - min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min'] - 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('accounting') - 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, accounting) - 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). \ - filter(desk__client__location_id=loc).order_by('-time_from') - acc_sum = acc.aggregate(Sum('prize')) - acc_ids = list() - for a in acc: - acc_ids.append(a.id) - - context = { - 'location_id': int(loc), - 'locations': locations, - 'accounting': acc, - 'acc_ids': ','.join(str(e) for e in acc_ids), - } - if acc_sum['prize__sum'] is None: - context['acc_sum'] = 0 - else: - context['acc_sum'] = acc_sum['prize__sum'] - return render(request, template_name=template, context=context) - if request.method == 'POST': - loc = request.POST['location-selector'] - if 'accountings' in request.POST: - acc_ids = request.POST['accountings'].split(',') - Accounting.objects.filter(id__in=acc_ids).update(billed=True) - Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username) - request.session['loc'] = str(loc) - resp = redirect('accounting') - resp['Location'] += '?loc={}'.format(str(loc)) - return resp - - -@login_required -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'] - 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) - 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, 9), - 'locations': locations, - 'clients': clients, - 'location_id': int(loc), - } - 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 - - -def process_locationdata(request): +def process_location_data(request): process_location_data() return HttpResponse('DONE') From 857af8d54d53a13d4ae348cdfd90d50a4c04e9e9 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 14:03:57 +0200 Subject: [PATCH 14/24] cleanup code --- billard/urls.py | 12 ++--- billard/views.py | 113 +---------------------------------------------- 2 files changed, 4 insertions(+), 121 deletions(-) diff --git a/billard/urls.py b/billard/urls.py index 09a5f40..77853a3 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -20,14 +20,8 @@ urlpatterns = [ url(r'^account_modal/$', views.account_modal_view, name='account_modal'), # ex. /billard/1/account_modal/confirm/ url(r'^account_modal/(?P[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'), - # rest api + # ex. /billard/api/v1/ (rest api) url(r'api/v1/', include(router.urls)), - - #url(r'^$', views.index, name='carom_index'), - #url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'), - #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") - # (?P[0-9]+) + # ex. /billard/process_location_data/ + url(r'^process_location_data/$', views.process_location_data, name='process_location_data'), ] diff --git a/billard/views.py b/billard/views.py index d33eedb..d93b75c 100644 --- a/billard/views.py +++ b/billard/views.py @@ -89,122 +89,11 @@ def account_modal_confirm_view(request, pk): return redirect('billard:location_detail', pk=account.desk.client.location_id) -# TODO OLD CODE, CLEAN UP - - class LocationDataViewSet(viewsets.ModelViewSet): queryset = LocationData.objects.all() serializer_class = LocationDataSerializer -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 -@permission_required('billard.change_accounting') -def accounting(request): - if request.method == 'GET': - template = 'billard/accounting.html' - loc = None - min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min'] - 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('accounting') - 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, accounting) - 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). \ - filter(desk__client__location_id=loc).order_by('-time_from') - acc_sum = acc.aggregate(Sum('prize')) - acc_ids = list() - for a in acc: - acc_ids.append(a.id) - - context = { - 'location_id': int(loc), - 'locations': locations, - 'accounting': acc, - 'acc_ids': ','.join(str(e) for e in acc_ids), - } - if acc_sum['prize__sum'] is None: - context['acc_sum'] = 0 - else: - context['acc_sum'] = acc_sum['prize__sum'] - return render(request, template_name=template, context=context) - if request.method == 'POST': - loc = request.POST['location-selector'] - if 'accountings' in request.POST: - acc_ids = request.POST['accountings'].split(',') - Accounting.objects.filter(id__in=acc_ids).update(billed=True) - Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username) - request.session['loc'] = str(loc) - resp = redirect('accounting') - resp['Location'] += '?loc={}'.format(str(loc)) - return resp - - -@login_required -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'] - 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) - 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, 9), - 'locations': locations, - 'clients': clients, - 'location_id': int(loc), - } - 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 - - -def process_locationdata(request): +def process_location_data(request): process_location_data() return HttpResponse('DONE') From a165a0560fe7b1986be257f096889517588b695e Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 14:04:56 +0200 Subject: [PATCH 15/24] cleanup code --- billard/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/billard/views.py b/billard/views.py index d93b75c..be4c464 100644 --- a/billard/views.py +++ b/billard/views.py @@ -6,7 +6,6 @@ from billard.tasks import process_location_data from rest_framework import viewsets from django.shortcuts import render, redirect from django.views import generic -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 279d6437581fc394634298bc2a4076110b50b43f Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 14:22:23 +0200 Subject: [PATCH 16/24] rewrite url scemata --- billard/templates/billard/accountmodal.html | 2 +- billard/templates/billard/location_detail.html | 2 +- billard/urls.py | 5 +++-- billard/views.py | 13 ++++++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/billard/templates/billard/accountmodal.html b/billard/templates/billard/accountmodal.html index f064504..a38dedd 100644 --- a/billard/templates/billard/accountmodal.html +++ b/billard/templates/billard/accountmodal.html @@ -22,7 +22,7 @@ diff --git a/billard/templates/billard/location_detail.html b/billard/templates/billard/location_detail.html index 726bd90..1fe1f89 100644 --- a/billard/templates/billard/location_detail.html +++ b/billard/templates/billard/location_detail.html @@ -20,7 +20,7 @@ $(document).ready(function() { function refresh_page() { $('#desk_data').load('#'); - $('#modal-wrapper').load('{% url 'billard:account_modal' %}', function() { + $('#modal-wrapper').load('{% url 'billard:account_modal' loc_pk=pk %}', function() { if ( $('#accountsmodal').length ) { window.clearInterval(interval); $('#accountsmodal').modal('show'); diff --git a/billard/urls.py b/billard/urls.py index 77853a3..79d842e 100644 --- a/billard/urls.py +++ b/billard/urls.py @@ -17,9 +17,10 @@ urlpatterns = [ # ex. /billard/1/accounting/confirm url(r'^(?P[0-9]+)/accounting/confirm/$', views.accounting_confirm, name='accounting_detail_confirm'), # ex. /billard/1/account_modal/ - url(r'^account_modal/$', views.account_modal_view, name='account_modal'), + url(r'^(?P[0-9]+)/account_modal/$', views.account_modal_view, name='account_modal'), # ex. /billard/1/account_modal/confirm/ - url(r'^account_modal/(?P[0-9]+)/confirm/$', views.account_modal_confirm_view, name='account_modal_confirm'), + url(r'^(?P[0-9]+)/account_modal/(?P[0-9]+)/confirm/$', views.account_modal_confirm_view, + name='account_modal_confirm'), # ex. /billard/api/v1/ (rest api) url(r'api/v1/', include(router.urls)), # ex. /billard/process_location_data/ diff --git a/billard/views.py b/billard/views.py index be4c464..d2db1f6 100644 --- a/billard/views.py +++ b/billard/views.py @@ -31,7 +31,9 @@ class LocationDetailView(generic.DetailView): 'location': self.get_object(), } return render(request, template_name='billard/location_detail_ajax.html', context=context) - return super(LocationDetailView, self).dispatch(request, *args, **kwargs) + result = super(LocationDetailView, self).dispatch(request, *args, **kwargs) + result.context_data['pk'] = self.kwargs['pk'] + return result @method_decorator(login_required, name='dispatch') @@ -67,7 +69,7 @@ def accounting_confirm(request, pk): @login_required -def account_modal_view(request): +def account_modal_view(request, loc_pk): try: uuids = Client.objects.filter(report_user=request.user).values_list('uuid') account = Accounting.objects.filter(reporter_uuid__in=uuids).first @@ -75,17 +77,18 @@ def account_modal_view(request): except Client.DoesNotExist: account = None context = { - 'account': account + 'account': account, + 'loc_pk': loc_pk, } return render(request, 'billard/accountmodal.html', context=context) @login_required -def account_modal_confirm_view(request, pk): +def account_modal_confirm_view(request, loc_pk, pk): account = Accounting.objects.get(pk=pk) account.reporter_uuid = None account.save() - return redirect('billard:location_detail', pk=account.desk.client.location_id) + return redirect('billard:location_detail', pk=loc_pk) class LocationDataViewSet(viewsets.ModelViewSet): From f1404e0c0f8e1cb824558c2eba0df63cc96b0629 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 14:29:30 +0200 Subject: [PATCH 17/24] apply new version info --- billard/templates/billard/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index 5fb9fa6..b50a707 100644 --- a/billard/templates/billard/base.html +++ b/billard/templates/billard/base.html @@ -44,7 +44,7 @@ {% endif %} From e1e5fdd6f5a98cf485d81d837ecfbb8c742c1164 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Thu, 27 Apr 2017 14:35:04 +0200 Subject: [PATCH 18/24] fix login and logout urls --- caromserver/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/caromserver/settings.py b/caromserver/settings.py index f966cca..d6ee8c9 100644 --- a/caromserver/settings.py +++ b/caromserver/settings.py @@ -135,8 +135,8 @@ REST_FRAMEWORK = { CRISPY_TEMPLATE_PACK = 'bootstrap3' LOGIN_URL = 'login' LOGOUT_URL = 'logout' -LOGIN_REDIRECT_URL = 'carom_index' -LOGOUT_REDIRECT_URL = 'carom_index' +LOGIN_REDIRECT_URL = 'billard:location_index' +LOGOUT_REDIRECT_URL = 'billard:location_index' # CELERY STUFF BROKER_URL = 'redis://localhost:6379' From 54e1beb177188a5ea481a2b4bb653f219ac18eb8 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Fri, 28 Apr 2017 07:11:58 +0200 Subject: [PATCH 19/24] add search filter to accounting --- billard/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/billard/admin.py b/billard/admin.py index 92dddd1..6cd0492 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -58,3 +58,4 @@ class DeskAdmin(admin.ModelAdmin): @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') + list_filter = ('prize', 'billed', 'account_user') From 5647e23e1204b6d90a1cb30329a6db01e9c517d9 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Fri, 28 Apr 2017 07:17:56 +0200 Subject: [PATCH 20/24] realign search filter --- billard/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/admin.py b/billard/admin.py index 6cd0492..28fa163 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -58,4 +58,4 @@ class DeskAdmin(admin.ModelAdmin): @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') - list_filter = ('prize', 'billed', 'account_user') + list_filter = ('account_user', 'billed') From 865e8bb09a19d5a69912d9c9d5367ff70dc07754 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Fri, 28 Apr 2017 12:21:15 +0200 Subject: [PATCH 21/24] redesign location index page --- billard/templates/billard/location_index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/billard/templates/billard/location_index.html b/billard/templates/billard/location_index.html index 196b36f..cfad5af 100644 --- a/billard/templates/billard/location_index.html +++ b/billard/templates/billard/location_index.html @@ -19,11 +19,11 @@ {% for loc in location_list %} - {{ 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:"" }} + {{ 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:"" }} {% if perms.billard.change_accounting %} Abrechnen {% endif %} From 6492c29e32445e8c07c6249f0747deca9485f5ec Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Sat, 29 Apr 2017 11:06:14 +0200 Subject: [PATCH 22/24] extend list filter for location --- billard/admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/admin.py b/billard/admin.py index 28fa163..943a5f6 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -58,4 +58,4 @@ class DeskAdmin(admin.ModelAdmin): @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') - list_filter = ('account_user', 'billed') + list_filter = ('desk__client__location', 'account_user', 'billed') From 673092407b1289ceee687863f1776dc724cc8194 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Sat, 29 Apr 2017 11:15:26 +0200 Subject: [PATCH 23/24] add accounting tst --- billard/admin.py | 7 +++++-- .../migrations/0023_accounting_account_tst.py | 20 +++++++++++++++++++ billard/models.py | 1 + billard/views.py | 4 +++- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 billard/migrations/0023_accounting_account_tst.py diff --git a/billard/admin.py b/billard/admin.py index 943a5f6..062d815 100644 --- a/billard/admin.py +++ b/billard/admin.py @@ -57,5 +57,8 @@ class DeskAdmin(admin.ModelAdmin): @admin.register(Accounting) class AccountingAdmin(admin.ModelAdmin): - list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user') - list_filter = ('desk__client__location', 'account_user', 'billed') + list_display = ('desk', 'time_from', 'time_to', 'prize', 'billed', 'account_user', 'account_tst') + list_filter = ('desk__client__location', 'account_user', 'account_tst', 'billed') + + def has_add_permission(self, request): + return False diff --git a/billard/migrations/0023_accounting_account_tst.py b/billard/migrations/0023_accounting_account_tst.py new file mode 100644 index 0000000..7fe5c71 --- /dev/null +++ b/billard/migrations/0023_accounting_account_tst.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-04-29 11:09 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('billard', '0022_auto_20170427_0835'), + ] + + operations = [ + migrations.AddField( + model_name='accounting', + name='account_tst', + field=models.DateTimeField(blank=True, null=True, verbose_name='Abr. TST'), + ), + ] diff --git a/billard/models.py b/billard/models.py index 0a7e356..65d6875 100644 --- a/billard/models.py +++ b/billard/models.py @@ -86,6 +86,7 @@ class Accounting(models.Model): prize_normal = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Normalzeit") prize_hh = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, verbose_name="Preis Happy Hour") account_user = models.CharField(blank=True, null=True, max_length=128, verbose_name="Abr. Benutzer") + account_tst = models.DateTimeField(blank=True, null=True, verbose_name="Abr. TST") def __str__(self): return '{}: {} -> {}, {}, {}'.format(self.desk, self.time_from, self.time_to, self.prize, self.billed) diff --git a/billard/views.py b/billard/views.py index d2db1f6..087fef1 100644 --- a/billard/views.py +++ b/billard/views.py @@ -7,9 +7,10 @@ from rest_framework import viewsets from django.shortcuts import render, redirect from django.views import generic from django.contrib.auth.decorators import login_required, permission_required -from django.db.models import Min, Sum +from django.db.models import Sum from django.http import HttpResponse from django.utils.decorators import method_decorator +from django.utils import timezone class LocationIndexView(generic.ListView): @@ -64,6 +65,7 @@ def accounting_confirm(request, pk): if len(acc_ids) > 0: Accounting.objects.filter(id__in=acc_ids).update(billed=True) Accounting.objects.filter(id__in=acc_ids).update(account_user=request.user.username) + Accounting.objects.filter(id__in=acc_ids).update(account_tst=timezone.now()) resp = redirect('billard:accounting_detail', pk=pk) return resp From b0b848c1a649e4aa41038b6ce8cd04d4259d9f96 Mon Sep 17 00:00:00 2001 From: Robert Einsle Date: Sat, 29 Apr 2017 11:24:09 +0200 Subject: [PATCH 24/24] set release --- billard/templates/billard/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html index b50a707..cba7394 100644 --- a/billard/templates/billard/base.html +++ b/billard/templates/billard/base.html @@ -44,7 +44,7 @@ {% endif %}