summaryrefslogtreecommitdiff
path: root/program/management/commands/cleanup_defaultshow.py
blob: 98d3f9806c4523b8f353e234d40675627497bd71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.core.management.base import NoArgsCommand
from django.db import transaction

from program.models import Show, TimeSlot, ProgramSlot


class Command(NoArgsCommand):
    help = 'removes default shows without note'

    @transaction.commit_manually
    def handle_noargs(self, **options):

        default_show = Show.objects.get(pk=1)
        try:
            TimeSlot.objects.filter(show=default_show, note__isnull=True).delete()
            for programslot in ProgramSlot.objects.filter(show=default_show):
                if programslot.timeslots.count() == 0:
                    programslot.delete()
        except:
            transaction.rollback()
        else:
            transaction.commit()