forked from rc/aircox
work on admin ui
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from . import api
|
||||
from . import api, admin
|
||||
|
||||
from .article import ArticleDetailView, ArticleListView
|
||||
from .base import BaseView
|
||||
|
64
aircox/views/admin.py
Normal file
64
aircox/views/admin.py
Normal file
@ -0,0 +1,64 @@
|
||||
"""
|
||||
Aircox admin tools and views.
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, \
|
||||
PermissionRequiredMixin, UserPassesTestMixin
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import ListView
|
||||
|
||||
from ..models import Program
|
||||
from .log import BaseLogListView
|
||||
|
||||
|
||||
class BaseAdminView(LoginRequiredMixin, UserPassesTestMixin):
|
||||
title = ''
|
||||
|
||||
def test_func(self):
|
||||
return self.request.user.is_staff
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs.update(admin.site.each_context(self.request))
|
||||
kwargs.setdefault('title', self.title)
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
class StatisticsView(BaseAdminView, BaseLogListView, ListView):
|
||||
template_name = 'admin/aircox/statistics.html'
|
||||
title = _('Statistics')
|
||||
date = None
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().today(self.date)
|
||||
|
||||
def get_diffusions_queryset(self):
|
||||
return super().get_diffusions_queryset().today(self.date)
|
||||
|
||||
def get(self, request, *args, date=None, **kwargs):
|
||||
self.date = datetime.date.today() if date is None else date
|
||||
return super().get(request, *args, date=date, **kwargs)
|
||||
|
||||
|
||||
class AdminSite(admin.AdminSite):
|
||||
def each_context(self, request):
|
||||
context = super().each_context(request)
|
||||
context.update({
|
||||
'programs': Program.objects.all().active().values('pk', 'title'),
|
||||
})
|
||||
return context
|
||||
|
||||
def get_urls(self):
|
||||
from django.urls import path, include
|
||||
urls = super().get_urls()
|
||||
urls += [
|
||||
path('tools/statistics/',
|
||||
self.admin_view(StatisticsView.as_view()),
|
||||
name='tools-stats'),
|
||||
]
|
||||
return urls
|
||||
|
||||
|
||||
admin_site = AdminSite()
|
||||
|
@ -19,7 +19,6 @@ class BaseAPIView:
|
||||
|
||||
|
||||
class LiveAPIView(BaseLogListView, BaseAPIView, ListAPIView):
|
||||
model = Log
|
||||
serializer_class = LogInfoSerializer
|
||||
min_date = None
|
||||
queryset = Log.objects.all()
|
||||
|
@ -11,6 +11,7 @@ __all__ = ['BaseLogListView', 'LogListView']
|
||||
|
||||
|
||||
class BaseLogListView:
|
||||
model = Log
|
||||
date = None
|
||||
|
||||
def get_queryset(self):
|
||||
@ -23,8 +24,6 @@ class BaseLogListView:
|
||||
|
||||
|
||||
class LogListView(BaseView, BaseLogListView, ListView):
|
||||
model = Log
|
||||
|
||||
date = None
|
||||
max_age = 10
|
||||
min_date = None
|
||||
@ -37,8 +36,6 @@ class LogListView(BaseView, BaseLogListView, ListView):
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def get_queryset(self):
|
||||
# only get logs for tracks: log for diffusion will be retrieved
|
||||
# by the diffusions' queryset.
|
||||
return super().get_queryset().today(self.date)
|
||||
|
||||
def get_diffusions_queryset(self):
|
||||
|
Reference in New Issue
Block a user