logs
This commit is contained in:
		@ -4,16 +4,6 @@ Manage diffusions using schedules, to update, clean up or check diffusions.
 | 
			
		||||
A generated diffusion can be unconfirmed, that means that the user must confirm
 | 
			
		||||
it by changing its type to "normal". The behaviour is controlled using
 | 
			
		||||
--approval.
 | 
			
		||||
 | 
			
		||||
Different actions are available:
 | 
			
		||||
- "update" is the process that is used to generated them using programs
 | 
			
		||||
schedules for the (given) month.
 | 
			
		||||
 | 
			
		||||
- "clean" will remove all diffusions that are still unconfirmed and have been
 | 
			
		||||
planified before the (given) month.
 | 
			
		||||
 | 
			
		||||
- "check" will remove all diffusions that are unconfirmed and have been planified
 | 
			
		||||
from the (given) month and later.
 | 
			
		||||
"""
 | 
			
		||||
import datetime
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
@ -64,13 +64,14 @@ class DiffusionQuerySet(BaseRerunQuerySet):
 | 
			
		||||
        """ On air diffusions """
 | 
			
		||||
        return self.filter(type=Diffusion.TYPE_ON_AIR)
 | 
			
		||||
 | 
			
		||||
    # TODO: rename to `datetime`
 | 
			
		||||
    def now(self, now=None, order=True):
 | 
			
		||||
        """ Diffusions occuring now """
 | 
			
		||||
        now = now or tz.now()
 | 
			
		||||
        qs = self.filter(start__lte=now, end__gte=now).distinct()
 | 
			
		||||
        return qs.order_by('start') if order else qs
 | 
			
		||||
 | 
			
		||||
    def today(self, today=None, order=True):
 | 
			
		||||
    def date(self, today=None, order=True):
 | 
			
		||||
        """ Diffusions occuring today. """
 | 
			
		||||
        today = today or datetime.date.today()
 | 
			
		||||
        start = tz.datetime.combine(today, datetime.time())
 | 
			
		||||
 | 
			
		||||
@ -24,7 +24,7 @@ class LogQuerySet(models.QuerySet):
 | 
			
		||||
        return self.filter(station=station) if id is None else \
 | 
			
		||||
               self.filter(station_id=id)
 | 
			
		||||
 | 
			
		||||
    def today(self, date):
 | 
			
		||||
    def date(self, date):
 | 
			
		||||
        return self.filter(date__date=date)
 | 
			
		||||
 | 
			
		||||
    def after(self, date):
 | 
			
		||||
@ -133,7 +133,7 @@ class LogQuerySet(models.QuerySet):
 | 
			
		||||
        if os.path.exists(path) and not force:
 | 
			
		||||
            return -1
 | 
			
		||||
 | 
			
		||||
        qs = self.station(station).today(date)
 | 
			
		||||
        qs = self.station(station).date(date)
 | 
			
		||||
 | 
			
		||||
        if not qs.exists():
 | 
			
		||||
            return 0
 | 
			
		||||
 | 
			
		||||
@ -17,13 +17,13 @@ class HomeView(PageListView):
 | 
			
		||||
 | 
			
		||||
    def get_logs(self):
 | 
			
		||||
        today = datetime.date.today()
 | 
			
		||||
        logs = Log.objects.on_air().today(today).filter(track__isnull=False)
 | 
			
		||||
        diffs = Diffusion.objects.on_air().today(today)
 | 
			
		||||
        logs = Log.objects.on_air().date(today).filter(track__isnull=False)
 | 
			
		||||
        diffs = Diffusion.objects.on_air().date(today)
 | 
			
		||||
        return Log.merge_diffusions(logs, diffs, self.logs_count)
 | 
			
		||||
 | 
			
		||||
    def get_sidebar_queryset(self):
 | 
			
		||||
        today = datetime.date.today()
 | 
			
		||||
        return Diffusion.objects.on_air().today(today)
 | 
			
		||||
        return Diffusion.objects.on_air().date(today)
 | 
			
		||||
 | 
			
		||||
    def get_top_diffs(self):
 | 
			
		||||
        now = tz.now()
 | 
			
		||||
 | 
			
		||||
@ -19,11 +19,12 @@ __all__ = ['LogListMixin', 'LogListView']
 | 
			
		||||
 | 
			
		||||
class LogListMixin(GetDateMixin):
 | 
			
		||||
    model = Log
 | 
			
		||||
    min_date = None
 | 
			
		||||
 | 
			
		||||
    def get_date(self):
 | 
			
		||||
        date, today = super().get_date(), datetime.date.today()
 | 
			
		||||
        date = super().get_date()
 | 
			
		||||
        if date is not None and not self.request.user.is_staff:
 | 
			
		||||
            return min(date, today)
 | 
			
		||||
            return min(date, datetime.date.today())
 | 
			
		||||
        return date
 | 
			
		||||
 | 
			
		||||
    def get_queryset(self):
 | 
			
		||||
@ -31,13 +32,13 @@ class LogListMixin(GetDateMixin):
 | 
			
		||||
        # by the diffusions' queryset.
 | 
			
		||||
        qs = super().get_queryset().on_air().filter(track__isnull=False) \
 | 
			
		||||
                                   .filter(date__lte=tz.now())
 | 
			
		||||
        return qs.today(self.date) if self.date is not None else \
 | 
			
		||||
        return qs.date(self.date) if self.date is not None else \
 | 
			
		||||
            qs.after(self.min_date) if self.min_date is not None else qs
 | 
			
		||||
 | 
			
		||||
    def get_diffusions_queryset(self):
 | 
			
		||||
        qs = Diffusion.objects.station(self.station).on_air() \
 | 
			
		||||
                      .filter(start__lte=tz.now())
 | 
			
		||||
        return qs.today(self.date) if self.date is not None else \
 | 
			
		||||
        return qs.date(self.date) if self.date is not None else \
 | 
			
		||||
            qs.after(self.min_date) if self.min_date is not None else qs
 | 
			
		||||
 | 
			
		||||
    def get_object_list(self, logs, full=False):
 | 
			
		||||
@ -60,17 +61,19 @@ class LogListView(BaseView, LogListMixin, ListView):
 | 
			
		||||
    has_filters = True
 | 
			
		||||
 | 
			
		||||
    def get_date(self):
 | 
			
		||||
        date, today = super().get_date(), datetime.date.today()
 | 
			
		||||
        return today if date is None else min(date, today)
 | 
			
		||||
        date = super().get_date()
 | 
			
		||||
        return datetime.date.today() if date is None else date
 | 
			
		||||
 | 
			
		||||
    def get_context_data(self, **kwargs):
 | 
			
		||||
        today = datetime.date.today()
 | 
			
		||||
        kwargs = super().get_context_data(**kwargs)
 | 
			
		||||
        print('objects:', self.date, self.get_queryset(), kwargs['object_list'])
 | 
			
		||||
        kwargs.update({
 | 
			
		||||
            'date': self.date,
 | 
			
		||||
            'dates': (today - datetime.timedelta(days=i) for i in range(0, 7)),
 | 
			
		||||
            'object_list': self.get_object_list(self.object_list),
 | 
			
		||||
        })
 | 
			
		||||
        return super().get_context_data(**kwargs)
 | 
			
		||||
        return kwargs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Logs are accessible through API only with this list view
 | 
			
		||||
@ -86,11 +89,11 @@ class LogListAPIView(LogListMixin, BaseAPIView, ListAPIView):
 | 
			
		||||
    serializer_class = LogInfoSerializer
 | 
			
		||||
    queryset = Log.objects.all()
 | 
			
		||||
 | 
			
		||||
    def get(self, *args, **kwargs):
 | 
			
		||||
        self.date = self.get_date()
 | 
			
		||||
        if self.date is None:
 | 
			
		||||
    def get_date(self):
 | 
			
		||||
        date = super().get_date()
 | 
			
		||||
        if date is None:
 | 
			
		||||
            self.min_date = tz.now() - tz.timedelta(minutes=30)
 | 
			
		||||
        return super().get(*args, **kwargs)
 | 
			
		||||
        return date
 | 
			
		||||
 | 
			
		||||
    def get_object_list(self, logs, full):
 | 
			
		||||
        return [LogInfo(obj) for obj in super().get_object_list(logs, full)]
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user