2018-01-18 17:45:00 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class RequestManager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset()
|
|
|
|
|
|
|
|
def unplayed(self):
|
2018-09-24 17:03:42 +00:00
|
|
|
return self.get_queryset().filter(played_at__isnull=True)
|
2018-01-18 17:45:00 +00:00
|
|
|
|
2018-03-30 02:58:06 +00:00
|
|
|
def played(self):
|
|
|
|
return self.get_queryset().filter(models.Q(queued_at__isnull=False) |
|
|
|
|
models.Q(played_at__isnull=False))
|
|
|
|
|
2019-11-24 00:42:29 +00:00
|
|
|
def not_queued(self):
|
|
|
|
return self.get_queryset().filter(queued_at__isnull=True)
|
|
|
|
|
|
|
|
def queued(self):
|
2019-11-24 04:56:16 +00:00
|
|
|
return self.get_queryset().filter(queued_at__isnull=False)
|
2019-11-24 00:42:29 +00:00
|
|
|
|
|
|
|
def new_requests(self):
|
2019-11-24 03:31:11 +00:00
|
|
|
return self.get_queryset().filter(models.Q(queued_at__isnull=True) &
|
|
|
|
models.Q(played_at__isnull=True))
|
2019-11-24 00:42:29 +00:00
|
|
|
|
2018-03-30 02:58:06 +00:00
|
|
|
def get_played_requests(self, limit=None):
|
|
|
|
if limit:
|
|
|
|
return self.played()[0:limit]
|
|
|
|
return self.played()
|
|
|
|
|
2019-11-24 00:42:29 +00:00
|
|
|
def get_queued_requests(self, limit=None):
|
|
|
|
if limit:
|
|
|
|
return self.queued()[0:limit]
|
|
|
|
return self.queued()
|
|
|
|
|
2018-01-18 17:45:00 +00:00
|
|
|
def next_request(self):
|
2019-11-24 00:42:29 +00:00
|
|
|
return self.new_requests().earliest('created_date')
|