Example #1
0
 def get(self, *args, **kwargs):
     self.service = get_object_or_404(
         Service,
         id=kwargs.get('service_id'),
         is_active=True,
     )
     if self.request.GET and len(self.request.GET) >= 4:
         self.form = DateAndTimeRangeForm(self.request.GET)
     else:
         self.form = DateAndTimeRangeForm(
             data={
                 'start_date': timezone.now().strftime("%Y-%m-%d"),
                 'stop_date': timezone.now().strftime("%Y-%m-%d"),
                 'start_time': '00:00',
                 'stop_time': '23:59',
             },
         )
     self.history = None
     if self.form.is_valid():
         start_date = self.form.cleaned_data['start_date']
         start_time = self.form.cleaned_data['start_time']
         from_date = timezone.datetime(
             year=start_date.year,
             month=start_date.month,
             day=start_date.day,
             hour=start_time.hour,
             minute=start_time.minute,
         )
         stop_date = self.form.cleaned_data['stop_date']
         stop_time = self.form.cleaned_data['stop_time']
         to_date = timezone.datetime(
             year=stop_date.year,
             month=stop_date.month,
             day=stop_date.day,
             hour=stop_time.hour,
             minute=stop_time.minute,
         )
         paginator = Paginator(
             ServiceHistory.objects.filter(
                 service_id=self.service.id,
                 created__gte=from_date,
                 created__lte=to_date,
             ), 60,
         )
         page = self.request.GET.get('page', 1)
         try:
             self.history = paginator.page(page)
         except PageNotAnInteger:
             self.history = paginator.page(1)
         except EmptyPage:
             self.history = paginator.page(paginator.num_pages)
     return super(FullHistory, self).get(*args, **kwargs)
Example #2
0
class FullHistory(Base):
    template_name = 'boards/full_history.html'

    def get_context_data(self, **kwargs):
        ret = super(FullHistory, self).get_context_data(**kwargs)
        url_params = self.request.GET.copy()
        try:
            del url_params['page']
        except KeyError:
            pass
        url_params = url_params.urlencode()
        ret.update({
            'form': self.form,
            'service': self.service,
            'history': self.history,
            'params': self.service.additionalrequestparam_set.all(),
            'agents': Agent.objects.all(),
            'url_params': url_params,
        })
        return ret

    def get(self, *args, **kwargs):
        self.service = get_object_or_404(
            Service,
            id=kwargs.get('service_id'),
            is_active=True,
        )
        if self.request.GET and len(self.request.GET) >= 4:
            self.form = DateAndTimeRangeForm(self.request.GET)
        else:
            self.form = DateAndTimeRangeForm(
                data={
                    'start_date': timezone.now().strftime("%Y-%m-%d"),
                    'stop_date': timezone.now().strftime("%Y-%m-%d"),
                    'start_time': '00:00',
                    'stop_time': '23:59',
                },
            )
        self.history = None
        if self.form.is_valid():
            start_date = self.form.cleaned_data['start_date']
            start_time = self.form.cleaned_data['start_time']
            from_date = timezone.datetime(
                year=start_date.year,
                month=start_date.month,
                day=start_date.day,
                hour=start_time.hour,
                minute=start_time.minute,
            )
            stop_date = self.form.cleaned_data['stop_date']
            stop_time = self.form.cleaned_data['stop_time']
            to_date = timezone.datetime(
                year=stop_date.year,
                month=stop_date.month,
                day=stop_date.day,
                hour=stop_time.hour,
                minute=stop_time.minute,
            )
            paginator = Paginator(
                ServiceHistory.objects.filter(
                    service_id=self.service.id,
                    created__gte=from_date,
                    created__lte=to_date,
                ), 60,
            )
            page = self.request.GET.get('page', 1)
            try:
                self.history = paginator.page(page)
            except PageNotAnInteger:
                self.history = paginator.page(1)
            except EmptyPage:
                self.history = paginator.page(paginator.num_pages)
        return super(FullHistory, self).get(*args, **kwargs)