Cleanup of django code for import; need to fix import, not correct in linking to objects
svn: r18318
This commit is contained in:
parent
02eb64ce7d
commit
62d2031d31
@ -30,7 +30,8 @@ import cPickle
|
||||
import base64
|
||||
import web
|
||||
import gen
|
||||
from gen.db import DbReadBase, DbWriteBase
|
||||
import re
|
||||
from gen.db import DbReadBase, DbWriteBase, DbTxn
|
||||
from gen.db import (PERSON_KEY,
|
||||
FAMILY_KEY,
|
||||
SOURCE_KEY,
|
||||
@ -39,6 +40,7 @@ from gen.db import (PERSON_KEY,
|
||||
PLACE_KEY,
|
||||
REPOSITORY_KEY,
|
||||
NOTE_KEY)
|
||||
import Utils
|
||||
from web.libdjango import DjangoInterface
|
||||
|
||||
# Example for running a report:
|
||||
@ -66,6 +68,7 @@ def import_file(db, filename, callback):
|
||||
|
||||
>>> import_file(DbDjango(), "/home/user/Untitled_1.ged", lambda a: a)
|
||||
"""
|
||||
global count
|
||||
dbstate = DbState.DbState()
|
||||
climanager = CLIManager(dbstate, False) # do not load db_loader
|
||||
climanager.do_reg_plugins(dbstate, None)
|
||||
@ -82,10 +85,9 @@ def import_file(db, filename, callback):
|
||||
print "ERROR:", name, exception
|
||||
return False
|
||||
import_function = getattr(mod, pdata.import_function)
|
||||
db.step = 0
|
||||
import_function(db, filename, callback)
|
||||
db.step = 1
|
||||
db.prepare_import()
|
||||
import_function(db, filename, callback)
|
||||
db.commit_import()
|
||||
return True
|
||||
return False
|
||||
|
||||
@ -137,6 +139,23 @@ class Bookmarks:
|
||||
def get(self):
|
||||
return [] # handles
|
||||
|
||||
class DjangoTxn(DbTxn):
|
||||
def __init__(self, message, db, table=None):
|
||||
DbTxn.__init__(self, message, db)
|
||||
self.table = table
|
||||
|
||||
def get(self, key, default=None, txn=None, **kwargs):
|
||||
"""
|
||||
Returns the data object associated with key
|
||||
"""
|
||||
try:
|
||||
return self.table.objects(handle=key)
|
||||
except:
|
||||
if txn and key in txn:
|
||||
return txn[key]
|
||||
else:
|
||||
return None
|
||||
|
||||
class DbDjango(DbWriteBase, DbReadBase):
|
||||
"""
|
||||
A Gramps Database Backend. This replicates the grampsdb functions.
|
||||
@ -157,16 +176,31 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
self.repo_bookmarks = Bookmarks()
|
||||
self.media_bookmarks = Bookmarks()
|
||||
self.note_bookmarks = Bookmarks()
|
||||
self.event_prefix = "E%04s"
|
||||
self.set_person_id_prefix('I%04d')
|
||||
self.set_object_id_prefix('O%04d')
|
||||
self.set_family_id_prefix('F%04d')
|
||||
self.set_source_id_prefix('S%04d')
|
||||
self.set_place_id_prefix('P%04d')
|
||||
self.set_event_id_prefix('E%04d')
|
||||
self.set_repository_id_prefix('R%04d')
|
||||
self.set_note_id_prefix('N%04d')
|
||||
# ----------------------------------
|
||||
self.id_trans = {}
|
||||
self.fid_trans = {}
|
||||
self.pid_trans = {}
|
||||
self.sid_trans = {}
|
||||
self.oid_trans = {}
|
||||
self.rid_trans = {}
|
||||
self.nid_trans = {}
|
||||
self.eid_trans = {}
|
||||
self.id_trans = DjangoTxn("ID Transaction", self, self.dji.Person)
|
||||
self.fid_trans = DjangoTxn("FID Transaction", self, self.dji.Family)
|
||||
self.pid_trans = DjangoTxn("PID Transaction", self, self.dji.Place)
|
||||
self.sid_trans = DjangoTxn("SID Transaction", self, self.dji.Source)
|
||||
self.oid_trans = DjangoTxn("OID Transaction", self, self.dji.Media)
|
||||
self.rid_trans = DjangoTxn("RID Transaction", self, self.dji.Repository)
|
||||
self.nid_trans = DjangoTxn("NID Transaction", self, self.dji.Note)
|
||||
self.eid_trans = DjangoTxn("EID Transaction", self, self.dji.Event)
|
||||
self.smap_index = 0
|
||||
self.emap_index = 0
|
||||
self.pmap_index = 0
|
||||
self.fmap_index = 0
|
||||
self.lmap_index = 0
|
||||
self.omap_index = 0
|
||||
self.rmap_index = 0
|
||||
self.nmap_index = 0
|
||||
self.env = None
|
||||
self.person_map = {}
|
||||
self.family_map = {}
|
||||
@ -182,6 +216,284 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
self.redo_callback = None
|
||||
self.undo_history_callback = None
|
||||
self.modified = 0
|
||||
self.txn = DjangoTxn("DbDjango Transaction", self)
|
||||
|
||||
def prepare_import(self):
|
||||
"""
|
||||
DbDjango does not commit data, but saves them for later
|
||||
commit.
|
||||
"""
|
||||
self.cache = {}
|
||||
|
||||
def commit_import(self):
|
||||
"""
|
||||
Commits the items that were queued up during the last import.
|
||||
"""
|
||||
for key in self.cache.keys():
|
||||
obj = self.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.Source):
|
||||
self.dji.add_source(obj.serialize())
|
||||
elif isinstance(obj, gen.lib.Note):
|
||||
self.dji.add_note(obj.serialize())
|
||||
for key in self.cache.keys():
|
||||
obj = self.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.Source):
|
||||
self.dji.add_source_detail(obj.serialize())
|
||||
elif isinstance(obj, gen.lib.Note):
|
||||
self.dji.add_note_detail(obj.serialize())
|
||||
|
||||
def transaction_commit(self, txn):
|
||||
pass
|
||||
|
||||
def enable_signals(self):
|
||||
pass
|
||||
|
||||
def request_rebuild(self):
|
||||
# FIXME: rebuild cache
|
||||
pass
|
||||
|
||||
def get_undodb(self):
|
||||
return None
|
||||
|
||||
def transaction_abort(self, txn):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _validated_id_prefix(val, default):
|
||||
if isinstance(val, basestring) and val:
|
||||
try:
|
||||
str_ = val % 1
|
||||
except TypeError: # missing conversion specifier
|
||||
prefix_var = val + "%d"
|
||||
except ValueError: # incomplete format
|
||||
prefix_var = default+"%04d"
|
||||
else:
|
||||
prefix_var = val # OK as given
|
||||
else:
|
||||
prefix_var = default+"%04d" # not a string or empty string
|
||||
return prefix_var
|
||||
|
||||
@staticmethod
|
||||
def __id2user_format(id_pattern):
|
||||
"""
|
||||
Return a method that accepts a Gramps ID and adjusts it to the users
|
||||
format.
|
||||
"""
|
||||
pattern_match = re.match(r"(.*)%[0 ](\d+)[diu]$", id_pattern)
|
||||
if pattern_match:
|
||||
str_prefix = pattern_match.group(1)
|
||||
nr_width = pattern_match.group(2)
|
||||
def closure_func(gramps_id):
|
||||
if gramps_id and gramps_id.startswith(str_prefix):
|
||||
id_number = gramps_id[len(str_prefix):]
|
||||
if id_number.isdigit():
|
||||
id_value = int(id_number, 10)
|
||||
if len(str(id_value)) > nr_width:
|
||||
# The ID to be imported is too large to fit in the
|
||||
# users format. For now just create a new ID,
|
||||
# because that is also what happens with IDs that
|
||||
# are identical to IDs already in the database. If
|
||||
# the problem of colliding import and already
|
||||
# present IDs is solved the code here also needs
|
||||
# some solution.
|
||||
gramps_id = id_pattern % 1
|
||||
else:
|
||||
gramps_id = id_pattern % id_value
|
||||
return gramps_id
|
||||
else:
|
||||
def closure_func(gramps_id):
|
||||
return gramps_id
|
||||
return closure_func
|
||||
|
||||
def set_person_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Person ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as I%d or I%04d.
|
||||
"""
|
||||
self.person_prefix = self._validated_id_prefix(val, "I")
|
||||
self.id2user_format = self.__id2user_format(self.person_prefix)
|
||||
|
||||
def set_source_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Source ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as S%d or S%04d.
|
||||
"""
|
||||
self.source_prefix = self._validated_id_prefix(val, "S")
|
||||
self.sid2user_format = self.__id2user_format(self.source_prefix)
|
||||
|
||||
def set_object_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS MediaObject ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as O%d or O%04d.
|
||||
"""
|
||||
self.mediaobject_prefix = self._validated_id_prefix(val, "O")
|
||||
self.oid2user_format = self.__id2user_format(self.mediaobject_prefix)
|
||||
|
||||
def set_place_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Place ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as P%d or P%04d.
|
||||
"""
|
||||
self.place_prefix = self._validated_id_prefix(val, "P")
|
||||
self.pid2user_format = self.__id2user_format(self.place_prefix)
|
||||
|
||||
def set_family_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Family ID values. The string is
|
||||
expected to be in the form of a simple text string, or in a format
|
||||
that contains a C/Python style format string using %d, such as F%d
|
||||
or F%04d.
|
||||
"""
|
||||
self.family_prefix = self._validated_id_prefix(val, "F")
|
||||
self.fid2user_format = self.__id2user_format(self.family_prefix)
|
||||
|
||||
def set_event_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Event ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as E%d or E%04d.
|
||||
"""
|
||||
self.event_prefix = self._validated_id_prefix(val, "E")
|
||||
self.eid2user_format = self.__id2user_format(self.event_prefix)
|
||||
|
||||
def set_repository_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Repository ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as R%d or R%04d.
|
||||
"""
|
||||
self.repository_prefix = self._validated_id_prefix(val, "R")
|
||||
self.rid2user_format = self.__id2user_format(self.repository_prefix)
|
||||
|
||||
def set_note_id_prefix(self, val):
|
||||
"""
|
||||
Set the naming template for GRAMPS Note ID values.
|
||||
|
||||
The string is expected to be in the form of a simple text string, or
|
||||
in a format that contains a C/Python style format string using %d,
|
||||
such as N%d or N%04d.
|
||||
"""
|
||||
self.note_prefix = self._validated_id_prefix(val, "N")
|
||||
self.nid2user_format = self.__id2user_format(self.note_prefix)
|
||||
|
||||
def __find_next_gramps_id(self, prefix, map_index, trans):
|
||||
"""
|
||||
Helper function for find_next_<object>_gramps_id methods
|
||||
"""
|
||||
index = prefix % map_index
|
||||
while trans.get(str(index), txn=self.txn) is not None:
|
||||
map_index += 1
|
||||
index = prefix % map_index
|
||||
map_index += 1
|
||||
return (map_index, index)
|
||||
|
||||
def find_next_person_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Person object based off the
|
||||
person ID prefix.
|
||||
"""
|
||||
self.pmap_index, gid = self.__find_next_gramps_id(self.person_prefix,
|
||||
self.pmap_index, self.id_trans)
|
||||
return gid
|
||||
|
||||
def find_next_place_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Place object based off the
|
||||
place ID prefix.
|
||||
"""
|
||||
self.lmap_index, gid = self.__find_next_gramps_id(self.place_prefix,
|
||||
self.lmap_index, self.pid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_event_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Event object based off the
|
||||
event ID prefix.
|
||||
"""
|
||||
self.emap_index, gid = self.__find_next_gramps_id(self.event_prefix,
|
||||
self.emap_index, self.eid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_object_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a MediaObject object based
|
||||
off the media object ID prefix.
|
||||
"""
|
||||
self.omap_index, gid = self.__find_next_gramps_id(self.mediaobject_prefix,
|
||||
self.omap_index, self.oid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_source_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Source object based off the
|
||||
source ID prefix.
|
||||
"""
|
||||
self.smap_index, gid = self.__find_next_gramps_id(self.source_prefix,
|
||||
self.smap_index, self.sid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_family_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Family object based off the
|
||||
family ID prefix.
|
||||
"""
|
||||
self.fmap_index, gid = self.__find_next_gramps_id(self.family_prefix,
|
||||
self.fmap_index, self.fid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_repository_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Respository object based
|
||||
off the repository ID prefix.
|
||||
"""
|
||||
self.rmap_index, gid = self.__find_next_gramps_id(self.repository_prefix,
|
||||
self.rmap_index, self.rid_trans)
|
||||
return gid
|
||||
|
||||
def find_next_note_gramps_id(self):
|
||||
"""
|
||||
Return the next available GRAMPS' ID for a Note object based off the
|
||||
note ID prefix.
|
||||
"""
|
||||
self.nmap_index, gid = self.__find_next_gramps_id(self.note_prefix,
|
||||
self.nmap_index, self.nid_trans)
|
||||
return gid
|
||||
|
||||
def get_mediapath(self):
|
||||
return None
|
||||
@ -196,11 +508,6 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
obj = gen.lib.Researcher()
|
||||
return obj
|
||||
|
||||
def get_event_from_handle(self, handle):
|
||||
obj = gen.lib.Event()
|
||||
obj.unserialize(self.dji.get_event(self.dji.Event.get(handle=handle)))
|
||||
return obj
|
||||
|
||||
def get_person_handles(self):
|
||||
return [item.handle for item in self.dji.Person.all()]
|
||||
|
||||
@ -228,51 +535,93 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
def get_tag_handles(self, sort_handles=False):
|
||||
return []
|
||||
|
||||
def get_event_from_handle(self, handle):
|
||||
try:
|
||||
event = self.dji.Event.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
self.make_event(event)
|
||||
|
||||
def get_family_from_handle(self, handle):
|
||||
#print "get_family_from_handle", handle
|
||||
family = self.dji.Family.get(handle=handle)
|
||||
obj = self.make_family(family)
|
||||
return obj
|
||||
try:
|
||||
family = self.dji.Family.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_family(family)
|
||||
|
||||
def get_family_from_gramps_id(self, gramps_id):
|
||||
#print "get_family_from_id", gramps_id
|
||||
try:
|
||||
family = self.dji.Family.get(gramps_id=gramps_id)
|
||||
except:
|
||||
return None
|
||||
obj = self.make_family(family)
|
||||
return obj
|
||||
return self.make_family(family)
|
||||
|
||||
def get_repository_from_handle(self, handle):
|
||||
return gen.lib.Repository.create(self.dji.get_repository(self.dji.Repository.get(handle=handle)))
|
||||
try:
|
||||
repository = self.dji.Repository.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_repository(repository)
|
||||
|
||||
def get_person_from_handle(self, handle):
|
||||
#print "get_person_from_handle", handle
|
||||
try:
|
||||
person = self.dji.Person.select_related().get(handle=handle)
|
||||
#person = self.dji.Person.select_related().get(handle=handle)
|
||||
person = self.dji.Person.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_person(person)
|
||||
|
||||
def make_repository(self, repository):
|
||||
if repository.cache:
|
||||
data = cPickle.loads(base64.decodestring(repository.cache))
|
||||
else:
|
||||
data = self.dji.get_family(family)
|
||||
return gen.lib.Repository.create(data)
|
||||
|
||||
def make_family(self, family):
|
||||
if family.cache:
|
||||
data = cPickle.loads(base64.decodestring(family.cache))
|
||||
obj = gen.lib.Family.create(data)
|
||||
else:
|
||||
data = self.dji.get_family(family)
|
||||
obj = gen.lib.Family.create(data)
|
||||
return obj
|
||||
return gen.lib.Family.create(data)
|
||||
|
||||
def make_person(self, person):
|
||||
if person.cache:
|
||||
data = cPickle.loads(base64.decodestring(person.cache))
|
||||
obj = gen.lib.Person.create(data)
|
||||
else:
|
||||
data = self.dji.get_person(person)
|
||||
obj = gen.lib.Person.create(data)
|
||||
return obj
|
||||
return gen.lib.Person.create(data)
|
||||
|
||||
def make_event(self, event):
|
||||
if event.cache:
|
||||
data = cPickle.loads(base64.decodestring(event.cache))
|
||||
else:
|
||||
data = self.dji.get_event(event)
|
||||
return gen.lib.Event.create(data)
|
||||
|
||||
def make_note(self, event):
|
||||
if note.cache:
|
||||
data = cPickle.loads(base64.decodestring(note.cache))
|
||||
else:
|
||||
data = self.dji.get_note(note)
|
||||
return gen.lib.Note.create(data)
|
||||
|
||||
def make_place(self, place):
|
||||
if place.cache:
|
||||
data = cPickle.loads(base64.decodestring(place.cache))
|
||||
else:
|
||||
data = self.dji.get_place(place)
|
||||
return gen.lib.Place.create(data)
|
||||
|
||||
def make_media(self, media):
|
||||
if media.cache:
|
||||
data = cPickle.loads(base64.decodestring(media.cache))
|
||||
else:
|
||||
data = self.dji.get_media(media)
|
||||
return gen.lib.Media.create(data)
|
||||
|
||||
def get_place_from_handle(self, handle):
|
||||
# FIXME: use cache
|
||||
try:
|
||||
dji_obj = self.dji.Place.get(handle=handle)
|
||||
except:
|
||||
@ -286,19 +635,25 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
return None
|
||||
|
||||
def get_source_from_handle(self, handle):
|
||||
obj = gen.lib.Source()
|
||||
obj.unserialize(self.dji.get_source(self.dji.Source.get(handle=handle)))
|
||||
return obj
|
||||
try:
|
||||
source = self.dji.Source.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_source(source)
|
||||
|
||||
def get_note_from_handle(self, handle):
|
||||
obj = gen.lib.Note()
|
||||
obj.unserialize(self.dji.get_note(self.dji.Note.get(handle=handle)))
|
||||
return obj
|
||||
try:
|
||||
note = self.dji.Note.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_note(note)
|
||||
|
||||
def get_object_from_handle(self, handle):
|
||||
obj = gen.lib.MediaObject()
|
||||
obj.unserialize(self.dji.get_media(self.dji.Media.get(handle=handle)))
|
||||
return obj
|
||||
try:
|
||||
media = self.dji.Media.get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
return self.make_media(media)
|
||||
|
||||
def get_media_object_handles(self):
|
||||
return [media.handle for media in self.dji.Media.all()]
|
||||
@ -324,7 +679,6 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
return (family.handle for family in self.dji.Family.all())
|
||||
|
||||
def get_person_from_gramps_id(self, gramps_id):
|
||||
#print "get_person_from_gramps_id", gramps_id
|
||||
match_list = self.dji.Person.filter(gramps_id=gramps_id)
|
||||
if match_list.count() > 0:
|
||||
return self.make_person(match_list[0])
|
||||
@ -386,138 +740,117 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
return self.dji.Place.filter(handle=handle).count() == 1
|
||||
|
||||
def get_raw_person_data(self, handle):
|
||||
return self.dji.get_person(self.dji.Person.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_person(self.dji.Person.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_raw_family_data(self, handle):
|
||||
return self.dji.get_family(self.dji.Family.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_family(self.dji.Family.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_raw_source_data(self, handle):
|
||||
return self.dji.get_source(self.dji.Source.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_source(self.dji.Source.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_raw_repository_data(self, handle):
|
||||
return self.dji.get_repository(self.dji.Repository.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_repository(self.dji.Repository.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_raw_note_data(self, handle):
|
||||
return self.dji.get_note(self.dji.Note.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_note(self.dji.Note.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def get_raw_place_data(self, handle):
|
||||
return self.dji.get_place(self.dji.Place.get(handle=handle))
|
||||
try:
|
||||
return self.dji.get_place(self.dji.Place.get(handle=handle))
|
||||
except:
|
||||
return None
|
||||
|
||||
def add_person(self, person, trans, set_gid=True):
|
||||
pass
|
||||
# if self.step == 0:
|
||||
# if not person.handle:
|
||||
# person.handle = Utils.create_id()
|
||||
# if not person.gramps_id:
|
||||
# person.gramps_id = self.find_next_person_gramps_id()
|
||||
# self.lookup[person.gramps_id] = person.handle
|
||||
# if self.dji.Person.filter(handle=person.handle).count() == 0:
|
||||
# print "add_person:", person.handle
|
||||
# self.dji.add_person(person.serialize())
|
||||
# else:
|
||||
# print "update_person:", person.handle
|
||||
# person.handle = self.lookup[person.gramps_id]
|
||||
# self.dji.add_person_detail(person.serialize())
|
||||
if not person.handle:
|
||||
person.handle = Utils.create_id()
|
||||
if not person.gramps_id:
|
||||
person.gramps_id = self.find_next_person_gramps_id()
|
||||
self.commit_person(person, trans)
|
||||
return person.handle
|
||||
|
||||
def add_family(self, family, trans, set_gid=True):
|
||||
pass
|
||||
# if self.step == 0:
|
||||
# if not family.handle:
|
||||
# family.handle = Utils.create_id()
|
||||
# if not family.gramps_id:
|
||||
# family.gramps_id = self.find_next_family_gramps_id()
|
||||
# self.lookup[family.gramps_id] = family.handle
|
||||
# if self.dji.Family.filter(handle=family.handle).count() == 0:
|
||||
# print "add_family:", family.handle
|
||||
# self.dji.add_family(family.serialize())
|
||||
# else:
|
||||
# family.handle = self.lookup[family.gramps_id]
|
||||
# self.dji.add_family_detail(family.serialize())
|
||||
if not family.handle:
|
||||
family.handle = Utils.create_id()
|
||||
if not family.gramps_id:
|
||||
family.gramps_id = self.find_next_family_gramps_id()
|
||||
self.commit_family(family, trans)
|
||||
return family.handle
|
||||
|
||||
def add_source(self, source, trans, set_gid=True):
|
||||
pass
|
||||
#print "add_source:", source.handle
|
||||
#if not source.handle:
|
||||
# source.handle = Utils.create_id()
|
||||
# self.dji.add_source(source.serialize())
|
||||
#self.dji.add_source_detail(source.serialize())
|
||||
if not source.handle:
|
||||
source.handle = Utils.create_id()
|
||||
if not source.gramps_id:
|
||||
source.gramps_id = self.find_next_source_gramps_id()
|
||||
self.commit_source(source, trans)
|
||||
return source.handle
|
||||
|
||||
def add_repository(self, repository, trans, set_gid=True):
|
||||
pass
|
||||
#print "add_repository:", repository.handle
|
||||
#if not repository.handle:
|
||||
# repository.handle = Utils.create_id()
|
||||
# self.dji.add_repository(repository.serialize())
|
||||
#self.dji.add_repository_detail(repository.serialize())
|
||||
if not repository.handle:
|
||||
repository.handle = Utils.create_id()
|
||||
if not repository.gramps_id:
|
||||
repository.gramps_id = self.find_next_repository_gramps_id()
|
||||
self.commit_repository(repository, trans)
|
||||
return repository.handle
|
||||
|
||||
def add_note(self, note, trans, set_gid=True):
|
||||
pass
|
||||
#print "add_note:", note.handle
|
||||
#if not note.handle:
|
||||
# note.handle = Utils.create_id()
|
||||
# self.dji.add_note(note.serialize())
|
||||
#self.dji.add_note_detail(note.serialize())
|
||||
if not note.handle:
|
||||
note.handle = Utils.create_id()
|
||||
if not note.gramps_id:
|
||||
note.gramps_id = self.find_next_note_gramps_id()
|
||||
self.commit_note(note, trans)
|
||||
return note.handle
|
||||
|
||||
def add_place(self, place, trans, set_gid=True):
|
||||
print "add_place:", place.handle
|
||||
pass
|
||||
if not place.handle:
|
||||
place.handle = Utils.create_id()
|
||||
if not place.gramps_id:
|
||||
place.gramps_id = self.find_next_place_gramps_id()
|
||||
self.commit_place(place, trans)
|
||||
return place.handle
|
||||
|
||||
def add_event(self, event, trans, set_gid=True):
|
||||
pass
|
||||
#print "add_event:", event.handle
|
||||
#if not event.handle:
|
||||
# event.handle = Utils.create_id()
|
||||
# self.dji.add_event(event.serialize())
|
||||
#self.dji.add_event_detail(event.serialize())
|
||||
if not event.handle:
|
||||
event.handle = Utils.create_id()
|
||||
if not event.gramps_id:
|
||||
event.gramps_id = self.find_next_event_gramps_id()
|
||||
self.commit_event(event, trans)
|
||||
return event.handle
|
||||
|
||||
def commit_person(self, person, trans, change_time=None):
|
||||
pass
|
||||
#print "commit_person:", person.handle
|
||||
#self.add_person(person, trans)
|
||||
self.cache[person.handle] = person
|
||||
|
||||
def commit_family(self, family, trans, change_time=None):
|
||||
pass
|
||||
#print "commit_family:", family.handle
|
||||
#self.add_family(family, trans)
|
||||
self.cache[family.handle] = family
|
||||
|
||||
def commit_source(self, source, trans, change_time=None):
|
||||
pass
|
||||
#print "commit_source:", source.handle
|
||||
#self.add_source(source, change_time)
|
||||
self.cache[source.handle] = source
|
||||
|
||||
def commit_repository(self, repository, trans, change_time=None):
|
||||
pass
|
||||
#print "commit_repository:", repository.handle
|
||||
#self.add_repository(repository, change_time)
|
||||
self.cache[repository.handle] = repository
|
||||
|
||||
def commit_note(self, note, trans, change_time=None):
|
||||
pass
|
||||
#print "commit_note:", note.handle
|
||||
#self.add_note(note, change_time)
|
||||
self.cache[note.handle] = note
|
||||
|
||||
def commit_place(self, place, trans, change_time=None):
|
||||
print "commit_place:", place.handle
|
||||
if self.dji.Place.filter(handle=place.handle).count() == 0:
|
||||
self.dji.add_place(place.serialize())
|
||||
self.dji.add_place_detail(place.serialize())
|
||||
|
||||
def commit_event(self, event, change_time=None):
|
||||
pass
|
||||
#print "commit_event:", event.handle
|
||||
#self.add_event(event, change_time)
|
||||
|
||||
# def find_family_from_handle(self, handle, trans):
|
||||
# obj = gen.lib.Family()
|
||||
# results = self.dji.Family.filter(handle=handle)
|
||||
# if results.count() == 0:
|
||||
# obj.handle = handle
|
||||
# new = True
|
||||
# else:
|
||||
# data = self.dji.get_family(results[0])
|
||||
# obj.unserialize(data)
|
||||
# new = False
|
||||
# return obj, new
|
||||
self.cache[place.handle] = place
|
||||
|
||||
def commit_event(self, event, trans, change_time=None):
|
||||
self.cache[event.handle] = event
|
||||
|
||||
def get_gramps_ids(self, obj_key):
|
||||
key2table = {
|
||||
@ -534,10 +867,6 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
table = key2table[obj_key]
|
||||
return table.keys()
|
||||
|
||||
def get_gramps_ids(self, obj_key):
|
||||
print "object key:", obj_key
|
||||
return []
|
||||
|
||||
def transaction_begin(self, transaction):
|
||||
return
|
||||
|
||||
@ -547,5 +876,3 @@ class DbDjango(DbWriteBase, DbReadBase):
|
||||
def set_researcher(self, owner):
|
||||
pass
|
||||
|
||||
def find_next_place_gramps_id(self):
|
||||
return "P0"
|
||||
|
@ -1051,6 +1051,7 @@ class DjangoInterface(object):
|
||||
last_changed=todate(change),
|
||||
private=private,
|
||||
gender_type=models.get_type(models.GenderType, gender))
|
||||
person.cache = base64.encodestring(cPickle.dumps(data))
|
||||
person.save()
|
||||
|
||||
def add_person_detail(self, data):
|
||||
@ -1139,6 +1140,7 @@ class DjangoInterface(object):
|
||||
preformatted=format,
|
||||
text=text,
|
||||
note_type=models.get_type(models.NoteType, note_type))
|
||||
n.cache = base64.encodestring(cPickle.dumps(data))
|
||||
n.save()
|
||||
count = 1
|
||||
for markup in markup_list:
|
||||
@ -1162,6 +1164,7 @@ class DjangoInterface(object):
|
||||
family_rel_type = models.get_type(models.FamilyRelType, the_type),
|
||||
last_changed=todate(change),
|
||||
private=private)
|
||||
family.cache = base64.encodestring(cPickle.dumps(data))
|
||||
family.save()
|
||||
|
||||
def add_family_detail(self, data):
|
||||
@ -1213,6 +1216,7 @@ class DjangoInterface(object):
|
||||
source = models.Source(handle=handle, gramps_id=gid, title=title,
|
||||
author=author, pubinfo=pubinfo, abbrev=abbrev,
|
||||
last_changed=todate(change), private=private)
|
||||
source.cache = base64.encodestring(cPickle.dumps(data))
|
||||
source.save()
|
||||
|
||||
def add_source_detail(self, data):
|
||||
@ -1245,6 +1249,7 @@ class DjangoInterface(object):
|
||||
private=private,
|
||||
repository_type=models.get_type(models.RepositoryType, the_type),
|
||||
name=name)
|
||||
repository.cache = base64.encodestring(cPickle.dumps(data))
|
||||
repository.save()
|
||||
|
||||
def add_repository_detail(self, data):
|
||||
@ -1308,6 +1313,7 @@ class DjangoInterface(object):
|
||||
place = models.Place(handle=handle, gramps_id=gid, title=title,
|
||||
long=long, lat=lat, last_changed=todate(change),
|
||||
private=private)
|
||||
place.cache = base64.encodestring(cPickle.dumps(data))
|
||||
place.save()
|
||||
|
||||
def add_place_detail(self, data):
|
||||
@ -1347,6 +1353,7 @@ class DjangoInterface(object):
|
||||
path=path, mime=mime,
|
||||
desc=desc, last_changed=todate(change),
|
||||
private=private)
|
||||
media.cache = base64.encodestring(cPickle.dumps(data))
|
||||
self.add_date(media, date)
|
||||
media.save()
|
||||
|
||||
@ -1379,6 +1386,7 @@ class DjangoInterface(object):
|
||||
private=private,
|
||||
description=description,
|
||||
last_changed=todate(change))
|
||||
event.cache = base64.encodestring(cPickle.dumps(data))
|
||||
self.add_date(event, date)
|
||||
event.save()
|
||||
|
||||
|
@ -603,71 +603,6 @@ def person_get_event(person, event_type=None):
|
||||
for event_handle in event_ref_list]
|
||||
return [j for i in retval for j in i]
|
||||
|
||||
class lazy(object):
|
||||
EMPTY = []
|
||||
used = 0
|
||||
total = 0
|
||||
def __init__(self, func, *args, **kwargs):
|
||||
self.func = func
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.result = lazy.EMPTY
|
||||
lazy.used = lazy.used + 1
|
||||
lazy.total = lazy.total + 1
|
||||
#print "freeze:", func, args
|
||||
|
||||
def thaw(self):
|
||||
self.result = object.__getattribute__(self, "func")(*object.__getattribute__(self, "args"),
|
||||
**object.__getattribute__(self, "kwargs"))
|
||||
#print "thaw:", object.__getattribute__(self, "func"), object.__getattribute__(self, "result")
|
||||
lazy.used = lazy.used - 1
|
||||
|
||||
def __getattribute__(self, attr):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return getattr(object.__getattribute__(self, "result"), attr)
|
||||
|
||||
def myclass(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return object.__getattribute__(self, "result").__class__
|
||||
|
||||
#__class__ = property(myclass)
|
||||
|
||||
def __str__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return str(object.__getattribute__(self, "result"))
|
||||
|
||||
def __int__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return int(object.__getattribute__(self, "result"))
|
||||
|
||||
def __float__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return float(object.__getattribute__(self, "result"))
|
||||
|
||||
def __repr__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return repr(object.__getattribute__(self, "result"))
|
||||
|
||||
def __getitem__(self, pos):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return object.__getattribute__(self, "result")[pos]
|
||||
|
||||
def __len__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return len(object.__getattribute__(self, "result"))
|
||||
|
||||
def freeze(item):
|
||||
return lazy(lambda i: i, item)
|
||||
|
||||
|
||||
register_plugins()
|
||||
|
||||
# works after registering plugins:
|
||||
|
Loading…
Reference in New Issue
Block a user