summaryrefslogtreecommitdiff
path: root/program/management/commands/update_shows.py
blob: a337f21c3dafbd74bf5ca8e297f9cb228a37113b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from django.core.management.base import NoArgsCommand

from program.models import Show


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

        print "%s shows activated, %s shows de-activated" % (activated, deactivated)