Exemple #1
0
    def from_struct(self, struct):
        """
        Given a struct with metadata, create a Gramps object.

        self is class when called as a classmethod.
        """
        from gprime.lib import (Person, Family, Event, Source, Place, Citation,
                                Repository, Media, Note, Tag, Date)
        if isinstance(struct, dict):
            if "_class" in struct.keys():
                if struct["_class"] == "Person":
                    return Person.from_struct(struct)
                elif struct["_class"] == "Family":
                    return Family.from_struct(struct)
                elif struct["_class"] == "Event":
                    return Event.from_struct(struct)
                elif struct["_class"] == "Source":
                    return Source.from_struct(struct)
                elif struct["_class"] == "Place":
                    return Place.from_struct(struct)
                elif struct["_class"] == "Citation":
                    return Citation.from_struct(struct)
                elif struct["_class"] == "Repository":
                    return Repository.from_struct(struct)
                elif struct["_class"] == "Media":
                    return Media.from_struct(struct)
                elif struct["_class"] == "Note":
                    return Note.from_struct(struct)
                elif struct["_class"] == "Tag":
                    return Tag.from_struct(struct)
                elif struct["_class"] == "Date":
                    return Date.from_struct(struct, full=True)
        raise AttributeError("invalid struct: %s" % struct)
Exemple #2
0
 def get(self, path=""):
     """
     HANDLE
     HANDLE/edit|delete
     /add
     b2cfa6ca1e174b1f63d/remove/eventref/1
     """
     page = int(self.get_argument("page", 1))
     search = self.get_argument("search", "")
     if "/" in path:
         handle, action = path.split("/", 1)
     else:
         handle, action = path, "view"
     if handle:
         if handle == "add":
             person = Person()
             person.primary_name.surname_list.append(Surname())
             action = "edit"
         else:
             person = self.database.get_person_from_handle(handle)
         if person:
             person.probably_alive = True
             self.render(
                 "person.html",
                 **self.get_template_dict(tview=self._("person detail"),
                                          action=action,
                                          page=page,
                                          search=search,
                                          form=PersonForm(self.database,
                                                          self._,
                                                          instance=person),
                                          logform=None))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such person</body></html>")
             return
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=self._("person view"),
             page=page,
             search=search,
             form=PersonForm(self.database, self._),
         ))
Exemple #3
0
 def post(self, path):
     if "/" in path:
         handle, action = path.split("/")
     else:
         handle, action = path, "view"
     if handle == "add":
         person = Person()
         person.primary_name.surname_list.append(Surname())
         person.handle = handle = create_id()
     else:
         person = self.database.get_person_from_handle(handle)
     form = PersonForm(self.database, self._, instance=person)
     form.save(handler=self)
     self.redirect("/person/%(handle)s" % {"handle": handle})
Exemple #4
0
def importData(db, filename, user):
    db.disable_signals()
    try:
        with DbTxn(_("JSON import"), db, batch=True) as trans:
            with OpenFileOrStdin(filename, encoding="utf-8") as fp:
                line = fp.readline()
                while line:
                    data = json.loads(line)
                    if data["_class"] == "Person":
                        obj = Person.from_struct(data)
                        db.add_person(obj, trans)
                    elif data["_class"] == "Family":
                        obj = Family.from_struct(data)
                        db.add_family(obj, trans)
                    elif data["_class"] == "Event":
                        obj = Event.from_struct(data)
                        db.add_event(obj, trans)
                    elif data["_class"] == "Media":
                        obj = Media.from_struct(data)
                        db.add_media(obj, trans)
                    elif data["_class"] == "Repository":
                        obj = Repository.from_struct(data)
                        db.add_repository(obj, trans)
                    elif data["_class"] == "Tag":
                        obj = Tag.from_struct(data)
                        db.add_tag(obj, trans)
                    elif data["_class"] == "Source":
                        obj = Source.from_struct(data)
                        db.add_source(obj, trans)
                    elif data["_class"] == "Citation":
                        obj = Citation.from_struct(data)
                        db.add_citation(obj, trans)
                    elif data["_class"] == "Note":
                        obj = Note.from_struct(data)
                        db.add_note(obj, trans)
                    elif data["_class"] == "Place":
                        obj = Place.from_struct(data)
                        db.add_place(obj, trans)
                    else:
                        LOG.warn("ignored: " + data)
                    line = fp.readline()
    except EnvironmentError as err:
        user.notify_error(_("%s could not be opened\n") % filename, str(err))

    db.enable_signals()
    db.request_rebuild()
Exemple #5
0
 def post(self, path):
     """
     """
     _ = self.app.get_translate_func(self.current_user)
     page = int(self.get_argument("page", 1) or 1)
     search = self.get_argument("search", "")
     if path.count("/") == 0:  # handle
         handle, action = path, "view"
     elif path.count("/") == 1:  # handle/add
         handle, action = path.split("/", 1)
     else:
         self.clear()
         self.set_status(404)
         self.finish("<html><body>No such person</body></html>")
         return
     json_data = json.loads(html.unescape(self.get_argument("json_data")))
     instance = Person.from_struct(json_data)
     update_json = self.get_argument("update_json", None)
     if update_json:
         # edit the instance
         self.update_instance(instance, update_json)
         form = PersonForm(self, instance=instance)
         form.load_data()
         self.render(
             "person.html",
             **self.get_template_dict(tview=_("person detail"),
                                      action=action,
                                      page=page,
                                      search=search,
                                      form=form))
     else:
         self.send_message("Updated person. <a href=\"FIXME\">Undo</a>")
         form = PersonForm(self, instance=instance)
         form.save()
         handle = instance.handle
         self.redirect(
             self.app.make_url("/person/%(handle)s" % {"handle": handle}))
Exemple #6
0
    def dump_parent(self, title, person_handle):

        if not person_handle and not self.missing_info:
            return
        elif not person_handle:
            person = Person()
        else:
            person = self.db.get_person_from_handle(person_handle)
        name = self._name_display.display(person)

        self.doc.start_table(title, 'FGR-ParentTable')
        self.doc.start_row()
        self.doc.start_cell('FGR-ParentHead', 3)
        self.doc.start_paragraph('FGR-ParentName')
        mark = utils.get_person_mark(self.db, person)
        # translators: needed for French, ignore otherwise
        self.doc.write_text(
            self._("%(str1)s: %(str2)s") % {
                'str1': title,
                'str2': name
            }, mark)
        if self.gids:
            gid = person.get_gid()
            if gid:
                self.doc.write_text(" (%s)" % gid)
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()

        birth_ref = person.get_birth_ref()
        birth = None
        ev_name = self._("Birth")
        if birth_ref:
            birth = self.db.get_event_from_handle(birth_ref.ref)
        if birth or self.missing_info:
            self.dump_parent_event(ev_name, birth)

        death_ref = person.get_death_ref()
        death = None
        ev_name = self._("Death")
        if death_ref:
            death = self.db.get_event_from_handle(death_ref.ref)
        if death or self.missing_info:
            self.dump_parent_event(ev_name, death)

        self.dump_parent_parents(person)

        if self.inc_par_events:
            for event_ref in person.get_primary_event_ref_list():
                if event_ref != birth_ref and event_ref != death_ref:
                    event = self.db.get_event_from_handle(event_ref.ref)
                    event_type = self._get_type(event.get_type())
                    self.dump_parent_event(self._(event_type), event)

        if self.inc_par_addr:
            addrlist = person.get_address_list()[:]
            for addr in addrlist:
                location = utils.get_address_str(addr)
                date = self._get_date(addr.get_date_object())

                self.doc.start_row()
                self.doc.start_cell("FGR-TextContents")
                self.doc.start_paragraph('FGR-Normal')
                self.doc.write_text(self._("Address"))
                self.doc.end_paragraph()
                self.doc.end_cell()
                self.doc.start_cell("FGR-TextContents")
                self.doc.start_paragraph('FGR-Normal')
                self.doc.write_text(date)
                self.doc.end_paragraph()
                self.doc.end_cell()
                self.doc.start_cell("FGR-TextContentsEnd")
                self.doc.start_paragraph('FGR-Normal')
                self.doc.write_text(location)
                self.doc.end_paragraph()
                self.doc.end_cell()
                self.doc.end_row()

        if self.inc_par_notes:
            for notehandle in person.get_note_list():
                note = self.db.get_note_from_handle(notehandle)
                self.dump_parent_noteline(self._("Note"), note)

        if self.include_attrs:
            for attr in person.get_attribute_list():
                attr_type = self._get_type(attr.get_type())
                self.dump_parent_line(self._(attr_type), attr.get_value())

        if self.inc_par_names:
            for alt_name in person.get_alternate_names():
                name_type = self._get_type(alt_name.get_type())
                name = self._name_display.display_name(alt_name)
                self.dump_parent_line(self._(name_type), name)

        self.doc.end_table()
Exemple #7
0
 def get(self, path=""):
     """
     person
     person/add
     person/b2cfa6ca1e174b1f63
     person/b2cfa6ca1e174b1f63/edit
     person/b2cfa6ca1e174b1f63/delete
     """
     _ = self.app.get_translate_func(self.current_user)
     page = int(self.get_argument("page", 1) or 1)
     search = self.get_argument("search", "")
     if path.count("/") == 0:  # handle
         handle, action = path, "view"
     elif path.count("/") == 1:  # handle/add
         handle, action = path.split("/", 1)
     else:
         self.clear()
         self.set_status(404)
         self.finish("<html><body>No such person</body></html>")
         return
     if handle:
         if handle == "add":
             person = Person()
             person.primary_name.surname_list.append(Surname())
             action = "edit"
         else:
             person = self.database.get_person_from_handle(handle)
         if person:
             if action == "delete":
                 ## Delete person
                 form = PersonForm(self, instance=person)
                 form.delete()
                 return
             else:
                 ## Action can be edit or view
                 self.render(
                     "person.html",
                     **self.get_template_dict(tview=_("person detail"),
                                              action=action,
                                              page=page,
                                              search=search,
                                              form=PersonForm(
                                                  self, instance=person)))
             return
         else:
             self.clear()
             self.set_status(404)
             self.finish("<html><body>No such person</body></html>")
             return
     form = PersonForm(self)
     # Do this here, to catch errors:
     try:
         form.select(page, search)
     except Exception as exp:
         self.send_message(str(exp))
         self.redirect(form.make_url())
         return
     # If no errors, carry on:
     self.render(
         "page_view.html",
         **self.get_template_dict(
             tview=_("person view"),
             page=page,
             search=search,
             form=form,
         ))