Moved code to get links from notes to Note object; updated quickview

svn: r23382
This commit is contained in:
Doug Blank 2013-10-24 14:31:21 +00:00
parent 39a3f50a96
commit 365daaba62
2 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -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)