Various changes to use title, author, pubinfo and page from citeref, rather than from Src and Citation.

svn: r22912
This commit is contained in:
Tim G L Lyons 2013-08-23 18:25:21 +00:00
parent 9037f827a5
commit 7c90638ad3
8 changed files with 64 additions and 50 deletions

View File

@ -35,6 +35,8 @@ _ = glocale.translation.gettext
#
#-------------------------------------------------------------------------
from . import Rule
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo)
#-------------------------------------------------------------------------
#
@ -55,16 +57,16 @@ class HasSourceBase(Rule):
allow_regex = True
def apply(self,db,source):
if not self.match_substring(0,source.get_title()):
if not self.match_substring(0, get_gedcom_title(db, source)):
return False
if not self.match_substring(1,source.get_author()):
if not self.match_substring(1, get_gedcom_author(db, source)):
return False
if not self.match_substring(2,source.get_abbreviation()):
return False
if not self.match_substring(3,source.get_publication_info()):
if not self.match_substring(3, get_gedcom_pubinfo(db, source)):
return False
return True

View File

@ -32,6 +32,8 @@ from ...lib import NoteType, Citation
from ...const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from ...utils.string import confidence
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo, get_gedcom_page)
def add_endnote_styles(style_sheet):
"""
@ -141,7 +143,7 @@ def write_endnotes(bibliography, database, doc, printnotes=False, links=False,
first = True
doc.start_paragraph('Endnotes-Source', "%d." % cindex)
doc.write_text(_format_source_text(source), links=links)
doc.write_text(_format_source_text(database, source), links=links)
doc.end_paragraph()
if printnotes:
@ -149,29 +151,29 @@ def write_endnotes(bibliography, database, doc, printnotes=False, links=False,
for key, ref in citation.get_ref_list():
doc.start_paragraph('Endnotes-Ref', "%s:" % key)
doc.write_text(_format_ref_text(ref, key, elocale), links=links)
doc.write_text(_format_ref_text(database, ref, key, elocale), links=links)
doc.end_paragraph()
if printnotes:
_print_notes(ref, database, doc, 'Endnotes-Ref-Notes', links)
def _format_source_text(source):
def _format_source_text(database, source):
if not source: return ""
src_txt = ""
if source.get_author():
src_txt += source.get_author()
if get_gedcom_author(database, source):
src_txt += get_gedcom_author(database, source)
if source.get_title():
if get_gedcom_title(database, source):
if src_txt:
src_txt += ", "
src_txt += '"%s"' % source.get_title()
src_txt += '"%s"' % get_gedcom_title(database, source)
if source.get_publication_info():
if get_gedcom_pubinfo(database, source):
if src_txt:
src_txt += ", "
src_txt += source.get_publication_info()
src_txt += get_gedcom_pubinfo(database, source)
if source.get_abbreviation():
if src_txt:
@ -180,7 +182,7 @@ def _format_source_text(source):
return src_txt
def _format_ref_text(ref, key, elocale):
def _format_ref_text(database, ref, key, elocale):
if not ref: return ""
ref_txt = ""
@ -190,12 +192,13 @@ def _format_ref_text(ref, key, elocale):
if date is not None and not date.is_empty():
datepresent = True
if datepresent:
if ref.get_page():
ref_txt = "%s - %s" % (ref.get_page(), elocale.get_date(date))
if get_gedcom_page(database, ref):
ref_txt = "%s - %s" % (get_gedcom_page(database, ref),
elocale.get_date(date))
else:
ref_txt = elocale.get_date(date)
else:
ref_txt = ref.get_page()
ref_txt = get_gedcom_page(database, ref)
# Print only confidence level if it is not Normal
if (ref.get_confidence_level() != Citation.CONF_NORMAL

View File

@ -40,6 +40,8 @@ from ..config import config
from ..const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from ..constfunc import STRTYPE
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo)
#-------------------------------------------------------------------------
#
@ -846,7 +848,7 @@ class SimpleAccess(object):
"""
assert(source is None or isinstance(source, Source))
if source:
return source.get_title()
return get_gedcom_title(self.dbase, source)
return ''
def page(self, citation):
@ -860,7 +862,7 @@ class SimpleAccess(object):
"""
assert(citation is None or isinstance(citation, Citation))
if citation:
return citation.get_page()
return get_gedcom_page(self.dbase, citation)
return ''
def author(self, source):
@ -874,7 +876,7 @@ class SimpleAccess(object):
"""
assert(source is None or isinstance(source, Source))
if source:
return source.get_author()
return get_gedcom_author(self.dbase, source)
return ''
def person(self, handle):

View File

@ -131,34 +131,34 @@ def get_gedcom_title(db, source=None):
else:
return source_cache.get_name()
return (template_cache.get_map_element(GED_TITLE) %
DefaultKey(input_dict)) or ""
DefaultBlank(input_dict)) or ""
def get_gedcom_author(db, source=None):
global template_cache, source_cache
if source:
set_input_dict_and_template(db, source)
if template_cache is None:
return "author not available"
return ""
return (template_cache.get_map_element(GED_AUTHOR) %
DefaultKey(input_dict)) or ""
DefaultBlank(input_dict)) or ""
def get_gedcom_pubinfo(db, source=None):
global template_cache, source_cache
if source:
set_input_dict_and_template(db, source)
if template_cache is None:
return "pubinfo not available"
return ""
return (template_cache.get_map_element(GED_PUBINF) %
DefaultKey(input_dict)) or ""
DefaultBlank(input_dict)) or ""
def get_gedcom_page(db, citation=None):
global template_cache
if citation:
set_input_dict_and_template(db, source=None, citation=citation)
if template_cache is None:
return "page not available"
return ""
return (template_cache.get_map_element(GED_PAGE) %
DefaultKey(input_dict)) or ""
DefaultBlank(input_dict)) or ""
# http://bugs.python.org/issue6081
class DefaultBlank(dict):

View File

@ -64,7 +64,7 @@ from ..glade import Glade
from gramps.gen.utils.citeref import (set_input_dict_and_template, reference_L,
reference_S, reference_F,
get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo)
get_gedcom_pubinfo, get_gedcom_page)
#-------------------------------------------------------------------------
#
@ -124,7 +124,7 @@ class EditSource(EditPrimary):
return Source()
def get_menu_title(self):
title = self.obj.get_title()
title = get_gedcom_title(self.db, self.obj)
if self.obj.get_handle():
title = _('Source') + ": " + title
else:
@ -667,7 +667,7 @@ class EditSource(EditPrimary):
(uses_dupe_id, id) = self._uses_duplicate_id()
if uses_dupe_id:
prim_object = self.get_from_gramps_id(id)
name = prim_object.get_title()
name = get_gedcom_title(self.db, prim_object)
msg1 = _("Cannot save source. ID already exists.")
msg2 = _("You have attempted to use the existing Gramps ID with "
"value %(id)s. This value is already used by '"
@ -689,7 +689,7 @@ class EditSource(EditPrimary):
self.citation)
if uses_dupe_id:
prim_object = self.db.get_citation_from_gramps_id(gramps_id)
name = prim_object.get_page()
name = get_gedcom_page(self.db, prim_object)
msg1 = _("Cannot save citation. ID already exists.")
msg2 = _("You have attempted to use the existing Gramps ID with "
"value %(gramps_id)s. This value is already used by '"
@ -712,13 +712,13 @@ class EditSource(EditPrimary):
# First commit the Source Primary object
if not self.obj.get_handle():
self.db.add_source(self.obj, trans)
msg = _("Add Source (%s)") % self.obj.get_title()
msg = _("Add Source (%s)") % get_gedcom_title(self.db, self.obj)
elif not only_cite:
#a changed source is not saved if only_cite
if not self.obj.get_gramps_id():
self.obj.set_gramps_id(self.db.find_next_source_gramps_id())
self.db.commit_source(self.obj, trans)
msg = _("Edit Source (%s)") % self.obj.get_title()
msg = _("Edit Source (%s)") % get_gedcom_title(self.db, self.obj)
else:
msg = ''
# Make sure citation references this source
@ -728,13 +728,13 @@ class EditSource(EditPrimary):
if self.citation_loaded:
if not self.citation.get_handle():
self.db.add_citation(self.citation, trans)
msg += "\n" + _("Add Citation (%s)") % self.citation.get_page()
msg += "\n" + _("Add Citation (%s)") % get_gedcom_page(self.db, self.citation)
else:
if not self.citation.get_gramps_id():
self.citation.set_gramps_id(
self.db.find_next_citation_gramps_id())
self.db.commit_citation(self.citation, trans)
msg += "\n" + _("Edit Citation (%s)") % self.citation.get_page()
msg += "\n" + _("Edit Citation (%s)") % get_gedcom_page(self.db, self.citation)
# set transaction description
trans.set_description(msg)
@ -881,7 +881,7 @@ class DeleteSrcQuery(object):
self.the_lists = the_lists
def query_response(self):
with DbTxn(_("Delete Source (%s)") % self.source.get_title(),
with DbTxn(_("Delete Source (%s)") % get_gedcom_title(self.db, self),
self.db) as trans:
self.db.disable_signals()

View File

@ -28,6 +28,8 @@ from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from gramps.gen.errors import WindowActiveError
from gi.repository import Gtk
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo)
class Citations(Gramplet, DbGUIElement):
@ -142,9 +144,9 @@ class Citations(Gramplet, DbGUIElement):
page = _('<No Citation>')
source_handle = citation.get_reference_handle()
source = self.dbstate.db.get_source_from_handle(source_handle)
title = source.get_title()
author = source.get_author()
publisher = source.get_publication_info()
title = get_gedcom_title(self.dbstate.db, source)
author = get_gedcom_author(self.dbstate.db, source)
publisher = get_gedcom_pubinfo(self.dbstate.db, source)
if source_handle not in self.source_nodes:
node = self.model.add([source_handle, title, author, publisher])

View File

@ -60,6 +60,8 @@ from gramps.gui.editors import (DeleteCitationQuery, EditSource,
DeleteSrcQuery)
from gramps.gui.filters.sidebar import SourceSidebarFilter
from gramps.gui.merge import MergeCitation, MergeSource
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo, get_gedcom_page)
#-------------------------------------------------------------------------
#
@ -194,10 +196,10 @@ class CitationTreeView(ListView):
_LOG.debug("\n\n\n")
if source:
_LOG.debug("---- %s -- source %s" %
(text, source.get_title()))
(text, get_gedcom_title(self.dbstate.db, source)))
elif citation:
_LOG.debug("---- %s -- citation %s" %
(text, citation.get_page()))
(text, get_gedcom_page(self.dbstate.db, citation)))
else:
_LOG.debug("---- %s -- handle %s" % (text, handle))

View File

@ -148,6 +148,8 @@ from gramps.gen.utils.place import conv_lat_lon
from gramps.gui.pluginmanager import GuiPluginManager
from gramps.gen.relationship import get_relationship_calculator
from gramps.gen.utils.citeref import (get_gedcom_title, get_gedcom_author,
get_gedcom_pubinfo, get_gedcom_page)
COLLATE_LANG = glocale.collation
SORT_KEY = glocale.sort_key
@ -2346,7 +2348,7 @@ class BasePage(object):
# Add this source and its references to the page
source = self.dbase_.get_source_from_handle(citation.get_source_handle())
if source is not None:
list = Html("li", self.source_link(source.get_handle(), source.get_title(),
list = Html("li", self.source_link(source.get_handle(), get_gedcom_title(self.dbase_, source),
source.get_gramps_id(), cindex, uplink = self.up))
else:
list = Html("li", "None")
@ -2361,7 +2363,7 @@ class BasePage(object):
conf = None
for (label, data) in [
[_("Date"), _dd.display(sref.date)],
[_("Page"), sref.page],
[_("Page"), get_gedcom_page(self.dbase_, sref)],
[_("Confidence"), conf] ]:
if data:
tmp += Html("li", "%s: %s" % (label, data))
@ -4180,7 +4182,7 @@ class SourcePages(BasePage):
for handle in source_handles:
source = self.db.get_source_from_handle(handle)
if source is not None:
key = source.get_title() + str(source.get_gramps_id())
key = get_gedcom_title(report.database, source) + str(source.get_gramps_id())
source_dict[key] = (source, handle)
keys = sorted(source_dict, key=SORT_KEY)
@ -4219,8 +4221,9 @@ class SourcePages(BasePage):
)
tbody += trow
trow.extend(
Html("td", self.source_link(source_handle, source.get_title(),
source.get_gramps_id()), class_ ="ColumnName")
Html("td", self.source_link(source_handle,
get_gedcom_title(report.database, source),
source.get_gramps_id()), class_ ="ColumnName")
)
# add clearline for proper styling
@ -4245,7 +4248,7 @@ class SourcePages(BasePage):
return
BasePage.__init__(self, report, title, source.get_gramps_id())
self.page_title = source.get_title()
self.page_title = get_gedcom_title(report.database, source)
inc_repositories = self.report.options["inc_repository"]
self.navigation = self.report.options['navigation']
@ -4267,7 +4270,7 @@ class SourcePages(BasePage):
sourcedetail += thumbnail
# add section title
sourcedetail += Html("h3", html_escape(source.get_title()), inline = True)
sourcedetail += Html("h3", html_escape(get_gedcom_title(report.database, source)), inline = True)
# begin sources table
with Html("table", class_ = "infolist source") as table:
@ -4282,9 +4285,9 @@ class SourcePages(BasePage):
for (label, value) in [
(_("Gramps ID"), source_gid),
(_("Author"), source.get_author()),
(_("Author"), get_gedcom_author(report.database, source)),
(_("Abbreviation"), source.get_abbreviation()),
(_("Publication information"), source.get_publication_info()) ]:
(_("Publication information"), get_gedcom_pubinfo(report.database, source)) ]:
if value:
trow = Html("tr") + (
Html("td", label, class_ = "ColumnAttribute", inline = True),
@ -7423,7 +7426,7 @@ class NavWebReport(Report):
def _add_source(self, source_handle, bkref_class, bkref_handle):
source = self.database.get_source_from_handle(source_handle)
source_name = source.get_title()
source_name = get_gedcom_title(self.database, source)
source_fname = self.build_url_fname(source_handle, "src",
False) + self.ext
self.obj_dict[Source][source_handle] = (source_fname, source_name,