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,7 +21,8 @@ class Channel(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u"%s %s" % (self.list or 'All', self.run)
|
return u"%s %s" % (self.list or 'All', self.run)
|
||||||
|
|
||||||
def json(self, user):
|
def update_program(self, now=None):
|
||||||
|
if not now:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
cansee = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
cansee = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
||||||
if self.list:
|
if self.list:
|
||||||
|
@ -29,7 +30,7 @@ class Channel(models.Model):
|
||||||
else:
|
else:
|
||||||
items = Item.objects.filter(rendered=True, level__lte=cansee, sort__duration__gt=0)
|
items = Item.objects.filter(rendered=True, level__lte=cansee, sort__duration__gt=0)
|
||||||
if items.count() == 0:
|
if items.count() == 0:
|
||||||
return {}
|
return None
|
||||||
|
|
||||||
program = self.program.order_by('-start')
|
program = self.program.order_by('-start')
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -59,7 +60,15 @@ class Channel(models.Model):
|
||||||
program = self.program.order_by('-start')
|
program = self.program.order_by('-start')
|
||||||
if changed:
|
if changed:
|
||||||
self.save()
|
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):
|
class Program(models.Model):
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
|
@ -9,6 +9,5 @@ import models
|
||||||
|
|
||||||
@periodic_task(run_every=timedelta(days=1), queue='encoding')
|
@periodic_task(run_every=timedelta(days=1), queue='encoding')
|
||||||
def update_program(**kwargs):
|
def update_program(**kwargs):
|
||||||
user = User.objects.all()[0]
|
|
||||||
for c in models.Channel.objects.all():
|
for c in models.Channel.objects.all():
|
||||||
c.json(user)
|
c.update_program()
|
||||||
|
|
Loading…
Reference in a new issue