summaryrefslogtreecommitdiff
path: root/program/management
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-08-03 19:17:26 (GMT)
committerErnesto Rico-Schmidt <ernesto.rico-schmidt@evolaris.net>2016-08-03 19:18:51 (GMT)
commit1ee756130945cf5e60955945d01a6bb018620cac (patch)
tree184d77959bf2c5c0860983a8ed51bbb813b9d647 /program/management
parent4cfbc102d21302d774b558230f10252b40170944 (diff)
added management commands to chech and remove stale automation_ids
Diffstat (limited to 'program/management')
-rw-r--r--program/management/commands/check_automation_ids.py35
-rw-r--r--program/management/commands/remove_automation_id.py16
2 files changed, 51 insertions, 0 deletions
diff --git a/program/management/commands/check_automation_ids.py b/program/management/commands/check_automation_ids.py
new file mode 100644
index 0000000..be57ae2
--- /dev/null
+++ b/program/management/commands/check_automation_ids.py
@@ -0,0 +1,35 @@
+import json
+from os.path import join
+
+from django.conf import settings
+from django.core.management.base import NoArgsCommand
+
+from program.models import ProgramSlot
+
+
+class Command(NoArgsCommand):
+ help = 'checks the automation_ids used by program slots against the exported'
+
+ def handle_noargs(self, **options):
+ cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
+ cached_shows = join(cache_dir, 'shows.json')
+ with open(cached_shows) as shows_json:
+ shows = json.loads(shows_json.read())['shows']
+
+ automation_ids = []
+ for show in shows:
+ automation_ids.append(show['id'])
+ automation_ids.sort()
+
+ automation_ids2 = []
+ for programslot in ProgramSlot.objects.filter(automation_id__isnull=False):
+ automation_ids2.append(int(programslot.automation_id))
+ automation_ids2.sort()
+
+ for automation_id in automation_ids:
+ if automation_id not in automation_ids2:
+ print '+', automation_id
+
+ for automation_id in automation_ids2:
+ if automation_id not in automation_ids:
+ print '-', automation_id
diff --git a/program/management/commands/remove_automation_id.py b/program/management/commands/remove_automation_id.py
new file mode 100644
index 0000000..4fb8ee7
--- /dev/null
+++ b/program/management/commands/remove_automation_id.py
@@ -0,0 +1,16 @@
+from django.core.management.base import BaseCommand, CommandError
+
+from program.models import ProgramSlot
+
+
+class Command(BaseCommand):
+ help = 'removes the automation_id from the program slots'
+ args = '<automation_id>'
+
+ def handle(self, *args, **options):
+ if len(args) == 1:
+ automation_id = args[0]
+ else:
+ raise CommandError('you must provide the automation_id')
+
+ ProgramSlot.objects.filter(automation_id=automation_id).update(automation_id=None)