diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2016-03-27 18:38:29 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2016-03-27 18:38:29 (GMT) |
commit | 6c29ea12d96094cf1b71e6c2f22043bf92d32bcb (patch) | |
tree | 31b0b3e0187065ccfe1f479bb6689d424c022c68 /program/management/commands | |
parent | 94af0c6f391fc21f14047a8d649d4d4e8697afea (diff) |
fixed update commands
Diffstat (limited to 'program/management/commands')
-rw-r--r-- | program/management/commands/update_hosts.py | 20 | ||||
-rw-r--r-- | program/management/commands/update_programslots.py | 10 | ||||
-rw-r--r-- | program/management/commands/update_shows.py | 25 |
3 files changed, 40 insertions, 15 deletions
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) |