move code to django tables
This commit is contained in:
		
							
								
								
									
										22
									
								
								billard/tables.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								billard/tables.py
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
			
		||||
@@ -8,34 +8,6 @@
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
 | 
			
		||||
    <h2>Bitte Standort auswählen:</h2>
 | 
			
		||||
    <table class="table table-hover">
 | 
			
		||||
        <tr>
 | 
			
		||||
            <th>Code</th>
 | 
			
		||||
            <th>Name</th>
 | 
			
		||||
            <th>Strasse</th>
 | 
			
		||||
            <th>Plz</th>
 | 
			
		||||
            <th>Ort</th>
 | 
			
		||||
            {% if perms.billard.change_accounting %}
 | 
			
		||||
                <th>Accounting</th>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </tr>
 | 
			
		||||
        {% for loc in location_list %}
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td><a href="{% url 'billard:location_detail' loc.id %}"
 | 
			
		||||
                       class="btn btn-outline-primary btn-sm">{{ loc.code|default_if_none:"" }}</a></td>
 | 
			
		||||
                <td>{{ loc.name|default_if_none:"" }}</td>
 | 
			
		||||
                <td>{{ loc.street|default_if_none:"" }}</td>
 | 
			
		||||
                <td>{{ loc.plz|default_if_none:"" }}</td>
 | 
			
		||||
                <td>{{ loc.city|default_if_none:"" }}</td>
 | 
			
		||||
                {% if perms.billard.change_accounting %}
 | 
			
		||||
                    <td><a href="{% url 'billard:accounting_detail' loc.id %}"
 | 
			
		||||
                           class="btn btn-outline-danger btn-sm">Abrechnen</a></td>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </tr>
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </table>
 | 
			
		||||
    {% render_table table %}
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user