From bbbb87cf6bd3bee25f3fe777357dc195029d8d38 Mon Sep 17 00:00:00 2001 From: Ernesto Rico-Schmidt Date: Mon, 21 Mar 2011 15:44:53 +0100 Subject: cleaned up host import code. 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() -- cgit v0.10.2