diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-07-23 17:42:56 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-07-23 17:42:56 (GMT) |
commit | 7f7e61b0200f9acab55dd4b95aa81ec372d693f4 (patch) | |
tree | a2b53175b7bcc7e084a920e513ef51af55f9b191 /program/management/commands | |
parent | b9aea9d71f2b01416e28eaaa5100072c3ef14673 (diff) |
updated note migration.
Diffstat (limited to 'program/management/commands')
-rw-r--r-- | program/management/commands/importnotes.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/program/management/commands/importnotes.py b/program/management/commands/importnotes.py index 94cea41..52999f5 100644 --- a/program/management/commands/importnotes.py +++ b/program/management/commands/importnotes.py @@ -1,5 +1,5 @@ from django.contrib.auth.models import User -from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned +from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned, ValidationError from django.core.management.base import NoArgsCommand from django.utils.html import clean_html, strip_tags @@ -22,14 +22,14 @@ class Command(NoArgsCommand): cursor.execute("""SELECT n.titel, n.datum, s.titel, n.notiz FROM notizen AS n JOIN sendungen AS s ON n.sendung_id=s.id -WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_date) AND n.titel != ''""") +WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_date)""") counter = 0 for ntitel, datum, stitel, notiz in cursor.fetchall(): - ntitel = strip_tags(ntitel) + ntitel = strip_tags(ntitel) if ntitel else strip_tags(stitel) stitel = strip_tags(stitel) notiz = clean_html(notiz) - + if stitel.endswith('(Wiederholung)'): stitel = stitel[:-15] @@ -37,7 +37,9 @@ WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_d year, month, day = datum.year, datum.month, datum.day try: show = Show.objects.get(name=stitel) - + except ObjectDoesNotExist: + print 'show with name "%s" not found' % stitel + else: try: timeslot = TimeSlot.objects.get(programslot__show=show, start__year=year, start__month=month, start__day=day) except ObjectDoesNotExist: @@ -46,15 +48,17 @@ WHERE n.sendung_id in (SELECT id FROM sendungen WHERE letzter_termin > current_d print 'multiple timeslots found for sendung "%s" and datum "%s"' % (stitel, datum) else: note = Note(timeslot=timeslot, owner=OWNER, title=ntitel, content=notiz) - try: - note.save() - except: - print 'could not save note "%s" for show "%s" and datum "%s"' % (ntitel, stitel, datum) + note.validate_unique() + except ValidationError: + print 'note already imported for show "%s" and datum "%s"' % (stitel, datum) else: - counter += 1 - except ObjectDoesNotExist: - print 'show with name "%s" not found' % stitel + try: + note.save() + except: + print 'could not save note "%s" for show "%s" and datum "%s"' % (ntitel, stitel, datum) + else: + counter += 1 cursor.close() connection.close() |