def get_queryset(self, **kwargs): user = self.request.user status = Ticket.STATUS_OPEN if self.kwargs[ "status"] == "open" else Ticket.STATUS_CLOSED uuid = self.kwargs.get("uuid", None) after = int(self.request.GET.get("after", 0)) before = int(self.request.GET.get("before", 0)) # fetching new activity gets a different order later ordered = False if after else True qs = self.folder.get_queryset(user.get_org(), user, ordered).filter(status=status) # all new activity after = int(self.request.GET.get("after", 0)) if after: after = timestamp_to_datetime(after) qs = qs.filter(last_activity_on__gt=after).order_by( "last_activity_on", "id") # historical page if before: before = timestamp_to_datetime(before) qs = qs.filter(last_activity_on__lt=before) # if we have exactly one historical page, redo our query for anything including the date # of our last ticket to make sure we don't lose items in our paging if not after and not uuid: qs = qs[:self.paginate_by] count = len(qs) if count == self.paginate_by: last_ticket = qs[len(qs) - 1] qs = self.folder.get_queryset( user.get_org(), user, ordered).filter( status=status, last_activity_on__gte=last_ticket.last_activity_on) # now reapply our before if we have one if before: qs = qs.filter( last_activity_on__lt=before) # pragma: needs cover if uuid: qs = qs.filter(uuid=uuid) return qs
def random_date(self, start=None, end=None): if not end: end = timezone.now() if not start: start = end - timedelta(days=365) if start == end: return end return timestamp_to_datetime(self.random.randrange(datetime_to_timestamp(start), datetime_to_timestamp(end)))