diff options
Diffstat (limited to 'program/management/commands/update_shows.py')
-rw-r--r-- | program/management/commands/update_shows.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/program/management/commands/update_shows.py b/program/management/commands/update_shows.py index 805c51e..a337f21 100644 --- a/program/management/commands/update_shows.py +++ b/program/management/commands/update_shows.py @@ -2,21 +2,28 @@ from django.core.management.base import NoArgsCommand from program.models import Show -from datetime import date - 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): - is_active = None for programslot in show.programslots.all(): - if programslot.until > date.today(): - is_active = True + active_programslots = 0 + if programslot.is_active: + active_programslots += 1 else: - is_active = False - show.is_active = is_active + active_programslots -= 1 + + show.is_active = active_programslots > 0 + show.save() + + if show.is_active: + activated += 1 + else: + deactivated += 1 - if not is_active: - show.save() + print "%s shows activated, %s shows de-activated" % (activated, deactivated) |