예제 #1
0
 def get_tag(self, name):
     tag = self.database.get_tag_from_name(name)
     if tag is None:
         tag = gramps.gen.lib.Tag()
         tag.set_name(name)
         trans_class = self.database.get_transaction_class()
         with trans_class("QueryQuickview new Tag", self.database, batch=False) as trans:
             self.database.add_tag(tag, trans)
     return Handle("Tag", tag.handle)
예제 #2
0
파일: diff.py 프로젝트: cicl06/gramps
def get_schema(cls):
    """
    Given a gramps.gen.lib class, or class name, return a dictionary
    containing the schema. The schema is a dictionary of fieldname
    keys with type as value.

    Also, the schema includes the same metadata fields as does struct,
    including "_class", returned as real class of cls.
    """
    orig_cls = cls
    # Get type as a gramps.gen.lib string name
    if isinstance(cls, type):
        cls = cls().__class__.__name__
    elif isinstance(cls, object) and not isinstance(cls, str):
        cls = cls.__class__.__name__
    ### Is there a Path?
    if "." in cls:
        items = parse(cls)  # "Person.alternate_names"
        cls, path = items[0], items[1:]
    else:
        path = []
    # Now get the schema
    if cls in ("str", "int", "bool", "float", "long", "list"):
        schema = orig_cls
    elif cls == "Person":
        schema = {
            "_class": Person,
            "handle": Handle("Person", "PERSON-HANDLE"),
            "gramps_id": str,
            "gender": int,
            "primary_name": Name,
            "alternate_names": [Name],
            "death_ref_index": int,
            "birth_ref_index": int,
            "event_ref_list": [EventRef],
            "family_list": [Handle("Family", "FAMILY-HANDLE")],
            "parent_family_list": [Handle("Family", "FAMILY-HANDLE")],
            "media_list": [MediaRef],
            "address_list": [Address],
            "attribute_list": [Attribute],
            "urls": [Url],
            "lds_ord_list": [LdsOrd],
            "citation_list": [Handle("Citation", "CITATION-HANDLE")],
            "note_list": [Handle("Note", "NOTE-HANDLE")],
            "change": int,
            "tag_list": [Handle("Tag", "TAG-HANDLE")],
            "private": bool,
            "person_ref_list": [PersonRef]
        }
    elif cls == "Name":
        schema = {
            "_class": Name,
            "private": bool,
            "citation_list": [Handle("Citation", "CITATION-HANDLE")],
            "note_list": [Handle("Note", "NOTE-HANDLE")],
            "date": Date,
            "first_name": str,
            "surname_list": [Surname],
            "suffix": str,
            "title": str,
            "type": NameType,
            "group_as": str,
            "sort_as": int,
            "display_as": int,
            "call": str,
            "nick": str,
            "famnick": str,
        }
    else:
        raise AttributeError("unknown class '%s'" % cls)
    # walk down path, if given:
    for p in range(len(path)):
        # could be a list
        item = path[p]
        if isinstance(schema, (list, tuple)):
            schema = schema[int(item)]
        else:
            schema = schema[item]
        if isinstance(schema, type):
            schema = get_schema(schema)
    return schema