forked from 0x2620/pandora
split program update and current json
This commit is contained in:
parent
103f3396d6
commit
9ee71ce6dd
2 changed files with 14 additions and 6 deletions
|
@ -21,15 +21,16 @@ class Channel(models.Model):
|
|||
def __unicode__(self):
|
||||
return u"%s %s" % (self.list or 'All', self.run)
|
||||
|
||||
def json(self, user):
|
||||
now = datetime.now()
|
||||
def update_program(self, now=None):
|
||||
if not now:
|
||||
now = datetime.now()
|
||||
cansee = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||
if self.list:
|
||||
items = self.list.get_items(self.list.user).filter(rendered=True, level__lte=cansee, sort__duration__gt=0)
|
||||
else:
|
||||
items = Item.objects.filter(rendered=True, level__lte=cansee, sort__duration__gt=0)
|
||||
if items.count() == 0:
|
||||
return {}
|
||||
return None
|
||||
|
||||
program = self.program.order_by('-start')
|
||||
changed = False
|
||||
|
@ -59,7 +60,15 @@ class Channel(models.Model):
|
|||
program = self.program.order_by('-start')
|
||||
if changed:
|
||||
self.save()
|
||||
return program[0].json(user, now)
|
||||
return program[0]
|
||||
|
||||
def json(self, user):
|
||||
now = datetime.now()
|
||||
program = self.update_program(now)
|
||||
if not program:
|
||||
return {}
|
||||
else:
|
||||
return program.json(user, now)
|
||||
|
||||
class Program(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -9,6 +9,5 @@ import models
|
|||
|
||||
@periodic_task(run_every=timedelta(days=1), queue='encoding')
|
||||
def update_program(**kwargs):
|
||||
user = User.objects.all()[0]
|
||||
for c in models.Channel.objects.all():
|
||||
c.json(user)
|
||||
c.update_program()
|
||||
|
|
Loading…
Reference in a new issue