GEP 18: Obtain repo data from attached repo, no user input field
svn: r22572
This commit is contained in:
parent
99671bdfaf
commit
1fd823bb71
@ -235,6 +235,27 @@ def get_address_str(addr):
|
||||
str = "%s, %s" % (str, info)
|
||||
return str
|
||||
|
||||
def get_address_ref_str(addr):
|
||||
"""
|
||||
Return a string that combines the elements of an address without county,
|
||||
postal_code and phone, for typical use in references
|
||||
|
||||
@param addr: the GRAMPS address instance
|
||||
"""
|
||||
str = ""
|
||||
elems = [ addr.get_street(),
|
||||
addr.get_locality(),
|
||||
addr.get_city(),
|
||||
addr.get_state(),
|
||||
addr.get_country(), ]
|
||||
|
||||
for info in elems:
|
||||
if info:
|
||||
if str == "":
|
||||
str = info
|
||||
else:
|
||||
str = "%s, %s" % (str, info)
|
||||
return str
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# People Filters
|
||||
|
@ -44,6 +44,7 @@ from gi.repository import Gtk
|
||||
from gramps.gen.lib.srcattrtype import (SrcAttributeType, REF_TYPE_F,
|
||||
REF_TYPE_S, REF_TYPE_L, EMPTY)
|
||||
from gramps.gen.lib import SrcAttribute, SrcTemplate
|
||||
from gramps.gen.plug.report.utils import get_address_ref_str
|
||||
from ...autocomp import StandardCustomSelector
|
||||
from ...widgets.srctemplatetreeview import SrcTemplateTreeView
|
||||
from ...widgets import UndoableEntry, MonitoredEntryIndicator
|
||||
@ -308,7 +309,18 @@ class TemplateFields(object):
|
||||
lbl.set_halign(Gtk.Align.START)
|
||||
self.gridfields.attach(lbl, 0, row-1, 1, 1)
|
||||
self.lbls.append(lbl)
|
||||
if srcattrtype in [SrcAttributeType.REPOSITORY,
|
||||
SrcAttributeType.REPOSITORY_ADDRESS,
|
||||
SrcAttributeType.REPOSITORY_CALL_NUMBER]:
|
||||
self._add_repo_entry(srcattrtype, row)
|
||||
else:
|
||||
#setup entry
|
||||
self._add_normal_entry(srcattrtype, row, hint, tooltip)
|
||||
|
||||
def _add_normal_entry(self, srcattrtype, row, hint, tooltip):
|
||||
"""
|
||||
add an entryfield that sets the required SrcAttribute
|
||||
"""
|
||||
inpt = UndoableEntry()
|
||||
inpt.set_halign(Gtk.Align.FILL)
|
||||
inpt.set_hexpand(True)
|
||||
@ -327,6 +339,42 @@ class TemplateFields(object):
|
||||
read_only=self.db.readonly,
|
||||
parameter=srcattrtype)
|
||||
|
||||
def _add_repo_entry(self, srcattrtype, row):
|
||||
"""
|
||||
Add a field that obtains info from repository
|
||||
"""
|
||||
repo_list = self.src.get_reporef_list()
|
||||
if repo_list:
|
||||
reporef = repo_list[0]
|
||||
repo = self.db.get_repository_from_handle(reporef.get_reference_handle())
|
||||
else:
|
||||
reporef = None
|
||||
repo = None
|
||||
if not reporef:
|
||||
lbl = Gtk.Label("")
|
||||
lbl.set_markup(_("<i>No repository added to the source</i>"))
|
||||
lbl.set_halign(Gtk.Align.START)
|
||||
self.gridfields.attach(lbl, 1, row-1, 1, 1)
|
||||
self.lbls.append(lbl)
|
||||
else:
|
||||
#we show the data as defined by the field
|
||||
if srcattrtype == SrcAttributeType.REPOSITORY:
|
||||
text = repo.get_name()
|
||||
elif srcattrtype == SrcAttributeType.REPOSITORY_ADDRESS:
|
||||
text = _("<i>No Address attached to the repository</i>")
|
||||
addrlist = repo.get_address_list()
|
||||
if addrlist:
|
||||
text = get_address_ref_str(addrlist[0])
|
||||
elif srcattrtype == SrcAttributeType.REPOSITORY_CALL_NUMBER:
|
||||
text = reporef.get_call_number().strip()
|
||||
if not text:
|
||||
text = _("<i>No call number given in the repository reference</i>")
|
||||
lbl = Gtk.Label("")
|
||||
lbl.set_markup(text)
|
||||
lbl.set_halign(Gtk.Align.START)
|
||||
self.gridfields.attach(lbl, 1, row-1, 1, 1)
|
||||
self.lbls.append(lbl)
|
||||
|
||||
def get_src_field(self, srcattrtype):
|
||||
return self.__get_field(srcattrtype, self.src)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user