DictionaryDb: reworked internal reprs; updated gender stats, researcher

This commit is contained in:
Doug Blank 2015-05-15 22:50:54 -04:00
parent a1d44d0246
commit 87d2cfb301
2 changed files with 213 additions and 145 deletions

View File

@ -38,7 +38,8 @@ import logging
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.gen.db import DbReadBase, DbWriteBase, DbTxn, KEY_TO_NAME_MAP from gramps.gen.db import (DbReadBase, DbWriteBase, DbTxn,
KEY_TO_NAME_MAP, KEY_TO_CLASS_MAP)
from gramps.gen.db.undoredo import DbUndo from gramps.gen.db.undoredo import DbUndo
from gramps.gen.db.dbconst import * from gramps.gen.db.dbconst import *
from gramps.gen.utils.callback import Callback from gramps.gen.utils.callback import Callback
@ -66,6 +67,7 @@ from gramps.gen.lib.place import Place
from gramps.gen.lib.repo import Repository from gramps.gen.lib.repo import Repository
from gramps.gen.lib.note import Note from gramps.gen.lib.note import Note
from gramps.gen.lib.tag import Tag from gramps.gen.lib.tag import Tag
from gramps.gen.lib.genderstats import GenderStats
_LOG = logging.getLogger(DBLOGNAME) _LOG = logging.getLogger(DBLOGNAME)
@ -99,8 +101,8 @@ class Table(object):
""" """
return self.funcs["cursor_func"]() return self.funcs["cursor_func"]()
def put(key, data, txn=None): def put(self, key, data, txn=None):
self[key] = data self.funcs["add_func"](data, txn)
class Map(dict): class Map(dict):
""" """
@ -137,15 +139,14 @@ class MetaCursor(object):
pass pass
class Cursor(object): class Cursor(object):
def __init__(self, map, func): def __init__(self, map):
self.map = map self.map = map
self.func = func
self._iter = self.__iter__() self._iter = self.__iter__()
def __enter__(self): def __enter__(self):
return self return self
def __iter__(self): def __iter__(self):
for item in self.map.keys(): for item in self.map.keys():
yield (bytes(item, "utf-8"), self.func(item)) yield (bytes(item, "utf-8"), self.map[item])
def __next__(self): def __next__(self):
try: try:
return self._iter.__next__() return self._iter.__next__()
@ -155,7 +156,7 @@ class Cursor(object):
pass pass
def iter(self): def iter(self):
for item in self.map.keys(): for item in self.map.keys():
yield (bytes(item, "utf-8"), self.func(item)) yield (bytes(item, "utf-8"), self.map[item])
def first(self): def first(self):
self._iter = self.__iter__() self._iter = self.__iter__()
try: try:
@ -383,15 +384,25 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.nmap_index = 0 self.nmap_index = 0
self.env = Environment(self) self.env = Environment(self)
self.person_map = Map(Table(self._tables["Person"])) self.person_map = Map(Table(self._tables["Person"]))
self.person_id_map = {}
self.family_map = Map(Table(self._tables["Family"])) self.family_map = Map(Table(self._tables["Family"]))
self.family_id_map = {}
self.place_map = Map(Table(self._tables["Place"])) self.place_map = Map(Table(self._tables["Place"]))
self.place_id_map = {}
self.citation_map = Map(Table(self._tables["Citation"])) self.citation_map = Map(Table(self._tables["Citation"]))
self.citation_id_map = {}
self.source_map = Map(Table(self._tables["Source"])) self.source_map = Map(Table(self._tables["Source"]))
self.source_id_map = {}
self.repository_map = Map(Table(self._tables["Repository"])) self.repository_map = Map(Table(self._tables["Repository"]))
self.repository_id_map = {}
self.note_map = Map(Table(self._tables["Note"])) self.note_map = Map(Table(self._tables["Note"]))
self.note_id_map = {}
self.media_map = Map(Table(self._tables["Media"])) self.media_map = Map(Table(self._tables["Media"]))
self.media_id_map = {}
self.event_map = Map(Table(self._tables["Event"])) self.event_map = Map(Table(self._tables["Event"]))
self.event_id_map = {}
self.tag_map = Map(Table(self._tables["Tag"])) self.tag_map = Map(Table(self._tables["Tag"]))
self.tag_id_map = {}
self.metadata = Map(Table({"cursor_func": lambda: MetaCursor()})) self.metadata = Map(Table({"cursor_func": lambda: MetaCursor()}))
self.name_group = {} self.name_group = {}
self.undo_callback = None self.undo_callback = None
@ -407,6 +418,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.full_name = None self.full_name = None
self.path = None self.path = None
self.brief_name = None self.brief_name = None
self.genderStats = GenderStats() # can pass in loaded stats as dict
self.owner = Researcher()
if directory: if directory:
self.load(directory) self.load(directory)
@ -425,12 +438,15 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def transaction_commit(self, txn): def transaction_commit(self, txn):
## FIXME
pass pass
def get_undodb(self): def get_undodb(self):
## FIXME
return None return None
def transaction_abort(self, txn): def transaction_abort(self, txn):
## FIXME
pass pass
@staticmethod @staticmethod
@ -687,10 +703,12 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
## Fixme: implement sort ## Fixme: implement sort
return self.person_map.keys() return self.person_map.keys()
def get_family_handles(self): def get_family_handles(self, sort_handles=False):
## Fixme: implement sort
return self.family_map.keys() return self.family_map.keys()
def get_event_handles(self, sort_handles=False): def get_event_handles(self, sort_handles=False):
## Fixme: implement sort
return self.event_map.keys() return self.event_map.keys()
def get_citation_handles(self, sort_handles=False): def get_citation_handles(self, sort_handles=False):
@ -705,78 +723,80 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
## Fixme: implement sort ## Fixme: implement sort
return self.place_map.keys() return self.place_map.keys()
def get_repository_handles(self): def get_repository_handles(self, sort_handles=False):
## Fixme: implement sort
return self.repository_map.keys() return self.repository_map.keys()
def get_media_object_handles(self, sort_handles=False): def get_media_object_handles(self, sort_handles=False):
## Fixme: implement sort ## Fixme: implement sort
return self.media_map.keys() return self.media_map.keys()
def get_note_handles(self): def get_note_handles(self, sort_handles=False):
## Fixme: implement sort
return self.note_map.keys() return self.note_map.keys()
def get_tag_handles(self, sort_handles=False): def get_tag_handles(self, sort_handles=False):
# FIXME: sort # FIXME: implement sort
return self.tag_map.keys() return self.tag_map.keys()
def get_event_from_handle(self, handle): def get_event_from_handle(self, handle):
event = None event = None
if handle in self.event_map: if handle in self.event_map:
event = self.event_map[handle] event = Event.create(self.event_map[handle])
return event return event
def get_family_from_handle(self, handle): def get_family_from_handle(self, handle):
family = None family = None
if handle in self.family_map: if handle in self.family_map:
family = self.family_map[handle] family = Family.create(self.family_map[handle])
return family return family
def get_repository_from_handle(self, handle): def get_repository_from_handle(self, handle):
repository = None repository = None
if handle in self.repository_map: if handle in self.repository_map:
repository = self.repository_map[handle] repository = Repository.create(self.repository_map[handle])
return repository return repository
def get_person_from_handle(self, handle): def get_person_from_handle(self, handle):
person = None person = None
if handle in self.person_map: if handle in self.person_map:
person = self.person_map[handle] person = Person.create(self.person_map[handle])
return person return person
def get_place_from_handle(self, handle): def get_place_from_handle(self, handle):
place = None place = None
if handle in self.place_map: if handle in self.place_map:
place = self.place_map[handle] place = Place.create(self.place_map[handle])
return place return place
def get_citation_from_handle(self, handle): def get_citation_from_handle(self, handle):
citation = None citation = None
if handle in self.citation_map: if handle in self.citation_map:
citation = self.citation_map[handle] citation = Citation.create(self.citation_map[handle])
return citation return citation
def get_source_from_handle(self, handle): def get_source_from_handle(self, handle):
source = None source = None
if handle in self.source_map: if handle in self.source_map:
source = self.source_map[handle] source = Source.create(self.source_map[handle])
return source return source
def get_note_from_handle(self, handle): def get_note_from_handle(self, handle):
note = None note = None
if handle in self.note_map: if handle in self.note_map:
note = self.note_map[handle] note = Note.create(self.note_map[handle])
return note return note
def get_object_from_handle(self, handle): def get_object_from_handle(self, handle):
media = None media = None
if handle in self.media_map: if handle in self.media_map:
media = self.media_map[handle] media = MediaObject.create(self.media_map[handle])
return media return media
def get_tag_from_handle(self, handle): def get_tag_from_handle(self, handle):
tag = None tag = None
if handle in self.tag_map: if handle in self.tag_map:
tag = self.tag_map[handle] tag = Tag.create(self.tag_map[handle])
return tag return tag
def get_default_person(self): def get_default_person(self):
@ -787,81 +807,73 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def iter_people(self): def iter_people(self):
return (person for person in self.person_map.values()) return (Person.create(person) for person in self.person_map.values())
def iter_person_handles(self): def iter_person_handles(self):
return (handle for handle in self.person_map.keys()) return (handle for handle in self.person_map.keys())
def iter_families(self): def iter_families(self):
return (family for family in self.family_map.values()) return (Family.create(family) for family in self.family_map.values())
def iter_family_handles(self): def iter_family_handles(self):
return (handle for handle in self.family_map.keys()) return (handle for handle in self.family_map.keys())
def get_tag_from_name(self, name): def get_tag_from_name(self, name):
for tag in self.tag_map.values(): ## Slow, but typically not too many tags:
for data in self.tag_map.values():
tag = Tag.create(data)
if tag.name == name: if tag.name == name:
return tag return tag
return None return None
def get_person_from_gramps_id(self, gramps_id): def get_person_from_gramps_id(self, gramps_id):
for person in self.person_map.values(): if gramps_id in self.person_id_map:
if person.gramps_id == gramps_id: return Person.create(self.person_id_map[gramps_id])
return person
return None return None
def get_family_from_gramps_id(self, gramps_id): def get_family_from_gramps_id(self, gramps_id):
for family in self.family_map.values(): if gramps_id in self.family_id_map:
if family.gramps_id == gramps_id: return Family.create(self.family_id_map[gramps_id])
return family
return None return None
def get_citation_from_gramps_id(self, gramps_id): def get_citation_from_gramps_id(self, gramps_id):
for citation in self.citation_map.values(): if gramps_id in self.citation_id_map:
if citation.gramps_id == gramps_id: return Citation.create(self.citation_id_map[gramps_id])
return citation
return None return None
def get_source_from_gramps_id(self, gramps_id): def get_source_from_gramps_id(self, gramps_id):
for source in self.source_map.values(): if gramps_id in self.source_id_map:
if source.gramps_id == gramps_id: return Source.create(self.source_id_map[gramps_id])
return source
return None return None
def get_event_from_gramps_id(self, gramps_id): def get_event_from_gramps_id(self, gramps_id):
for event in self.event_map.values(): if gramps_id in self.event_id_map:
if event.gramps_id == gramps_id: return Event.create(self.event_id_map[gramps_id])
return event
return None return None
def get_media_from_gramps_id(self, gramps_id): def get_media_from_gramps_id(self, gramps_id):
for media in self.media_map.values(): if gramps_id in self.media_id_map:
if media.gramps_id == gramps_id: return MediaObject.create(self.media_id_map[gramps_id])
return media
return None return None
def get_place_from_gramps_id(self, gramps_id): def get_place_from_gramps_id(self, gramps_id):
for place in self.place_map.values(): if gramps_id in self.place_id_map:
if place.gramps_id == gramps_id: return Place.create(self.place_id_map[gramps_id])
return place
return None return None
def get_repository_from_gramps_id(self, gramps_id): def get_repository_from_gramps_id(self, gramps_id):
for repository in self.repository_map.values(): if gramps_id in self.repository_id_map:
if repository.gramps_id == gramps_id: return Repository.create(self.repository_id_map[gramps_id])
return repository
return None return None
def get_note_from_gramps_id(self, gramps_id): def get_note_from_gramps_id(self, gramps_id):
for note in self.note_map.values(): if gramps_id in self.note_id_map:
if note.gramps_id == gramps_id: return Note.create(self.note_id_map[gramps_id])
return note
return None return None
def get_tag_from_gramps_id(self, gramps_id): def get_tag_from_gramps_id(self, gramps_id):
for tag in self.tag_map.values(): if gramps_id in self.tag_id_map:
if tag.gramps_id == gramps_id: return Tag.create(self.tag_id_map[gramps_id])
return tag
return None return None
def get_number_of_people(self): def get_number_of_people(self):
@ -874,7 +886,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return len(self.place_map) return len(self.place_map)
def get_number_of_tags(self): def get_number_of_tags(self):
return 0 # FIXME return len(self.tag_map)
def get_number_of_families(self): def get_number_of_families(self):
return len(self.family_map) return len(self.family_map)
@ -895,52 +907,48 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return len(self.repository_map) return len(self.repository_map)
def get_place_cursor(self): def get_place_cursor(self):
return Cursor(self.place_map, self.get_raw_place_data) return Cursor(self.place_map)
def get_person_cursor(self): def get_person_cursor(self):
return Cursor(self.person_map, self.get_raw_person_data) return Cursor(self.person_map)
def get_family_cursor(self): def get_family_cursor(self):
return Cursor(self.family_map, self.get_raw_family_data) return Cursor(self.family_map)
def get_event_cursor(self): def get_event_cursor(self):
return Cursor(self.event_map, self.get_raw_event_data) return Cursor(self.event_map)
def get_note_cursor(self): def get_note_cursor(self):
return Cursor(self.note_map, self.get_raw_note_data) return Cursor(self.note_map)
def get_tag_cursor(self): def get_tag_cursor(self):
return Cursor(self.tag_map, self.get_raw_tag_data) return Cursor(self.tag_map)
def get_repository_cursor(self): def get_repository_cursor(self):
return Cursor(self.repository_map, self.get_raw_repository_data) return Cursor(self.repository_map)
def get_media_cursor(self): def get_media_cursor(self):
return Cursor(self.media_map, self.get_raw_object_data) return Cursor(self.media_map)
def get_citation_cursor(self): def get_citation_cursor(self):
return Cursor(self.citation_map, self.get_raw_citation_data) return Cursor(self.citation_map)
def get_source_cursor(self): def get_source_cursor(self):
return Cursor(self.source_map, self.get_raw_source_data) return Cursor(self.source_map)
def has_gramps_id(self, obj_key, gramps_id): def has_gramps_id(self, obj_key, gramps_id):
key2table = { key2table = {
PERSON_KEY: self.person_map, PERSON_KEY: self.person_id_map,
FAMILY_KEY: self.family_map, FAMILY_KEY: self.family_id_map,
SOURCE_KEY: self.source_map, SOURCE_KEY: self.source_id_map,
CITATION_KEY: self.citation_map, CITATION_KEY: self.citation_id_map,
EVENT_KEY: self.event_map, EVENT_KEY: self.event_id_map,
MEDIA_KEY: self.media_map, MEDIA_KEY: self.media_id_map,
PLACE_KEY: self.place_map, PLACE_KEY: self.place_id_map,
REPOSITORY_KEY: self.repository_map, REPOSITORY_KEY: self.repository_id_map,
NOTE_KEY: self.note_map, NOTE_KEY: self.note_id_map,
} }
map = key2table[obj_key] return gramps_id in key2table[obj_key]
for item in map.values():
if item.gramps_id == gramps_id:
return True
return False
def has_person_handle(self, handle): def has_person_handle(self, handle):
return handle in self.person_map return handle in self.person_map
@ -981,59 +989,61 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
pass pass
def set_default_person_handle(self, handle): def set_default_person_handle(self, handle):
## FIXME
pass pass
def set_mediapath(self, mediapath): def set_mediapath(self, mediapath):
## FIXME
pass pass
def get_raw_person_data(self, handle): def get_raw_person_data(self, handle):
if handle in self.person_map: if handle in self.person_map:
return self.person_map[handle].serialize() return self.person_map[handle]
return None return None
def get_raw_family_data(self, handle): def get_raw_family_data(self, handle):
if handle in self.family_map: if handle in self.family_map:
return self.family_map[handle].serialize() return self.family_map[handle]
return None return None
def get_raw_citation_data(self, handle): def get_raw_citation_data(self, handle):
if handle in self.citation_map: if handle in self.citation_map:
return self.citation_map[handle].serialize() return self.citation_map[handle]
return None return None
def get_raw_source_data(self, handle): def get_raw_source_data(self, handle):
if handle in self.source_map: if handle in self.source_map:
return self.source_map[handle].serialize() return self.source_map[handle]
return None return None
def get_raw_repository_data(self, handle): def get_raw_repository_data(self, handle):
if handle in self.repository_map: if handle in self.repository_map:
return self.repository_map[handle].serialize() return self.repository_map[handle]
return None return None
def get_raw_note_data(self, handle): def get_raw_note_data(self, handle):
if handle in self.note_map: if handle in self.note_map:
return self.note_map[handle].serialize() return self.note_map[handle]
return None return None
def get_raw_place_data(self, handle): def get_raw_place_data(self, handle):
if handle in self.place_map: if handle in self.place_map:
return self.place_map[handle].serialize() return self.place_map[handle]
return None return None
def get_raw_object_data(self, handle): def get_raw_object_data(self, handle):
if handle in self.media_map: if handle in self.media_map:
return self.media_map[handle].serialize() return self.media_map[handle]
return None return None
def get_raw_tag_data(self, handle): def get_raw_tag_data(self, handle):
if handle in self.tag_map: if handle in self.tag_map:
return self.tag_map[handle].serialize() return self.tag_map[handle]
return None return None
def get_raw_event_data(self, handle): def get_raw_event_data(self, handle):
if handle in self.event_map: if handle in self.event_map:
return self.event_map[handle].serialize() return self.event_map[handle]
return None return None
def add_person(self, person, trans, set_gid=True): def add_person(self, person, trans, set_gid=True):
@ -1127,7 +1137,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "person-update" emit = "person-update"
else: else:
emit = "person-add" emit = "person-add"
self.person_map[person.handle] = person self.person_map[person.handle] = person.serialize()
self.person_id_map[person.gramps_id] = self.person_map[person.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([person.handle],)) self.emit(emit, ([person.handle],))
@ -1139,7 +1150,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "family-update" emit = "family-update"
else: else:
emit = "family-add" emit = "family-add"
self.family_map[family.handle] = family self.family_map[family.handle] = family.serialize()
self.family_id_map[family.gramps_id] = self.family_map[family.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([family.handle],)) self.emit(emit, ([family.handle],))
@ -1151,7 +1163,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "citation-update" emit = "citation-update"
else: else:
emit = "citation-add" emit = "citation-add"
self.citation_map[citation.handle] = citation self.citation_map[citation.handle] = citation.serialize()
self.citation_id_map[citation.gramps_id] = self.citation_map[citation.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([citation.handle],)) self.emit(emit, ([citation.handle],))
@ -1163,7 +1176,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "source-update" emit = "source-update"
else: else:
emit = "source-add" emit = "source-add"
self.source_map[source.handle] = source self.source_map[source.handle] = source.serialize()
self.source_id_map[source.gramps_id] = self.source_map[source.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([source.handle],)) self.emit(emit, ([source.handle],))
@ -1175,7 +1189,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "repository-update" emit = "repository-update"
else: else:
emit = "repository-add" emit = "repository-add"
self.repository_map[repository.handle] = repository self.repository_map[repository.handle] = repository.serialize()
self.repository_id_map[repository.gramps_id] = self.repository_map[repository.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([repository.handle],)) self.emit(emit, ([repository.handle],))
@ -1187,7 +1202,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "note-update" emit = "note-update"
else: else:
emit = "note-add" emit = "note-add"
self.note_map[note.handle] = note self.note_map[note.handle] = note.serialize()
self.note_id_map[note.gramps_id] = self.note_map[note.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([note.handle],)) self.emit(emit, ([note.handle],))
@ -1199,7 +1215,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "place-update" emit = "place-update"
else: else:
emit = "place-add" emit = "place-add"
self.place_map[place.handle] = place self.place_map[place.handle] = place.serialize()
self.place_id_map[place.gramps_id] = self.place_map[place.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([place.handle],)) self.emit(emit, ([place.handle],))
@ -1211,7 +1228,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "event-update" emit = "event-update"
else: else:
emit = "event-add" emit = "event-add"
self.event_map[event.handle] = event self.event_map[event.handle] = event.serialize()
self.event_id_map[event.gramps_id] = self.event_map[event.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([event.handle],)) self.emit(emit, ([event.handle],))
@ -1223,7 +1241,8 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "tag-update" emit = "tag-update"
else: else:
emit = "tag-add" emit = "tag-add"
self.tag_map[tag.handle] = tag self.tag_map[tag.handle] = tag.serialize()
self.tag_id_map[tag.gramps_id] = self.tag_map[tag.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([tag.handle],)) self.emit(emit, ([tag.handle],))
@ -1235,34 +1254,35 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
emit = "media-update" emit = "media-update"
else: else:
emit = "media-add" emit = "media-add"
self.media_map[media.handle] = media self.media_map[media.handle] = media.serialize()
self.media_id_map[media.gramps_id] = self.media_map[media.handle]
# Emit after added: # Emit after added:
if emit: if emit:
self.emit(emit, ([media.handle],)) self.emit(emit, ([media.handle],))
def get_gramps_ids(self, obj_key): def get_gramps_ids(self, obj_key):
key2table = { key2table = {
PERSON_KEY: self.person_map, PERSON_KEY: self.person_id_map,
FAMILY_KEY: self.family_map, FAMILY_KEY: self.family_id_map,
CITATION_KEY: self.citation_map, CITATION_KEY: self.citation_id_map,
SOURCE_KEY: self.source_map, SOURCE_KEY: self.source_id_map,
EVENT_KEY: self.event_map, EVENT_KEY: self.event_id_map,
MEDIA_KEY: self.media_map, MEDIA_KEY: self.media_id_map,
PLACE_KEY: self.place_map, PLACE_KEY: self.place_id_map,
REPOSITORY_KEY: self.repository_map, REPOSITORY_KEY: self.repository_id_map,
NOTE_KEY: self.note_map, NOTE_KEY: self.note_id_map,
} }
table = key2table[obj_key] return list(key2table[obj_key].keys())
return [item.gramps_id for item in table.values()]
def transaction_begin(self, transaction): def transaction_begin(self, transaction):
## FIXME
return return
def disable_signals(self):
pass
def set_researcher(self, owner): def set_researcher(self, owner):
pass self.owner.set_from(owner)
def get_researcher(self):
return self.owner
def request_rebuild(self): def request_rebuild(self):
self.emit('person-rebuild') self.emit('person-rebuild')
@ -1332,7 +1352,9 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
if self.readonly or not handle: if self.readonly or not handle:
return return
if handle in self.person_map: if handle in self.person_map:
person = Person.create(self.person_map[handle])
del self.person_map[handle] del self.person_map[handle]
del self.person_id_map[person.gramps_id]
self.emit("person-delete", ([handle],)) self.emit("person-delete", ([handle],))
def remove_source(self, handle, transaction): def remove_source(self, handle, transaction):
@ -1341,7 +1363,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.source_map, self.__do_remove(handle, transaction, self.source_map,
SOURCE_KEY) self.source_id_map, SOURCE_KEY)
def remove_citation(self, handle, transaction): def remove_citation(self, handle, transaction):
""" """
@ -1349,7 +1371,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.citation_map, self.__do_remove(handle, transaction, self.citation_map,
CITATION_KEY) self.citation_id_map, CITATION_KEY)
def remove_event(self, handle, transaction): def remove_event(self, handle, transaction):
""" """
@ -1357,7 +1379,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.event_map, self.__do_remove(handle, transaction, self.event_map,
EVENT_KEY) self.event_id_map, EVENT_KEY)
def remove_object(self, handle, transaction): def remove_object(self, handle, transaction):
""" """
@ -1365,7 +1387,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.media_map, self.__do_remove(handle, transaction, self.media_map,
MEDIA_KEY) self.media_id_map, MEDIA_KEY)
def remove_place(self, handle, transaction): def remove_place(self, handle, transaction):
""" """
@ -1373,7 +1395,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.place_map, self.__do_remove(handle, transaction, self.place_map,
PLACE_KEY) self.place_id_map, PLACE_KEY)
def remove_family(self, handle, transaction): def remove_family(self, handle, transaction):
""" """
@ -1381,7 +1403,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.family_map, self.__do_remove(handle, transaction, self.family_map,
FAMILY_KEY) self.family_id_map, FAMILY_KEY)
def remove_repository(self, handle, transaction): def remove_repository(self, handle, transaction):
""" """
@ -1389,7 +1411,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.repository_map, self.__do_remove(handle, transaction, self.repository_map,
REPOSITORY_KEY) self.repository_id_map, REPOSITORY_KEY)
def remove_note(self, handle, transaction): def remove_note(self, handle, transaction):
""" """
@ -1397,7 +1419,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.note_map, self.__do_remove(handle, transaction, self.note_map,
NOTE_KEY) self.note_id_map, NOTE_KEY)
def remove_tag(self, handle, transaction): def remove_tag(self, handle, transaction):
""" """
@ -1405,7 +1427,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
database, preserving the change in the passed transaction. database, preserving the change in the passed transaction.
""" """
self.__do_remove(handle, transaction, self.tag_map, self.__do_remove(handle, transaction, self.tag_map,
TAG_KEY) self.tag_id_map, TAG_KEY)
def is_empty(self): def is_empty(self):
""" """
@ -1416,13 +1438,13 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return False return False
return True return True
def __do_remove(self, handle, transaction, data_map, key): def __do_remove(self, handle, transaction, data_map, data_id_map, key):
if self.readonly or not handle: if self.readonly or not handle:
return return
if isinstance(handle, str):
handle = handle.encode('utf-8')
if handle in data_map: if handle in data_map:
obj = self._tables[KEY_TO_CLASS_MAP[key]]["class_func"].create(data_map[handle])
del data_map[handle] del data_map[handle]
del data_id_map[obj.gramps_id]
self.emit(KEY_TO_NAME_MAP[key] + "-delete", ([handle],)) self.emit(KEY_TO_NAME_MAP[key] + "-delete", ([handle],))
def delete_primary_from_reference_map(self, handle, transaction, txn=None): def delete_primary_from_reference_map(self, handle, transaction, txn=None):
@ -1486,6 +1508,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
## Missing: ## Missing:
def backup(self): def backup(self):
## FIXME
pass pass
def close(self): def close(self):
@ -1499,6 +1522,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
touch(filename) touch(filename)
def find_backlink_handles(self, handle, include_classes=None): def find_backlink_handles(self, handle, include_classes=None):
## FIXME
return [] return []
def find_initial_person(self): def find_initial_person(self):
@ -1508,22 +1532,30 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def find_place_child_handles(self, handle): def find_place_child_handles(self, handle):
## FIXME
return [] return []
def get_bookmarks(self): def get_bookmarks(self):
return self.bookmarks return self.bookmarks
def get_child_reference_types(self): def get_child_reference_types(self):
## FIXME
return [] return []
def get_citation_bookmarks(self): def get_citation_bookmarks(self):
return self.citation_bookmarks return self.citation_bookmarks
def get_cursor(self, table, txn=None, update=False, commit=False): def get_cursor(self, table, txn=None, update=False, commit=False):
## FIXME
## called from a complete find_back_ref
pass pass
def get_dbname(self): # cursors for lookups in the reference_map for back reference
return "DictionaryDb" # lookups. The reference_map has three indexes:
# the main index: a tuple of (primary_handle, referenced_handle)
# the primary_handle index: the primary_handle
# the referenced_handle index: the referenced_handle
# the main index is unique, the others allow duplicate entries.
def get_default_handle(self): def get_default_handle(self):
items = self.person_map.keys() items = self.person_map.keys()
@ -1532,124 +1564,141 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def get_event_attribute_types(self): def get_event_attribute_types(self):
## FIXME
return [] return []
def get_event_bookmarks(self): def get_event_bookmarks(self):
return self.event_bookmarks return self.event_bookmarks
def get_event_roles(self): def get_event_roles(self):
## FIXME
return [] return []
def get_event_types(self): def get_event_types(self):
## FIXME
return [] return []
def get_family_attribute_types(self): def get_family_attribute_types(self):
## FIXME
return [] return []
def get_family_bookmarks(self): def get_family_bookmarks(self):
return self.family_bookmarks return self.family_bookmarks
def get_family_event_types(self): def get_family_event_types(self):
## FIXME
return [] return []
def get_family_relation_types(self): def get_family_relation_types(self):
## FIXME
return [] return []
def get_media_attribute_types(self): def get_media_attribute_types(self):
## FIXME
return [] return []
def get_media_bookmarks(self): def get_media_bookmarks(self):
return self.media_bookmarks return self.media_bookmarks
def get_name_types(self): def get_name_types(self):
## FIXME
return [] return []
def get_note_bookmarks(self): def get_note_bookmarks(self):
return self.note_bookmarks return self.note_bookmarks
def get_note_types(self): def get_note_types(self):
## FIXME
return [] return []
def get_number_of_records(self, table):
return 0
def get_origin_types(self): def get_origin_types(self):
## FIXME
return [] return []
def get_person_attribute_types(self): def get_person_attribute_types(self):
## FIXME
return [] return []
def get_person_event_types(self): def get_person_event_types(self):
## FIXME
return [] return []
def get_place_bookmarks(self): def get_place_bookmarks(self):
return self.place_bookmarks return self.place_bookmarks
def get_place_tree_cursor(self): def get_place_tree_cursor(self):
## FIXME
return [] return []
def get_place_types(self): def get_place_types(self):
## FIXME
return [] return []
def get_repo_bookmarks(self): def get_repo_bookmarks(self):
return self.repo_bookmarks return self.repo_bookmarks
def get_repository_types(self): def get_repository_types(self):
## FIXME
return [] return []
def get_save_path(self): def get_save_path(self):
return self._directory return self._directory
def get_source_attribute_types(self): def get_source_attribute_types(self):
## FIXME
return [] return []
def get_source_bookmarks(self): def get_source_bookmarks(self):
return self.source_bookmarks return self.source_bookmarks
def get_source_media_types(self): def get_source_media_types(self):
## FIXME
return [] return []
def get_surname_list(self): def get_surname_list(self):
## FIXME
return [] return []
def get_url_types(self): def get_url_types(self):
## FIXME
return [] return []
def has_changed(self): def has_changed(self):
## FIXME
return True return True
def is_open(self): def is_open(self):
return True return self._directory is not None
def iter_citation_handles(self): def iter_citation_handles(self):
return (key for key in self.citation_map.keys()) return (key for key in self.citation_map.keys())
def iter_citations(self): def iter_citations(self):
return (key for key in self.citation_map.values()) return (Citation.create(key) for key in self.citation_map.values())
def iter_event_handles(self): def iter_event_handles(self):
return (key for key in self.event_map.keys()) return (key for key in self.event_map.keys())
def iter_events(self): def iter_events(self):
return (key for key in self.event_map.values()) return (Events.create(key) for key in self.event_map.values())
def iter_media_objects(self): def iter_media_objects(self):
return (key for key in self.media_map.values()) return (MediaObject.create(key) for key in self.media_map.values())
def iter_note_handles(self): def iter_note_handles(self):
return (key for key in self.note_map.keys()) return (key for key in self.note_map.keys())
def iter_notes(self): def iter_notes(self):
return (key for key in self.note_map.values()) return (Note.create(key) for key in self.note_map.values())
def iter_place_handles(self): def iter_place_handles(self):
return (key for key in self.place_map.keys()) return (key for key in self.place_map.keys())
def iter_places(self): def iter_places(self):
return (key for key in self.place_map.values()) return (Place.create(key) for key in self.place_map.values())
def iter_repositories(self): def iter_repositories(self):
return (key for key in self.repositories_map.values()) return (Repository.create(key) for key in self.repositories_map.values())
def iter_repository_handles(self): def iter_repository_handles(self):
return (key for key in self.repositories_map.keys()) return (key for key in self.repositories_map.keys())
@ -1658,13 +1707,13 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return (key for key in self.source_map.keys()) return (key for key in self.source_map.keys())
def iter_sources(self): def iter_sources(self):
return (key for key in self.source_map.values()) return (Source.create(key) for key in self.source_map.values())
def iter_tag_handles(self): def iter_tag_handles(self):
return (key for key in self.tag_map.keys()) return (key for key in self.tag_map.keys())
def iter_tags(self): def iter_tags(self):
return (key for key in self.tag_map.values()) return (Tag.create(key) for key in self.tag_map.values())
def load(self, directory, pulse_progress=None, mode=None, def load(self, directory, pulse_progress=None, mode=None,
force_schema_upgrade=False, force_schema_upgrade=False,
@ -1682,16 +1731,20 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
importData(self, filename, User()) importData(self, filename, User())
def prepare_import(self): def prepare_import(self):
## FIXME
pass pass
def redo(self, update_history=True): def redo(self, update_history=True):
## FIXME
pass pass
def restore(self): def restore(self):
## FIXME
pass pass
def set_prefixes(self, person, media, family, source, citation, def set_prefixes(self, person, media, family, source, citation,
place, event, repository, note): place, event, repository, note):
## FIXME
pass pass
def set_save_path(self, directory): def set_save_path(self, directory):
@ -1701,6 +1754,7 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.brief_name = os.path.basename(self._directory) self.brief_name = os.path.basename(self._directory)
def undo(self, update_history=True): def undo(self, update_history=True):
## FIXME
pass pass
def write_version(self, directory): def write_version(self, directory):
@ -1749,3 +1803,10 @@ class DictionaryDb(DbWriteBase, DbReadBase, UpdateCallback, Callback):
name = None name = None
return name return name
def reindex_reference_map(self):
## FIXME
pass
def rebuild_secondary(self, update):
## FIXME
pass

View File

@ -44,7 +44,7 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gramps.gen.lib import (Person, Family, Event, Place, Repository, from gramps.gen.lib import (Person, Family, Event, Place, Repository,
Citation, Source, Note, MediaObject, Tag, Citation, Source, Note, MediaObject, Tag,
Researcher) Researcher, GenderStats)
from gramps.gen.db import DbReadBase, DbWriteBase, DbTxn from gramps.gen.db import DbReadBase, DbWriteBase, DbTxn
from gramps.gen.db.undoredo import DbUndo from gramps.gen.db.undoredo import DbUndo
from gramps.gen.utils.callback import Callback from gramps.gen.utils.callback import Callback
@ -352,6 +352,8 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.full_name = None self.full_name = None
self.path = None self.path = None
self.brief_name = None self.brief_name = None
self.genderStats = GenderStats() # can pass in loaded stats as dict
self.owner = Researcher()
if directory: if directory:
self.load(directory) self.load(directory)
@ -788,8 +790,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def get_researcher(self): def get_researcher(self):
obj = Researcher() return self.owner
return obj
def get_tag_handles(self, sort_handles=False): def get_tag_handles(self, sort_handles=False):
if sort_handles: if sort_handles:
@ -1704,7 +1705,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return return
def set_researcher(self, owner): def set_researcher(self, owner):
pass self.owner.set_from(owner)
def copy_from_db(self, db): def copy_from_db(self, db):
""" """
@ -2037,9 +2038,10 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def remove_from_surname_list(self, person): def remove_from_surname_list(self, person):
## FIXME ## FIXME
## called by a complete commit_person
pass pass
## missing ## was missing
def find_place_child_handles(self, handle): def find_place_child_handles(self, handle):
pass pass
@ -2146,3 +2148,8 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
name = None name = None
return name return name
def reindex_reference_map(self):
pass
def rebuild_secondary(self, update):
pass