start working on schedule command/view

This commit is contained in:
bkfox 2015-06-12 18:09:15 +02:00
parent 55665a919b
commit 57f9159dbb
4 changed files with 251 additions and 176 deletions

View File

@ -54,15 +54,15 @@ class MetadataAdmin (admin.ModelAdmin):
class PublicationAdmin (MetadataAdmin): class PublicationAdmin (MetadataAdmin):
fieldsets = copy.deepcopy(MetadataAdmin.fieldsets) fieldsets = copy.deepcopy(MetadataAdmin.fieldsets)
list_display = ('id', 'title', 'date', 'status') list_display = ('id', 'title', 'date', 'public')
list_filter = ['date', 'status'] list_filter = ['date', 'public']
search_fields = ['title', 'content'] search_fields = ['title', 'content']
def __init__ (self, *args, **kwargs): def __init__ (self, *args, **kwargs):
self.fieldsets[0][1]['fields'].insert(1, 'subtitle') self.fieldsets[0][1]['fields'].insert(1, 'subtitle')
self.fieldsets[0][1]['fields'] += [ 'img', 'content' ] self.fieldsets[0][1]['fields'] += [ 'img', 'content' ]
self.fieldsets[1][1]['fields'] += [ 'parent', 'status', 'enable_comments', 'meta' ], self.fieldsets[1][1]['fields'] += [ 'parent', 'public', 'can_comment', 'meta' ],
return super(PublicationAdmin, self).__init__(*args, **kwargs) return super(PublicationAdmin, self).__init__(*args, **kwargs)

View File

@ -4,13 +4,12 @@ from django.core.management.base import BaseCommand, CommandError
import programs.models as models import programs.models as models
import programs.settings import programs.settings
class Command(BaseCommand):
class Command (BaseCommand):
help= "Take a look at the programs directory to check on new podcasts" help= "Take a look at the programs directory to check on new podcasts"
def handle (self, *args, **options):
def handle(self, *args, **options):
programs = models.Program.objects.filter(schedule__isnull = True) programs = models.Program.objects.filter(schedule__isnull = True)
for program in programs: for program in programs:
@ -24,6 +23,10 @@ class Command(BaseCommand):
for filename in os.listdir(path): for filename in os.listdir(path):
long_filename = path + '/' + filename long_filename = path + '/' + filename
# check for new sound files
# stat the sound files
# match sound files against episodes - if not found, create it
# upload public podcasts to mixcloud if required
except: except:
pass pass

View File

@ -0,0 +1,72 @@
import datetime
from django.core.management.base import BaseCommand, CommandError
from django.utils import timezone, dateformat
import programs.models as models
import programs.settings
class Diffusion:
ref = None
date_start = None
date_end = None
def __init__ (self, ref, date_start, date_end):
self.ref = ref
self.date_start = date_start
self.date_end = date_end
def __lt__ (self, d):
return self.date_start < d.date_start and \
self.date_end < d.date_end
class Command (BaseCommand):
help= "check sounds to diffuse"
diffusions = set()
def handle(self, *args, **options):
self.get_next_events()
self.get_next_episodes()
for diffusion in self.diffusions:
print( diffusion.ref.__str__()
, diffusion.date_start
, diffusion.date_end)
def get_next_episodes (self):
schedules = models.Schedule.objects.filter()
for schedule in schedules:
date = schedule.next_date()
if not date:
continue
dt = datetime.timedelta( hours = schedule.duration.hour
, minutes = schedule.duration.minute
, seconds = schedule.duration.second )
ref = models.Episode.objects.filter(date = date)[:1]
if not ref:
ref = ( schedule.parent, )
diffusion = Diffusion(ref[0], date, date + dt)
self.diffusions.add(diffusion)
def get_next_events (self):
events = models.Event.objects.filter(date_end__gt = timezone.now(),
canceled = False) \
.extra(order_by = ['date'])[:10]
for event in events:
diffusion = Diffusion(event, event.date, event.date_end)
self.diffusions.add(diffusion)

View File

@ -25,17 +25,6 @@ import programs.settings as settings
AStatus = {
'private': 0,
'public': 1,
# 'canceled': 2,
# 'finished': 3,
}
Status = [ (y, ugettext_lazy(x)) for x,y in AStatus.items() ]
RStatus = { y: x for x,y in AStatus.items() }
AFrequency = { AFrequency = {
'ponctual': 0x000000, 'ponctual': 0x000000,
'every week': 0b001111, 'every week': 0b001111,
@ -105,24 +94,34 @@ class Metadata (Model):
""" """
meta is used to extend a model for future needs meta is used to extend a model for future needs
""" """
author = models.ForeignKey ( author = models.ForeignKey (
User, User
verbose_name = _('author'), , verbose_name = _('author')
blank = True, , blank = True
null = True ) , null = True
date = models.DateTimeField( )
_('date'), title = models.CharField(
default = datetime.datetime.now ) _('title')
title = models.CharField( , max_length = 128
_('title'), )
max_length = 128 ) date = models.DateTimeField(
meta = models.TextField( _('date')
_('meta'), , default = datetime.datetime.now
blank = True, )
null = True ) public = models.BooleanField(
tags = TaggableManager( _('public')
_('tags'), , default = False
blank = True ) , help_text = _('publication is accessible to the public')
)
meta = models.TextField(
_('meta')
, blank = True
, null = True
)
tags = TaggableManager(
_('tags')
, blank = True
)
class Meta: class Meta:
abstract = True abstract = True
@ -136,38 +135,36 @@ class Publication (Metadata):
def __str__ (self): def __str__ (self):
return self.title + ' (' + str(self.id) + ')' return self.title + ' (' + str(self.id) + ')'
subtitle = models.CharField( subtitle = models.CharField(
_('subtitle'), _('subtitle')
max_length = 128, , max_length = 128
blank = True ) , blank = True
img = models.ImageField( )
_('image'), img = models.ImageField(
upload_to = "images", _('image')
blank = True ) , upload_to = "images"
content = models.TextField( , blank = True
_('content'), )
blank = True ) content = models.TextField(
status = models.SmallIntegerField( _('content')
_('status'), , blank = True
choices = Status, )
default = AStatus['public'] ) can_comment = models.BooleanField(
enable_comments = models.BooleanField( _('enable comments')
_('enable comments'), , default = True
default = True, , help_text = _('comments are enabled on this publication')
help_text = 'select to enable comments') )
# #
# Class methods # Class methods
# #
@staticmethod @staticmethod
def _exclude_args (allow_unpublished = False, prefix = ''): def _exclude_args (allow_unpublished = False, prefix = ''):
if allow_unpublished: if allow_unpublished:
return {} return {}
res = {} res = {}
res[prefix + 'status'] = AStatus['private'] res[prefix + 'public'] = False
res[prefix + 'date__gt'] = timezone.now() res[prefix + 'date__gt'] = timezone.now()
return res return res
@ -180,7 +177,7 @@ class Publication (Metadata):
Otherwise, return None Otherwise, return None
""" """
kwargs['status'] = AStatus['public'] kwargs['public'] = True
kwargs['date__lte'] = timezone.now() kwargs['date__lte'] = timezone.now()
e = cl.objects.filter(**kwargs) e = cl.objects.filter(**kwargs)
@ -193,10 +190,6 @@ class Publication (Metadata):
# #
# Instance's methods # Instance's methods
# #
def is_private (self):
return self.status == AStatus['private']
def get_parent (self, raise_404 = False ): def get_parent (self, raise_404 = False ):
if not parent and raise_404: if not parent and raise_404:
raise Http404 raise Http404
@ -230,23 +223,25 @@ class Publication (Metadata):
# #
# Final models # Usable models
# #
class Track (Model): class Track (Model):
artist = models.CharField( artist = models.CharField(
_('artist'), _('artist')
max_length = 128, , max_length = 128
blank = True) , blank = True
title = models.CharField( )
_('title'), title = models.CharField(
max_length = 128 ) _('title')
version = models.CharField( , max_length = 128
_('version'), )
max_length = 128, version = models.CharField(
blank = True, _('version')
help_text = _('additional informations on that track')) , max_length = 128
tags = TaggableManager( blank = True ) , blank = True
, help_text = _('additional informations on that track')
)
tags = TaggableManager( blank = True )
def __str__(self): def __str__(self):
@ -261,33 +256,33 @@ class Track (Model):
class SoundFile (Metadata): class SoundFile (Metadata):
parent = models.ForeignKey( parent = models.ForeignKey(
'Episode', 'Episode'
verbose_name = _('episode'), , verbose_name = _('episode')
blank = True, , blank = True
null = True ) , null = True
file = models.FileField( )
_('file'), file = models.FileField(
upload_to = "data/tracks", _('file')
blank = True ) , upload_to = "data/tracks"
duration = models.TimeField( , blank = True
_('duration'), )
blank = True, duration = models.TimeField(
null = True ) _('duration')
podcastable = models.BooleanField( , blank = True
_('podcastable'), , null = True
default = False, )
help_text = _('if checked, the file can be podcasted from this server')) fragment = models.BooleanField(
fragment = models.BooleanField( _('incomplete sound')
_('incomplete sound'), , default = False
default = False, , help_text = _("the file has been cut")
help_text = _("the file has been cut")) )
embed = models.TextField ( embed = models.TextField (
_('embed HTML code from external website'), _('embed HTML code from external website')
blank = True, , blank = True
null = True, , null = True
help_text = _('if set, consider the sound podcastable from there') , help_text = _('if set, consider the sound podcastable from there')
) )
def __str__ (self): def __str__ (self):
@ -300,13 +295,12 @@ class SoundFile (Metadata):
class Schedule (Model): class Schedule (Model):
parent = models.ForeignKey( 'Program', blank = True, null = True ) parent = models.ForeignKey( 'Program', blank = True, null = True )
date = models.DateTimeField(_('schedule')) date = models.DateTimeField(_('start'))
frequency = models.SmallIntegerField(_('frequency'), choices = Frequency) duration = models.TimeField(_('duration'))
duration = models.TimeField(_('duration')) frequency = models.SmallIntegerField(_('frequency'), choices = Frequency)
rerun = models.BooleanField(_('rerun'), default = False) rerun = models.BooleanField(_('rerun'), default = False)
def match_week (self, at = datetime.date.today()): def match_week (self, at = datetime.date.today()):
@ -337,7 +331,6 @@ class Schedule (Model):
if self.frequency == AFrequency['ponctual']: if self.frequency == AFrequency['ponctual']:
return None return None
print('#####')
# first day of the week # first day of the week
date = at - datetime.timedelta( days = at.weekday() ) date = at - datetime.timedelta( days = at.weekday() )
@ -393,18 +386,21 @@ class Schedule (Model):
class Article (Publication): class Article (Publication):
parent = models.ForeignKey( parent = models.ForeignKey(
'self', 'self'
verbose_name = _('parent'), , verbose_name = _('parent')
blank = True, , blank = True
null = True ) , null = True
static_page = models.BooleanField( )
_('static page'), static_page = models.BooleanField(
default = False ) _('static page')
focus = models.BooleanField( , default = False
_('article is focus'), )
blank = True, focus = models.BooleanField(
default = False ) _('article is focus')
, blank = True
, default = False
)
class Meta: class Meta:
@ -414,28 +410,28 @@ class Article (Publication):
class Program (Publication): class Program (Publication):
parent = models.ForeignKey( parent = models.ForeignKey(
Article Article
, verbose_name = _('parent') , verbose_name = _('parent')
, blank = True , blank = True
, null = True , null = True
) )
email = models.EmailField( email = models.EmailField(
_('email') _('email')
, max_length = 128 , max_length = 128
, null = True , null = True
, blank = True , blank = True
) )
url = models.URLField( url = models.URLField(
_('website') _('website')
, blank = True , blank = True
, null = True , null = True
) )
tag = models.CharField( tag = models.CharField(
_('tag') _('tag')
, max_length = 64 , max_length = 64
, help_text = _('used in articles to refer to it') , help_text = _('used in articles to refer to it')
) )
@property @property
def path(self): def path(self):
@ -456,15 +452,17 @@ class Episode (Publication):
# minimum of values. # minimum of values.
# Duration can be retrieved from the sound file if there is one. # Duration can be retrieved from the sound file if there is one.
# #
parent = models.ForeignKey( parent = models.ForeignKey(
Program, Program
verbose_name = _('parent'), , verbose_name = _('parent')
blank = True, , blank = True
null = True ) , null = True
tracks = models.ManyToManyField( )
Track, tracks = models.ManyToManyField(
verbose_name = _('playlist'), Track
blank = True ) , verbose_name = _('playlist')
, blank = True
)
class Meta: class Meta:
@ -476,27 +474,29 @@ class Episode (Publication):
class Event (Model): class Event (Model):
""" """
""" """
parent = models.ForeignKey ( parent = models.ForeignKey (
Episode, Episode
verbose_name = _('episode'), , verbose_name = _('episode')
blank = True, , blank = True
null = True ) , null = True
)
meta = models.TextField ( date = models.DateTimeField( _('date of start') )
_('meta'), date_end = models.DateTimeField(
blank = True, _('date of end')
null = True ) , blank = True
date = models.DateTimeField( _('date') ) , null = True
duration = models.TimeField( )
_('duration'), public = models.BooleanField(
blank = True, _('public')
null = True, , default = False
help_text = _('this is just indicative')) , help_text = _('publication is accessible to the public')
status = models.SmallIntegerField( )
_('status'), meta = models.TextField (
choices = Status, _('meta')
default = AStatus['public'] ) , blank = True
canceled = models.BooleanField( _('canceled'), default = False ) , null = True
)
canceled = models.BooleanField( _('canceled'), default = False )
def testify (self): def testify (self):