Use transactions on import; fix for date parser re-location

svn: r19667
This commit is contained in:
Doug Blank 2012-05-27 02:13:22 +00:00
parent 6f6c914649
commit 7b97bef883
2 changed files with 40 additions and 38 deletions

View File

@ -120,7 +120,7 @@ from gen.updatecallback import UpdateCallback
import gen.mime import gen.mime
import LdsUtils import LdsUtils
import Utils import Utils
from gen.datehandler._DateParser import DateParser import gen.datehandler._dateparser as DateParser
from gen.db.dbconst import EVENT_KEY from gen.db.dbconst import EVENT_KEY
from QuestionDialog import WarningDialog from QuestionDialog import WarningDialog
from gen.lib.const import IDENTICAL, DIFFERENT from gen.lib.const import IDENTICAL, DIFFERENT

View File

@ -43,6 +43,7 @@ from gen.db import (PERSON_KEY,
NOTE_KEY) NOTE_KEY)
import Utils import Utils
from webapp.libdjango import DjangoInterface from webapp.libdjango import DjangoInterface
from django.db import transaction
class Cursor(object): class Cursor(object):
def __init__(self, model, func): def __init__(self, model, func):
@ -177,43 +178,44 @@ class DbDjango(DbWriteBase, DbReadBase):
import for two step adding. import for two step adding.
""" """
# First we add the primary objects: # First we add the primary objects:
for key in self.import_cache.keys(): with transaction.commit_on_success():
obj = self.import_cache[key] for key in self.import_cache.keys():
if isinstance(obj, gen.lib.Person): obj = self.import_cache[key]
self.dji.add_person(obj.serialize()) if isinstance(obj, gen.lib.Person):
elif isinstance(obj, gen.lib.Family): self.dji.add_person(obj.serialize())
self.dji.add_family(obj.serialize()) elif isinstance(obj, gen.lib.Family):
elif isinstance(obj, gen.lib.Event): self.dji.add_family(obj.serialize())
self.dji.add_event(obj.serialize()) elif isinstance(obj, gen.lib.Event):
elif isinstance(obj, gen.lib.Place): self.dji.add_event(obj.serialize())
self.dji.add_place(obj.serialize()) elif isinstance(obj, gen.lib.Place):
elif isinstance(obj, gen.lib.Repository): self.dji.add_place(obj.serialize())
self.dji.add_repository(obj.serialize()) elif isinstance(obj, gen.lib.Repository):
elif isinstance(obj, gen.lib.Citation): self.dji.add_repository(obj.serialize())
self.dji.add_citation(obj.serialize()) elif isinstance(obj, gen.lib.Citation):
elif isinstance(obj, gen.lib.Source): self.dji.add_citation(obj.serialize())
self.dji.add_source(obj.serialize()) elif isinstance(obj, gen.lib.Source):
elif isinstance(obj, gen.lib.Note): self.dji.add_source(obj.serialize())
self.dji.add_note(obj.serialize()) elif isinstance(obj, gen.lib.Note):
# Next we add the links: self.dji.add_note(obj.serialize())
for key in self.import_cache.keys(): # Next we add the links:
obj = self.import_cache[key] for key in self.import_cache.keys():
if isinstance(obj, gen.lib.Person): obj = self.import_cache[key]
self.dji.add_person_detail(obj.serialize()) if isinstance(obj, gen.lib.Person):
elif isinstance(obj, gen.lib.Family): self.dji.add_person_detail(obj.serialize())
self.dji.add_family_detail(obj.serialize()) elif isinstance(obj, gen.lib.Family):
elif isinstance(obj, gen.lib.Event): self.dji.add_family_detail(obj.serialize())
self.dji.add_event_detail(obj.serialize()) elif isinstance(obj, gen.lib.Event):
elif isinstance(obj, gen.lib.Place): self.dji.add_event_detail(obj.serialize())
self.dji.add_place_detail(obj.serialize()) elif isinstance(obj, gen.lib.Place):
elif isinstance(obj, gen.lib.Repository): self.dji.add_place_detail(obj.serialize())
self.dji.add_repository_detail(obj.serialize()) elif isinstance(obj, gen.lib.Repository):
elif isinstance(obj, gen.lib.Citation): self.dji.add_repository_detail(obj.serialize())
self.dji.add_citation_detail(obj.serialize()) elif isinstance(obj, gen.lib.Citation):
elif isinstance(obj, gen.lib.Source): self.dji.add_citation_detail(obj.serialize())
self.dji.add_source_detail(obj.serialize()) elif isinstance(obj, gen.lib.Source):
elif isinstance(obj, gen.lib.Note): self.dji.add_source_detail(obj.serialize())
self.dji.add_note_detail(obj.serialize()) elif isinstance(obj, gen.lib.Note):
self.dji.add_note_detail(obj.serialize())
self.use_import_cache = False self.use_import_cache = False
self.import_cache = {} self.import_cache = {}