Skip to content

Commit

Permalink
when and where to show the hybrid marker.
Browse files Browse the repository at this point in the history
it should NOT be in the text entry, otherwise the TPL search will not work.
related to #8 and #3
  • Loading branch information
mfrasca committed Jan 21, 2016
1 parent 23c1296 commit 9d9fb79
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
13 changes: 8 additions & 5 deletions bauble/plugins/plants/genus.py
Expand Up @@ -149,7 +149,8 @@ class Genus(db.Base, db.Serializable, db.WithNotes):
def search_view_markup_pair(self):
'''provide the two lines describing object for SearchView row.
'''
return utils.xml_safe(self), utils.xml_safe(self.family)
return utils.xml_safe(self.str(use_hybrid_marker=True),
utils.xml_safe(self.family))

@property
def cites(self):
Expand Down Expand Up @@ -214,16 +215,17 @@ def accepted(self, value):
def __repr__(self):
return self.str()

def str(self, author=False):
def str(self, author=False, use_hybrid_marker=False):
# string representation of genus, good for markup.
prepend = use_hybrid_marker and self.hybrid_marker or ''
if self.epithet is None:
return repr(self)
elif not author or self.author is None:
return (self.hybrid_marker +
return (prepend +
' '.join([s for s in [self.epithet, self.aggregate]
if s not in ('', None)]))
else:
return (self.hybrid_marker +
return (prepend +
' '.join(
[s for s in [self.epithet, self.aggregate,
xml.sax.saxutils.escape(self.author)]
Expand Down Expand Up @@ -860,7 +862,8 @@ def update(self, row):
session = object_session(row)
self.current_obj = row
self.widget_set_value('gen_name_data', '<big>%s</big> %s' %
(row, utils.xml_safe(unicode(row.author))),
(row.str(use_hybrid_marker=True),
utils.xml_safe(unicode(row.author))),
markup=True)
self.widget_set_value('gen_fam_data',
(utils.xml_safe(unicode(row.family))))
Expand Down
2 changes: 1 addition & 1 deletion bauble/plugins/plants/species.py
Expand Up @@ -323,7 +323,7 @@ def update(self, row):
self.widgets.sp_fam_data, on_label_clicked, row.genus.family)
# link to genus
self.widget_set_value('sp_gen_data', '<big><i>%s</i></big>' %
row.genus.epithet, markup=True)
row.genus.str(use_hybrid_marker=True), markup=True)
utils.make_label_clickable(
self.widgets.sp_gen_data, on_label_clicked, row.genus)
# epithet (full binomial but missing genus)
Expand Down
2 changes: 1 addition & 1 deletion bauble/plugins/plants/species_model.py
Expand Up @@ -377,7 +377,7 @@ def str(self, authors=False, markup=False, remove_zws=False, genus=True,
# since it won't be able to look up the genus....we could
# probably try to query the genus directly with the genus_id
if genus is True:
genus = self.genus.str(author=False)
genus = self.genus.str(author=False, use_hybrid_marker=True)
else:
genus = ''
if self.epithet and not remove_zws:
Expand Down
19 changes: 15 additions & 4 deletions bauble/plugins/plants/test.py
Expand Up @@ -540,23 +540,34 @@ def test_genus_str_plain(self):
genus = Genus(family=f, epithet=u'Crataegus',
author='L.', hybrid_marker='')
self.assertEquals(genus.str(), 'Crataegus')
self.assertEquals(genus.str(use_hybrid_marker=True), 'Crataegus')
self.assertEquals(genus.str(author=True),
'Crataegus L.')

def test_genus_str_nothotaxon(self):
f = Family(epithet=u'Rosaceae')
genus = Genus(family=f, epithet=u"Cratae-Mespilus",
author="E.G.Camus", hybrid_marker="×")
self.assertEquals(genus.str(), '×Cratae-Mespilus')
self.assertEquals(genus.str(author=True),
'×Cratae-Mespilus E.G.Camus')
self.assertEquals(
genus.str(), 'Cratae-Mespilus')
self.assertEquals(
genus.str(use_hybrid_marker=True), '×Cratae-Mespilus')
self.assertEquals(
genus.str(author=True), 'Cratae-Mespilus E.G.Camus')
self.assertEquals(
genus.str(author=True, use_hybrid_marker=True),
'×Cratae-Mespilus E.G.Camus')

def test_genus_str_graft_chimera(self):
f = Family(epithet=u'Rosaceae')
genus = Genus(family=f, epithet=u'Crataegomespilus',
author="Simon-Louis & Bellair", hybrid_marker="+")
self.assertEquals(genus.str(), '+Crataegomespilus')
self.assertEquals(genus.str(), 'Crataegomespilus')
self.assertEquals(
genus.str(use_hybrid_marker=True), '+Crataegomespilus')
self.assertEquals(genus.str(author=True),
'Crataegomespilus Simon-Louis &amp; Bellair')
self.assertEquals(genus.str(use_hybrid_marker=True, author=True),
'+Crataegomespilus Simon-Louis &amp; Bellair')

def test_synonyms(self):
Expand Down

0 comments on commit 9d9fb79

Please sign in to comment.