summaryrefslogtreecommitdiff
path: root/program/management/commands
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-08-16 15:51:35 (GMT)
committerErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-08-16 15:51:35 (GMT)
commit6990ff7f88f827d7193cb5ddef0be22546bccd23 (patch)
tree452c58394885ea1db6064e0a3ff30ef2ff6c17d6 /program/management/commands
parent1ee756130945cf5e60955945d01a6bb018620cac (diff)
simplified update commands
Diffstat (limited to 'program/management/commands')
-rw-r--r--program/management/commands/update_programslots.py15
-rw-r--r--program/management/commands/update_shows.py22
2 files changed, 7 insertions, 30 deletions
diff --git a/program/management/commands/update_programslots.py b/program/management/commands/update_programslots.py
index f0cc59d..6f7ec90 100644
--- a/program/management/commands/update_programslots.py
+++ b/program/management/commands/update_programslots.py
@@ -2,23 +2,14 @@ from django.core.management.base import NoArgsCommand
from program.models import ProgramSlot
-from datetime import date
+from datetime import datetime
class Command(NoArgsCommand):
help = 'update programslots by setting is_active'
def handle_noargs(self, **options):
- activated = 0
- deactivated = 0
-
- for programslot in ProgramSlot.objects.all():
- programslot.is_active = programslot.until > date.today()
- programslot.save()
-
- if programslot.is_active:
- activated += 1
- else:
- deactivated += 1
+ deactivated = ProgramSlot.objects.filter(until__lt=datetime.now()).update(is_active=False)
+ activated = ProgramSlot.objects.filter(until__gt=datetime.now()).update(is_active=True)
print "%s program slots activated, %s program slots de-activated" % (activated, deactivated)
diff --git a/program/management/commands/update_shows.py b/program/management/commands/update_shows.py
index a337f21..0dafb88 100644
--- a/program/management/commands/update_shows.py
+++ b/program/management/commands/update_shows.py
@@ -2,28 +2,14 @@ from django.core.management.base import NoArgsCommand
from program.models import Show
+from datetime import datetime
+
class Command(NoArgsCommand):
help = 'update shows by setting is_active'
def handle_noargs(self, **options):
- activated = 0
- deactivated = 0
-
- for show in Show.objects.exclude(pk=1):
- for programslot in show.programslots.all():
- active_programslots = 0
- if programslot.is_active:
- active_programslots += 1
- else:
- active_programslots -= 1
-
- show.is_active = active_programslots > 0
- show.save()
-
- if show.is_active:
- activated += 1
- else:
- deactivated += 1
+ deactivated = Show.objects.exclude(id=1).filter(programslots__until__lt=datetime.now()).update(is_active=False)
+ activated = Show.objects.exclude(id=1).filter(programslots__until__gt=datetime.now()).distinct().update(is_active=True)
print "%s shows activated, %s shows de-activated" % (activated, deactivated)