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 LdsUtils
import Utils
from gen.datehandler._DateParser import DateParser
import gen.datehandler._dateparser as DateParser
from gen.db.dbconst import EVENT_KEY
from QuestionDialog import WarningDialog
from gen.lib.const import IDENTICAL, DIFFERENT

View File

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