diff options
author | Johan Lundberg <lundberg@nordu.net> | 2014-04-02 12:31:00 +0200 |
---|---|---|
committer | Johan Lundberg <lundberg@nordu.net> | 2014-04-02 12:31:00 +0200 |
commit | 587a94e8c4ddaa245fc61d912a6bf5fb57996911 (patch) | |
tree | 79b0ea211712378cc66ce9912b9f37836ff61e90 /meetingtools | |
parent | d17caf5f25fc6d063a7f412c5a15033b01eec6f6 (diff) |
Catch IntegrityError when doing a full import.
Diffstat (limited to 'meetingtools')
-rw-r--r-- | meetingtools/apps/content/models.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/meetingtools/apps/content/models.py b/meetingtools/apps/content/models.py index 58233ac..5b076b3 100644 --- a/meetingtools/apps/content/models.py +++ b/meetingtools/apps/content/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- __author__ = 'lundberg' -from django.db import models +from django.db import models, IntegrityError from django.db.models.fields import CharField, BigIntegerField, IntegerField from django.db.models.fields.related import ForeignKey from django.contrib.auth.models import User @@ -71,20 +71,23 @@ class Content(models.Model): datecreated = row.findtext('date-created') if not datecreated: datecreated = row.findtext('date-modified') - - content, created = Content.objects.get_or_create( - sco=get_sco(acc, sco_id), - creator=user, - name=row.findtext('name'), - folder_sco=get_sco(acc, sco_element.get('folder-id')), - type=row.get('icon'), - urlpath=row.findtext('url'), - bytecount=byte_count, - created=datecreated, - modified=row.findtext('date-modified'), - views=views['views'], - lastviewed=views['last-viewed-date'] - ) + try: + content, created = Content.objects.get_or_create( + sco=get_sco(acc, sco_id), + creator=user, + name=row.findtext('name'), + folder_sco=get_sco(acc, sco_element.get('folder-id')), + type=row.get('icon'), + urlpath=row.findtext('url'), + bytecount=byte_count, + created=datecreated, + modified=row.findtext('date-modified'), + views=views['views'], + lastviewed=views['last-viewed-date'] + ) + except IntegrityError: + content = Content.objects.get(sco=get_sco(acc, sco_id)) + created = False if not created: Content.objects.filter(sco=content.sco).update( creator=user, |