From 7b97bef883835fb2768bf2b34e2c3e569a072a2a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 27 May 2012 02:13:22 +0000 Subject: [PATCH] Use transactions on import; fix for date parser re-location svn: r19667 --- src/plugins/lib/libgedcom.py | 2 +- src/webapp/dbdjango.py | 76 ++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/plugins/lib/libgedcom.py b/src/plugins/lib/libgedcom.py index 52b715de9..a3a5de5c7 100644 --- a/src/plugins/lib/libgedcom.py +++ b/src/plugins/lib/libgedcom.py @@ -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 diff --git a/src/webapp/dbdjango.py b/src/webapp/dbdjango.py index 632e86e07..2c41fe649 100644 --- a/src/webapp/dbdjango.py +++ b/src/webapp/dbdjango.py @@ -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 = {}