def make_cache(self): from gramps.webapp.libdjango import DjangoInterface if self.dji is None: self.dji = DjangoInterface() if isinstance(self, Person): raw = self.dji.get_person(self) elif isinstance(self, Family): raw = self.dji.get_family(self) elif isinstance(self, Place): raw = self.dji.get_place(self) elif isinstance(self, Media): raw = self.dji.get_media(self) elif isinstance(self, Source): raw = self.dji.get_source(self) elif isinstance(self, Citation): raw = self.dji.get_citation(self) elif isinstance(self, Repository): raw = self.dji.get_repository(self) elif isinstance(self, Note): raw = self.dji.get_note(self) elif isinstance(self, Event): raw = self.dji.get_event(self) elif isinstance(self, Tag): raw = self.dji.get_tag(self) else: raise Exception("Don't know how to get raw '%s'" % type(item)) return str(base64.encodebytes(pickle.dumps(raw)), "utf-8")
def __init__(self, db, filename, callback): if not callable(callback): callback = lambda percent: None # dummy self.db = db self.dji = DjangoInterface() self.filename = filename self.callback = callback self.debug = 0
def save(self, commit=True): from gramps.webapp.utils import dp from gramps.webapp.libdjango import DjangoInterface dji = DjangoInterface() model = super(CitationForm, self).save(commit=False) dobj = dp(self.cleaned_data['text']) dji.add_date(model, dobj.serialize()) if commit: model.save() return model
def load(self, directory, callback=None, mode=None, force_schema_upgrade=False, force_bsddb_upgrade=False, force_bsddb_downgrade=False, force_python_upgrade=False): # Django-specific loads: from django.conf import settings LOG.info("Django loading...") default_settings = { "__file__": os.path.join(directory, "default_settings.py") } settings_file = os.path.join(directory, "default_settings.py") with open(settings_file) as f: code = compile(f.read(), settings_file, 'exec') exec(code, globals(), default_settings) class Module(object): def __init__(self, dictionary): self.dictionary = dictionary def __getattr__(self, item): return self.dictionary[item] LOG.info("Django loading defaults from: " + directory) try: settings.configure(Module(default_settings)) except RuntimeError: LOG.info("Django already configured error! Shouldn't happen!") # already configured; ignore import django django.setup() from gramps.webapp.libdjango import DjangoInterface self.dji = DjangoInterface() super().load(directory, callback, mode, force_schema_upgrade, force_bsddb_upgrade, force_bsddb_downgrade, force_python_upgrade)
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # """ Views for Person, Name, and Surname """ ## Gramps Modules from gramps.webapp.utils import _, boolean, update_last_changed, build_search from gramps.webapp.grampsdb.models import Source from gramps.webapp.grampsdb.forms import * from gramps.webapp.libdjango import DjangoInterface ## Django Modules from django.shortcuts import get_object_or_404, render_to_response, redirect from django.template import Context, RequestContext ## Globals dji = DjangoInterface() def process_source(request, context, handle, act, add_to=None): # view, edit, save """ Process act on person. Can return a redirect. """ context["tview"] = _("Source") context["tviews"] = _("Sources") context["action"] = "view" view_template = "view_source_detail.html"
def make_cache(self): from gramps.webapp.libdjango import DjangoInterface if self.dji is None: self.dji = DjangoInterface() raw = self.dji.get_tag(self) return str(base64.encodebytes(pickle.dumps(raw)), "utf-8")
def export_all(database, filename, error_dialog, option_box=None, callback=None): if not callable(callback): callback = lambda percent: None # dummy start = time.time() total = ( database.get_number_of_notes() + database.get_number_of_people() + database.get_number_of_events() + database.get_number_of_families() + database.get_number_of_repositories() + database.get_number_of_places() + database.get_number_of_media_objects() + database.get_number_of_citations() + database.get_number_of_sources() + database.get_number_of_tags()) * 2 # 2 steps count = 0.0 dji = DjangoInterface() dji.clear_tables("primary", "secondary", "ref") with transaction.commit_on_success(): for step in [0, 1]: LOG.debug("Exporting Step %d..." % (step + 1)) # --------------------------------- # Person # --------------------------------- for person_handle in database.person_map.keys(): data = database.person_map[person_handle] if step == 0: dji.add_person(data) elif step == 1: djperson = dji.add_person_detail(data) djperson.probably_alive = not bool(djperson.death) djperson.save() count += 1 callback(100 * count / total) # --------------------------------- # Notes # --------------------------------- for note_handle in database.note_map.keys(): data = database.note_map[note_handle] if step == 0: dji.add_note(data) count += 1 callback(100 * count / total) # --------------------------------- # Family # --------------------------------- for family_handle in database.family_map.keys(): data = database.family_map[family_handle] if step == 0: dji.add_family(data) elif step == 1: dji.add_family_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Citation # --------------------------------- for citation_handle in database.citation_map.keys(): data = database.citation_map[citation_handle] if step == 0: dji.add_citation(data) elif step == 1: dji.add_citation_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Source # --------------------------------- for source_handle in database.source_map.keys(): data = database.source_map[source_handle] if step == 0: dji.add_source(data) elif step == 1: dji.add_source_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Event # --------------------------------- for event_handle in database.event_map.keys(): data = database.event_map[event_handle] if step == 0: dji.add_event(data) elif step == 1: dji.add_event_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Repository # --------------------------------- for repository_handle in database.repository_map.keys(): data = database.repository_map[repository_handle] if step == 0: dji.add_repository(data) elif step == 1: dji.add_repository_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Place # --------------------------------- for place_handle in database.place_map.keys(): data = database.place_map[place_handle] if step == 0: dji.add_place(data) elif step == 1: dji.add_place_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Media # --------------------------------- for media_handle in database.media_map.keys(): data = database.media_map[media_handle] if step == 0: dji.add_media(data) elif step == 1: dji.add_media_detail(data) count += 1 callback(100 * count / total) # --------------------------------- # Tags # --------------------------------- for tag_handle in database.tag_map.keys(): data = database.tag_map[tag_handle] if step == 0: dji.add_tag(data) elif step == 1: dji.add_tag_detail(data) count += 1 callback(100 * count / total) #dji.rebuild_caches(callback) # not needed anymore, caches get # saved in the add_*_detail methods total_time = time.time() - start msg = ngettext('Export Complete: %d second', 'Export Complete: %d seconds', total_time) % total_time LOG.debug(msg) return True
def __init__(self): DbReadBase.__init__(self) DbWriteBase.__init__(self) self._tables = { 'Person': { "handle_func": self.get_person_from_handle, "gramps_id_func": self.get_person_from_gramps_id, "class_func": gramps.gen.lib.Person, "cursor_func": self.get_person_cursor, "handles_func": self.get_person_handles, "iter_func": self.iter_people, }, 'Family': { "handle_func": self.get_family_from_handle, "gramps_id_func": self.get_family_from_gramps_id, "class_func": gramps.gen.lib.Family, "cursor_func": self.get_family_cursor, "handles_func": self.get_family_handles, "iter_func": self.iter_families, }, 'Source': { "handle_func": self.get_source_from_handle, "gramps_id_func": self.get_source_from_gramps_id, "class_func": gramps.gen.lib.Source, "cursor_func": self.get_source_cursor, "handles_func": self.get_source_handles, "iter_func": self.iter_sources, }, 'Citation': { "handle_func": self.get_citation_from_handle, "gramps_id_func": self.get_citation_from_gramps_id, "class_func": gramps.gen.lib.Citation, "cursor_func": self.get_citation_cursor, "handles_func": self.get_citation_handles, "iter_func": self.iter_citations, }, 'Event': { "handle_func": self.get_event_from_handle, "gramps_id_func": self.get_event_from_gramps_id, "class_func": gramps.gen.lib.Event, "cursor_func": self.get_event_cursor, "handles_func": self.get_event_handles, "iter_func": self.iter_events, }, 'Media': { "handle_func": self.get_object_from_handle, "gramps_id_func": self.get_object_from_gramps_id, "class_func": gramps.gen.lib.MediaObject, "cursor_func": self.get_media_cursor, "handles_func": self.get_media_object_handles, "iter_func": self.iter_media_objects, }, 'Place': { "handle_func": self.get_place_from_handle, "gramps_id_func": self.get_place_from_gramps_id, "class_func": gramps.gen.lib.Place, "cursor_func": self.get_place_cursor, "handles_func": self.get_place_handles, "iter_func": self.iter_places, }, 'Repository': { "handle_func": self.get_repository_from_handle, "gramps_id_func": self.get_repository_from_gramps_id, "class_func": gramps.gen.lib.Repository, "cursor_func": self.get_repository_cursor, "handles_func": self.get_repository_handles, "iter_func": self.iter_repositories, }, 'Note': { "handle_func": self.get_note_from_handle, "gramps_id_func": self.get_note_from_gramps_id, "class_func": gramps.gen.lib.Note, "cursor_func": self.get_note_cursor, "handles_func": self.get_note_handles, "iter_func": self.iter_notes, }, 'Tag': { "handle_func": self.get_tag_from_handle, "gramps_id_func": None, "class_func": gramps.gen.lib.Tag, "cursor_func": self.get_tag_cursor, "handles_func": self.get_tag_handles, "iter_func": self.iter_tags, }, } # skip GEDCOM cross-ref check for now: self.set_feature("skip-check-xref", True) self.dji = DjangoInterface() self.readonly = False self.db_is_open = True self.name_formats = [] self.bookmarks = Bookmarks() self.family_bookmarks = Bookmarks() self.event_bookmarks = Bookmarks() self.place_bookmarks = Bookmarks() self.citation_bookmarks = Bookmarks() self.source_bookmarks = Bookmarks() self.repo_bookmarks = Bookmarks() self.media_bookmarks = Bookmarks() self.note_bookmarks = Bookmarks() self.set_person_id_prefix('I%04d') self.set_object_id_prefix('O%04d') self.set_family_id_prefix('F%04d') self.set_citation_id_prefix('C%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 = 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.cid_trans = DjangoTxn("CID Transaction", self, self.dji.Citation) 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.cmap_index = 0 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 = {} self.place_map = {} self.citation_map = {} self.source_map = {} self.repository_map = {} self.note_map = {} self.media_map = {} self.event_map = {} self.metadata = {} self.name_group = {} self.undo_callback = None self.redo_callback = None self.undo_history_callback = None self.modified = 0 self.txn = DjangoTxn("DbDjango Transaction", self) self.transaction = None # Import cache for gedcom import, uses transactions, and # two step adding of objects. self.import_cache = {} self.use_import_cache = False self.use_db_cache = True