From 6c29ea12d96094cf1b71e6c2f22043bf92d32bcb Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Sun, 27 Mar 2016 20:38:29 +0200 Subject: fixed update commands diff --git a/program/management/commands/update_hosts.py b/program/management/commands/update_hosts.py index 64619cd..3cb143b 100644 --- a/program/management/commands/update_hosts.py +++ b/program/management/commands/update_hosts.py @@ -7,15 +7,23 @@ class Command(NoArgsCommand): help = 'update host by setting is_active' def handle_noargs(self, **options): + activated = 0 + deactivated = 0 + for host in Host.objects.all(): - is_active = None + active_shows = 0 for show in host.shows.all(): if show.is_active: - is_active = True + active_shows += 1 else: - is_active = False + active_shows -= 1 + + host.is_active = active_shows > 0 + host.save() - host.is_active = is_active + if host.is_active: + activated += 1 + else: + deactivated += 1 - if not is_active: - host.save() + print "%s hosts activated, %s hosts de-activated " % (activated, deactivated) diff --git a/program/management/commands/update_programslots.py b/program/management/commands/update_programslots.py index 62de064..f0cc59d 100644 --- a/program/management/commands/update_programslots.py +++ b/program/management/commands/update_programslots.py @@ -9,6 +9,16 @@ 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 + + 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 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) -- cgit v0.10.2