summaryrefslogtreecommitdiff
path: root/program/management/commands/update_hosts.py
diff options
context:
space:
mode:
Diffstat (limited to 'program/management/commands/update_hosts.py')
-rw-r--r--program/management/commands/update_hosts.py20
1 files changed, 14 insertions, 6 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)