diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-21 14:44:53 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2011-03-21 14:44:53 (GMT) |
commit | bbbb87cf6bd3bee25f3fe777357dc195029d8d38 (patch) | |
tree | e39b16b095d858f9122a72e92dd24f35c4a2fd43 | |
parent | d9881962d34f3c03148d49f4f9d6e7641cff4bd7 (diff) |
cleaned up host import code.
-rw-r--r-- | program/management/commands/importshows.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/program/management/commands/importshows.py b/program/management/commands/importshows.py index 71eb6fb..a907cca 100644 --- a/program/management/commands/importshows.py +++ b/program/management/commands/importshows.py @@ -36,25 +36,30 @@ ORDER BY titel, beginn, ende""") hosts = [] for macher in macher.decode('latin1').encode('utf8').split(','): + macher = macher.strip() try: - host = Host.objects.get(name=macher.strip()) - hosts.append(host) + host = Host.objects.get(name=macher) except MultipleObjectsReturned: print 'multiple hosts with name "%s" found' % macher except ObjectDoesNotExist: print 'host with name "%s" not found' % macher + else: + hosts.append(host) try: show = Show.objects.get(name=titel) print 'sendung "%s" already imported as show "%s"' % (titel, show) except ObjectDoesNotExist: show = Show(broadcastformat=TALK, name=titel, slug=slug, short_description='FIXME', description=beschreibung) - show.save() - counter += 1 - - for h in hosts: - show.hosts.add(h) + try: show.save() + counter += 1 + except: + print 'ERR: sendung "%s" could not be imported' % titel + else: + for h in hosts: + show.hosts.add(h) + show.save() cursor.close() connection.close() |