コード例 #1
0
def get_object_timestamps(db_handle: DbReadBase):
    """Get a dictionary with change timestamps of all objects in the DB."""
    d = {}
    for class_name in PRIMARY_GRAMPS_OBJECTS:
        d[class_name] = set()
        iter_method = db_handle.method("iter_%s_handles", class_name)
        for handle in iter_method():
            query_method = db_handle.method("get_%s_from_handle", class_name)
            obj = query_method(handle)
            d[class_name].add((handle, datetime.fromtimestamp(obj.change)))
    return d
コード例 #2
0
ファイル: match.py プロジェクト: zackJKnight/gramps-webapi
def match_dates(
    db_handle: DbReadBase, gramps_class_name: str, handles: List[Handle], date_mask: str
):
    """Match dates based on a date mask or range."""
    check_range = False
    if "-" in date_mask:
        check_range = True
        start, end = date_mask.split("-")
        if "/" in start:
            year, month, day = start.split("/")
            start_date = Date((int(year), int(month), int(day)))
        else:
            start_date = None
        if "/" in end:
            year, month, day = end.split("/")
            end_date = Date((int(year), int(month), int(day)))
        else:
            end_date = None

    query_method = db_handle.method("get_%s_from_handle", gramps_class_name)
    result = []
    for handle in handles:
        obj = query_method(handle)
        date = obj.get_date_object()
        if date.is_valid():
            if check_range:
                if match_date_range(date, start_date, end_date):
                    result.append(handle)
            else:
                if match_date(date, date_mask):
                    result.append(handle)
    return result
コード例 #3
0
ファイル: util.py プロジェクト: gramps-project/gramps-webapi
def get_extended_attributes(
    db_handle: DbReadBase, obj: GrampsObject, args: Optional[Dict] = None
) -> Dict:
    """Get extended attributes for a GrampsObject."""
    args = args or {}
    result = {}
    do_all = False
    if "all" in args["extend"]:
        do_all = True
    if (do_all or "child_ref_list" in args["extend"]) and hasattr(
        obj, "child_ref_list"
    ):
        result["children"] = [
            db_handle.get_person_from_handle(child_ref.ref)
            for child_ref in obj.child_ref_list
        ]
    if (do_all or "citation_list" in args["extend"]) and hasattr(obj, "citation_list"):
        result["citations"] = [
            db_handle.get_citation_from_handle(handle) for handle in obj.citation_list
        ]
    if (do_all or "event_ref_list" in args["extend"]) and hasattr(
        obj, "event_ref_list"
    ):
        result["events"] = [
            db_handle.get_event_from_handle(event_ref.ref)
            for event_ref in obj.event_ref_list
        ]
    if (do_all or "media_list" in args["extend"]) and hasattr(obj, "media_list"):
        result["media"] = [
            db_handle.get_media_from_handle(media_ref.ref)
            for media_ref in obj.media_list
        ]
    if (do_all or "note_list" in args["extend"]) and hasattr(obj, "note_list"):
        result["notes"] = [
            db_handle.get_note_from_handle(handle) for handle in obj.note_list
        ]
    if (do_all or "person_ref_list" in args["extend"]) and hasattr(
        obj, "person_ref_list"
    ):
        result["people"] = [
            db_handle.get_person_from_handle(person_ref.ref)
            for person_ref in obj.person_ref_list
        ]
    if (do_all or "reporef_list" in args["extend"]) and hasattr(obj, "reporef_list"):
        result["repositories"] = [
            db_handle.get_repository_from_handle(repo_ref.ref)
            for repo_ref in obj.reporef_list
        ]
    if (do_all or "tag_list" in args["extend"]) and hasattr(obj, "tag_list"):
        result["tags"] = [
            db_handle.get_tag_from_handle(handle) for handle in obj.tag_list
        ]
    if (do_all or "backlinks" in args["extend"]) and hasattr(obj, "backlinks"):
        result["backlinks"] = {}
        for class_name, backlinks in obj.backlinks.items():
            result["backlinks"][class_name] = [
                db_handle.method("get_%s_from_handle", class_name.upper())(handle)
                for handle in backlinks
            ]
    return result
コード例 #4
0
ファイル: search.py プロジェクト: windmark/gramps-webapi
def iter_obj_strings(
    db_handle: DbReadBase, ) -> Generator[Dict[str, Any], None, None]:
    """Iterate over object strings in the whole database."""
    for class_name in PRIMARY_GRAMPS_OBJECTS:
        query_method = db_handle.method("get_%s_from_handle", class_name)
        iter_method = db_handle.method("iter_%s_handles", class_name)
        for handle in iter_method():
            obj = query_method(handle)
            obj_string, obj_string_private = object_to_strings(obj)
            private = hasattr(obj, "private") and obj.private
            if obj_string:
                yield {
                    "class_name": class_name,
                    "handle": obj.handle,
                    "private": private,
                    "string": obj_string,
                    "string_private": obj_string_private,
                    "changed": datetime.fromtimestamp(obj.change),
                }
コード例 #5
0
def iter_obj_strings(
    db_handle: DbReadBase, ) -> Generator[Dict[str, Any], None, None]:
    """Iterate over object strings in the whole database."""
    for class_name in PRIMARY_GRAMPS_OBJECTS:
        iter_method = db_handle.method("iter_%s_handles", class_name)
        for handle in iter_method():
            obj_strings = obj_strings_from_handle(db_handle, class_name,
                                                  handle)
            if obj_strings:
                yield obj_strings
コード例 #6
0
 def old_unchanged(self, db: DbReadBase, class_name: str, handle: str,
                   old_data: Dict) -> bool:
     """Check if the "old" object is still unchanged."""
     handle_func = db.method("get_%s_from_handle", class_name)
     try:
         obj = handle_func(handle)
     except HandleError:
         if old_data is None:
             return True
         return False
     obj_dict = json.loads(to_json(obj))
     if diff_items(class_name, old_data, obj_dict):
         return False
     return True
コード例 #7
0
def obj_strings_from_handle(db_handle: DbReadBase, class_name: str,
                            handle) -> Optional[Dict[str, Any]]:
    """Return object strings from a handle and Gramps class name."""
    query_method = db_handle.method("get_%s_from_handle", class_name)
    obj = query_method(handle)
    obj_string, obj_string_private = object_to_strings(obj)
    private = hasattr(obj, "private") and obj.private
    if obj_string:
        return {
            "class_name": class_name,
            "handle": obj.handle,
            "private": private,
            "string": obj_string,
            "string_private": obj_string_private,
            "change": datetime.fromtimestamp(obj.change),
        }
    return None