move code to django tables
This commit is contained in:
@@ -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