From: Guillaume Pellerin Date: Fri, 7 Feb 2014 17:18:08 +0000 (+0100) Subject: add a command to fix item markers X-Git-Tag: 1.4.6~2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=f93873b85b813057fefd3533076001fecd812bad;p=telemeta.git add a command to fix item markers --- diff --git a/telemeta/management/commands/telemeta-fix-item-markers.py b/telemeta/management/commands/telemeta-fix-item-markers.py new file mode 100644 index 00000000..9bb67d03 --- /dev/null +++ b/telemeta/management/commands/telemeta-fix-item-markers.py @@ -0,0 +1,26 @@ +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.core.files.base import ContentFile +from telemeta.models import * +from telemeta.util.unaccent import unaccent +import os + + +class Command(BaseCommand): + help = "apply a equal time shift to all markers of an item putting the first one to 0s" + args = "code" + + def handle(self, *args, **options): + code = args[-2] + + items = MediaItem.objects.filter(code__contains=code) + if items: + item = items[0] + markers = item.markers.all() + time_shift = markers[0].time + for marker in markers: + marker.time -= time_shift + marker.save() + else: + exit("No such item")