diff --git a/billard/tables.py b/billard/tables.py
new file mode 100644
index 0000000..d8959b8
--- /dev/null
+++ b/billard/tables.py
@@ -0,0 +1,22 @@
+import django_tables2 as tables
+
+from .models import Location
+
+
+class LocationTable(tables.Table):
+ code = tables.TemplateColumn(template_name='billard/tc_location_detail.html')
+
+ class Meta:
+ model = Location
+ fields = ('code', 'name', 'street', 'plz', 'city')
+ orderable = False
+
+
+class LocationAccountingTable(tables.Table):
+ code = tables.TemplateColumn(template_name='billard/tc_location_detail.html')
+ accounting = tables.TemplateColumn(template_name='billard/tc_accounting_detail.html')
+
+ class Meta:
+ model = Location
+ fields = ('code', 'name', 'street', 'plz', 'city', 'accounting')
+ orderable = False
diff --git a/billard/templates/billard/location_index.html b/billard/templates/billard/location_index.html
index 2eaf49c..559adb7 100644
--- a/billard/templates/billard/location_index.html
+++ b/billard/templates/billard/location_index.html
@@ -8,34 +8,6 @@
{% endblock %}
{% block content %}
-
Bitte Standort auswählen:
-
-
- Code |
- Name |
- Strasse |
- Plz |
- Ort |
- {% if perms.billard.change_accounting %}
- Accounting |
- {% endif %}
-
- {% 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:"" }} |
- {% if perms.billard.change_accounting %}
- Abrechnen |
- {% endif %}
-
- {% endfor %}
-
{% render_table table %}
-
{% endblock %}
diff --git a/billard/views.py b/billard/views.py
index 7d8b82f..ad75286 100644
--- a/billard/views.py
+++ b/billard/views.py
@@ -1,7 +1,7 @@
import logging
-from datetime import datetime
from django.contrib.auth.decorators import login_required, permission_required
+from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Sum
from django.shortcuts import render, redirect
from django.urls import reverse_lazy
@@ -14,11 +14,12 @@ from rest_framework import viewsets
from billard.models import LocationData, Location, Client, Accounting
from billard.serializers import LocationDataSerializer, ClientUpdateLastSeenSerializer
from .forms import UserInformationUpdateForm
+from .tables import LocationTable, LocationAccountingTable
log = logging.getLogger(__name__)
-class LocationIndexView(generic.ListView):
+class LocationIndexView(LoginRequiredMixin, generic.ListView):
template_name = 'billard/location_index.html'
context_object_name = 'location_list'
@@ -26,6 +27,15 @@ class LocationIndexView(generic.ListView):
"""Return the last five published questions."""
return Location.objects.filter(users__id=self.request.user.id).order_by('code')
+ def get_context_data(self, *, object_list=None, **kwargs):
+ context = super().get_context_data(object_list=object_list, **kwargs)
+ table = LocationTable(self.get_queryset())
+ user = self.request.user
+ if user.has_perm('billard.change_accounting'):
+ table = LocationAccountingTable(self.get_queryset())
+ context['table'] = table
+ return context
+
class LocationDetailView(generic.DetailView):
model = Location