Add RadioManager to remaining Radio models.
This commit is contained in:
parent
b927bd5bc0
commit
3b55456a78
3 changed files with 64 additions and 35 deletions
|
@ -7,16 +7,52 @@ from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from core.utils import get_setting
|
from core.utils import get_setting
|
||||||
from .querysets import SongQuerySet
|
from .querysets import RadioQuerySet, SongQuerySet
|
||||||
|
|
||||||
|
|
||||||
# Set decimal precision
|
# Set decimal precision
|
||||||
getcontext().prec = 16
|
getcontext().prec = 16
|
||||||
|
|
||||||
|
|
||||||
class SongManager(models.Manager):
|
class RadioManager(models.Manager):
|
||||||
"""
|
"""
|
||||||
Custom object manager for filtering out common behaviors for a playlist.
|
Custom object manager for filtering out common behaviors for radio
|
||||||
|
objects.
|
||||||
|
"""
|
||||||
|
def get_queryset(self):
|
||||||
|
"""
|
||||||
|
Return customized default QuerySet.
|
||||||
|
"""
|
||||||
|
return RadioQuerySet(self.model, using=self._db)
|
||||||
|
|
||||||
|
def disabled(self):
|
||||||
|
"""
|
||||||
|
Radio objects that are marked as disabled.
|
||||||
|
"""
|
||||||
|
return self.get_queryset().disabled()
|
||||||
|
|
||||||
|
def enabled(self):
|
||||||
|
"""
|
||||||
|
Radio objects that are marked as enabled.
|
||||||
|
"""
|
||||||
|
return self.get_queryset().enabled()
|
||||||
|
|
||||||
|
def published(self):
|
||||||
|
"""
|
||||||
|
Radio objects that are marked as published.
|
||||||
|
"""
|
||||||
|
return self.get_queryset().published()
|
||||||
|
|
||||||
|
def unpublished(self):
|
||||||
|
"""
|
||||||
|
Radio objects that are marked as unpublished.
|
||||||
|
"""
|
||||||
|
return self.get_queryset().unpublished()
|
||||||
|
|
||||||
|
|
||||||
|
class SongManager(RadioManager):
|
||||||
|
"""
|
||||||
|
Custom object manager for filtering out common behaviors for Song objects.
|
||||||
"""
|
"""
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
|
@ -28,13 +64,13 @@ class SongManager(models.Manager):
|
||||||
"""
|
"""
|
||||||
Jingles that are currently published and are enabled.
|
Jingles that are currently published and are enabled.
|
||||||
"""
|
"""
|
||||||
return self.get_queryset().jingles().enabled().published()
|
return self.enabled().published().jingles()
|
||||||
|
|
||||||
def available_songs(self):
|
def available_songs(self):
|
||||||
"""
|
"""
|
||||||
Songs that are currently published and are enabled.
|
Songs that are currently published and are enabled.
|
||||||
"""
|
"""
|
||||||
return self.get_queryset().songs().enabled().published()
|
return self.enabled().published().songs()
|
||||||
|
|
||||||
def playlist_length(self):
|
def playlist_length(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,9 +4,8 @@ from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from core.behaviors import Timestampable
|
from core.behaviors import Disableable, Publishable, Timestampable
|
||||||
from .behaviors import Disableable, Publishable
|
from .managers import RadioManager, SongManager
|
||||||
from .managers import SongManager
|
|
||||||
|
|
||||||
|
|
||||||
class Album(Disableable, Publishable, Timestampable, models.Model):
|
class Album(Disableable, Publishable, Timestampable, models.Model):
|
||||||
|
@ -20,6 +19,9 @@ class Album(Disableable, Publishable, Timestampable, models.Model):
|
||||||
editable=False,
|
editable=False,
|
||||||
max_length=255)
|
max_length=255)
|
||||||
|
|
||||||
|
objects = models.Manager()
|
||||||
|
music = RadioManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['sorted_title', ]
|
ordering = ['sorted_title', ]
|
||||||
|
|
||||||
|
@ -40,6 +42,9 @@ class Artist(Disableable, Publishable, Timestampable, models.Model):
|
||||||
editable=False,
|
editable=False,
|
||||||
max_length=255)
|
max_length=255)
|
||||||
|
|
||||||
|
objects = models.Manager()
|
||||||
|
music = RadioManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['sorted_full_name', ]
|
ordering = ['sorted_full_name', ]
|
||||||
|
|
||||||
|
@ -72,6 +77,9 @@ class Game(Disableable, Publishable, Timestampable, models.Model):
|
||||||
editable=False,
|
editable=False,
|
||||||
max_length=255)
|
max_length=255)
|
||||||
|
|
||||||
|
objects = models.Manager()
|
||||||
|
music = RadioManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['sorted_title', ]
|
ordering = ['sorted_title', ]
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,9 @@
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
|
||||||
|
from core.querysets import EnabledQuerySet, PublishedQuerySet
|
||||||
|
|
||||||
|
|
||||||
class EnabledQuerySet(models.QuerySet):
|
class SongTypeQuerySet(models.QuerySet):
|
||||||
"""
|
|
||||||
Queryset to select all objects that are not disabled.
|
|
||||||
"""
|
|
||||||
def enabled(self):
|
|
||||||
return self.filter(disabled=False)
|
|
||||||
|
|
||||||
|
|
||||||
class PublishedQuerySet(models.QuerySet):
|
|
||||||
"""
|
|
||||||
Queryset to select all objects that have been published.
|
|
||||||
"""
|
|
||||||
def published(self):
|
|
||||||
results = self.filter(
|
|
||||||
models.Q(published_date__isnull=False) &
|
|
||||||
models.Q(published_date__lte=timezone.now())
|
|
||||||
)
|
|
||||||
return results
|
|
||||||
|
|
||||||
|
|
||||||
class TypeQuerySet(models.QuerySet):
|
|
||||||
"""
|
"""
|
||||||
Queryset to select all objects that are either songs or jingles.
|
Queryset to select all objects that are either songs or jingles.
|
||||||
"""
|
"""
|
||||||
|
@ -35,9 +14,15 @@ class TypeQuerySet(models.QuerySet):
|
||||||
return self.filter(song_type='J')
|
return self.filter(song_type='J')
|
||||||
|
|
||||||
|
|
||||||
class SongQuerySet(EnabledQuerySet,
|
class RadioQuerySet(EnabledQuerySet, PublishedQuerySet):
|
||||||
PublishedQuerySet,
|
"""
|
||||||
TypeQuerySet):
|
Queryset combination that can easily select enabled and published
|
||||||
|
objects.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SongQuerySet(RadioQuerySet, SongTypeQuerySet):
|
||||||
"""
|
"""
|
||||||
Queryset combination that can easily select enabled objects, published
|
Queryset combination that can easily select enabled objects, published
|
||||||
objects, and objects of a certain song type.
|
objects, and objects of a certain song type.
|
||||||
|
|
Loading…
Reference in a new issue