Databases: removed prepare_import/commit_import; updated Django places

This commit is contained in:
Doug Blank 2015-08-12 07:42:19 -04:00
parent e5a77a60f6
commit 32bbce8ccd
14 changed files with 31 additions and 2085 deletions

View File

@ -638,6 +638,15 @@ class DbGeneric(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.set_note_id_prefix('N%04d')
# ----------------------------------
self.undodb = None
self.id_trans = DbGenericTxn("ID Transaction", self)
self.fid_trans = DbGenericTxn("FID Transaction", self)
self.pid_trans = DbGenericTxn("PID Transaction", self)
self.cid_trans = DbGenericTxn("CID Transaction", self)
self.sid_trans = DbGenericTxn("SID Transaction", self)
self.oid_trans = DbGenericTxn("OID Transaction", self)
self.rid_trans = DbGenericTxn("RID Transaction", self)
self.nid_trans = DbGenericTxn("NID Transaction", self)
self.eid_trans = DbGenericTxn("EID Transaction", self)
self.cmap_index = 0
self.smap_index = 0
self.emap_index = 0

View File

@ -2493,18 +2493,6 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
_("Version"): bsddb_version,
}
def prepare_import(self):
"""
Initialization before imports
"""
pass
def commit_import(self):
"""
Post process after imports
"""
pass
def mk_backup_name(database, base):
"""
Return the backup name of the database table

View File

@ -39,18 +39,6 @@ class DictionaryDb(DbGeneric):
"""
pass
def prepare_import(self):
"""
Do anything needed before an import.
"""
pass
def commit_import(self):
"""
Do anything needed after an import.
"""
self.reindex_reference_map(lambda n: n)
def write_version(self, directory):
"""Write files for a newly created DB."""
versionpath = os.path.join(directory, str(DBBACKEND))

View File

@ -107,10 +107,8 @@ def importData(dbase, filename, user):
parser = CSVParser(dbase, user, (config.get('preferences.tag-on-import-format') if
config.get('preferences.tag-on-import') else None))
try:
dbase.prepare_import()
with open(filename, 'r') as filehandle:
parser.parse(filehandle)
dbase.commit_import()
except EnvironmentError as err:
user.notify_error(_("%s could not be opened\n") % filename, str(err))
return

View File

@ -131,9 +131,7 @@ def importData(database, filename, user):
try:
read_only = database.readonly
database.readonly = False
database.prepare_import()
gedparse.parse_gedcom_file(False)
database.commit_import()
database.readonly = read_only
ifile.close()
except IOError as msg:

View File

@ -154,9 +154,7 @@ def importData(database, filename, user):
return
try:
database.prepare_import()
status = g.parse_geneweb_file()
database.commit_import()
except IOError as msg:
errmsg = _("%s could not be opened\n") % filename
user.notify_error(errmsg,str(msg))

View File

@ -93,9 +93,7 @@ def impData(database, name, user):
imp_db_name = os.path.join(tmpdir_path, XMLFILE)
importer = importData
database.prepare_import()
info = importer(database, imp_db_name, user)
database.commit_import()
newmediapath = database.get_mediapath()
#import of gpkg should not change media path as all media has new paths!

View File

@ -75,9 +75,7 @@ def _importData(database, filename, user):
return
try:
database.prepare_import()
status = g.parse_progen_file()
database.commit_import()
except ProgenError as msg:
user.notify_error(_("Pro-Gen data error"), str(msg))
return

View File

@ -63,10 +63,8 @@ def importData(database, filename, user):
"""Function called by Gramps to import data on persons in VCard format."""
parser = VCardParser(database)
try:
database.prepare_import()
with OpenFileOrStdin(filename) as filehandle:
parser.parse(filehandle)
database.commit_import()
except EnvironmentError as msg:
user.notify_error(_("%s could not be opened\n") % filename, str(msg))
return

View File

@ -122,7 +122,6 @@ def importData(database, filename, user):
line_cnt = 0
person_cnt = 0
database.prepare_import()
with ImportOpenFileContextManager(filename, user) as xml_file:
if xml_file is None:
return
@ -163,7 +162,6 @@ def importData(database, filename, user):
"valid Gramps database."))
return
database.commit_import()
database.readonly = read_only
return info

File diff suppressed because it is too large Load Diff

View File

@ -693,13 +693,14 @@ class Repository(PrimaryObject):
# .address_set
# .url_set
class Place(PrimaryObject):
class Place(DateObject, PrimaryObject):
place_type = models.ForeignKey('PlaceType', verbose_name="Type")
title = models.TextField(blank=True)
#locations = models.ManyToManyField('Location', null=True, blank=True)
long = models.TextField(blank=True)
lat = models.TextField(blank=True)
name = models.TextField(blank=True)
lang = models.TextField(blank=True)
code = models.TextField(blank=True) # zipcode
#url_list = models.ManyToManyField('Url', null=True, blank=True)

View File

@ -303,7 +303,7 @@ class DjangoInterface(object):
def get_place_handle(self, obj): # obj is event
if obj.place:
return obj.place.handle
return ''
return None
## Packers:
@ -371,11 +371,11 @@ class DjangoInterface(object):
if family.father:
father_handle = family.father.handle
else:
father_handle = ''
father_handle = None
if family.mother:
mother_handle = family.mother.handle
else:
mother_handle = ''
mother_handle = None
return (str(family.handle), family.gramps_id,
father_handle, mother_handle,
child_ref_list, tuple(family.family_rel_type),
@ -522,6 +522,14 @@ class DjangoInterface(object):
return (obj.calendar, obj.modifier, obj.quality, dateval,
obj.text, obj.sortval, obj.newyear)
def get_placename(self, place):
placename_date = self.get_date(place)
placename_value = place.name
placename_lang = place.lang
return (placename_value,
placename_date,
placename_lang)
def get_place(self, place):
locations = place.location_set.all().order_by("order")
alt_location_list = [self.pack_location(location, True) for location in locations]
@ -531,13 +539,14 @@ class DjangoInterface(object):
note_list = self.get_note_list(place)
tag_list = self.get_tag_list(place)
place_ref_list = self.get_place_ref_list(place)
placename = self.get_placename(place)
return (str(place.handle),
place.gramps_id,
place.title,
place.long,
place.lat,
place_ref_list,
place.name,
placename,
[], ## FIXME: get_alt_names
tuple(place.place_type),
place.code,
@ -1585,10 +1594,11 @@ class DjangoInterface(object):
#obj.save()
def add_place(self, data):
## ('cef246c95c132bcf6a0255d4d17', 'P0036', 'Santa Clara Co., CA, USA', '', '', [('cef243fb5634559442323368f63', None)], 'Santa Clara Co.', [], (3, ''), '', [], [], [], [], [], 1422124781, [], False)
## ('cef246c95c132bcf6a0255d4d17', 'P0036', ('Santa Clara Co., CA, USA', DATE, "English"),
## '', '', [('cef243fb5634559442323368f63', None)], 'Santa Clara Co.', [], (3, ''), '', [], [], [], [], [], 1422124781, [], False)
(handle, gid, title, long, lat,
place_ref_list,
name,
(placename, date, placelang),
alt_name_list,
place_type,
code,
@ -1606,7 +1616,8 @@ class DjangoInterface(object):
title=title,
long=long,
lat=lat,
name=name,
name=placename,
lang=placelang,
place_type=models.get_type(models.PlaceType, place_type),
code=code,
last_changed=todate(change),
@ -1619,7 +1630,7 @@ class DjangoInterface(object):
def add_place_detail(self, data):
(handle, gid, title, long, lat,
place_ref_list,
name,
(placename, date, placelang),
alt_name_list,
place_type,
code,
@ -1637,6 +1648,7 @@ class DjangoInterface(object):
print(("ERROR: Place does not exist: '%s'" %
str(handle)), file=sys.stderr)
return
self.add_date(place, date)
place.save(save_cache=False)
self.add_url_list("place", place, url_list)
self.add_media_ref_list(place, media_list)

View File

@ -85,9 +85,7 @@ def import_file(db, filename, user):
print("ERROR:", name, exception)
return False
import_function = getattr(mod, pdata.import_function)
#db.prepare_import()
retval = import_function(db, filename, user)
#db.commit_import()
return retval
return False