From 365daaba622bd6b6fbe3c729eacc5019dc76446a Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 24 Oct 2013 14:31:21 +0000 Subject: [PATCH] Moved code to get links from notes to Note object; updated quickview svn: r23382 --- gramps/gen/lib/note.py | 23 ++++++++++++++++++++++ gramps/plugins/quickview/linkreferences.py | 14 +++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/gramps/gen/lib/note.py b/gramps/gen/lib/note.py index 1d25dc19a..4f58acfef 100644 --- a/gramps/gen/lib/note.py +++ b/gramps/gen/lib/note.py @@ -35,6 +35,7 @@ from .primaryobj import BasicPrimaryObject from .tagbase import TagBase from .notetype import NoteType from .styledtext import StyledText +from .styledtexttagtype import StyledTextTagType from ..constfunc import cuni from .handle import Handle @@ -257,3 +258,25 @@ class Note(BasicPrimaryObject): """ return self.type + + def get_links(self): + """ + Get the jump links from this note. Links can be external, to + urls, or can be internal to gramps objects. + + Return examples: + [("gramps", "Person", "handle", "7657626365362536"), + ("external", "www", "url", "http://example.com")] + + :returns: list of [(domain, type, propery, value), ...] + :rtype: list + """ + retval = [] + for styledtext_tag in self.text.get_tags(): + if int(styledtext_tag.name) == StyledTextTagType.LINK: + if styledtext_tag.value.startswith("gramps://"): + object_class, prop, value = styledtext_tag.value[9:].split("/", 2) + retval.append(("gramps", object_class, prop, value)) + else: + retval.append(("external", "www", "url", styledtext_tag.value)) + return retval diff --git a/gramps/plugins/quickview/linkreferences.py b/gramps/plugins/quickview/linkreferences.py index 3c27e4bdb..9fe2dcafa 100644 --- a/gramps/plugins/quickview/linkreferences.py +++ b/gramps/plugins/quickview/linkreferences.py @@ -46,14 +46,10 @@ def run(database, document, obj): sdoc.paragraph("\n") stab.columns(_("Type"), _("Reference"), _("Link check")) - tags = obj.text.get_tags() - - for styledtext_tag in tags: - if int(styledtext_tag.name) == StyledTextTagType.LINK: - if styledtext_tag.value.startswith("gramps://"): - object_class, prop, value = styledtext_tag.value[9:].split("/", 2) - tagtype = _(object_class) - ref_obj = sdb.get_link(object_class, prop, value) + for (ldomain, ltype, lprop, lvalue) in obj.get_links(): + if ldomain == "gramps": + tagtype = _(ltype) + ref_obj = sdb.get_link(ltype, lprop, lvalue) if ref_obj: tagvalue = ref_obj tagcheck = _("Ok") @@ -62,7 +58,7 @@ def run(database, document, obj): tagcheck = _("Failed: missing object") else: tagtype = _("Internet") - tagvalue = styledtext_tag.value + tagvalue = lvalue tagcheck = "" stab.row(tagtype, tagvalue, tagcheck)