Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
closes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jun 4, 2015
1 parent bbcefc4 commit 0dd7e53
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
3 changes: 3 additions & 0 deletions bauble/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import logging
logger = logging.getLogger(__name__)
#logger.setLevel(logging.DEBUG)

import glib
import gtk
Expand Down Expand Up @@ -516,6 +517,8 @@ def remove_problem(self, problem_id, problem_widgets=None):
from, if None then remove all occurrences of problem_id regardless
of the widget
"""
logger.debug('remove_problem(%s, %s, %s)' %
(self, problem_id, problem_widgets))
if problem_id is None and problem_widgets is None:
logger.warning('invoke remove_problem with None, None')
# if no problem id and not problem widgets then don't do anything
Expand Down
68 changes: 34 additions & 34 deletions bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import logging
logger = logging.getLogger(__name__)
#logger.setLevel(logging.DEBUG)

import gtk

Expand Down Expand Up @@ -218,7 +219,7 @@ def acc_markup_func(acc):
"""
Returns str(acc), acc.species_str()
"""
return utils.xml_safe_utf8(unicode(acc)), acc.species_str(markup=True)
return utils.xml_safe(unicode(acc)), acc.species_str(markup=True)


# TODO: accession should have a one-to-many relationship on verifications
Expand Down Expand Up @@ -1031,23 +1032,6 @@ def dirty(self):
def refresh_view(self):
pass

def on_taxon_add_button_clicked(self, button, taxon_entry):
## the `model` is an accession, it does refer to a species, but we
## come here when we are adding a Verification, so we are not
## interested in editing anything, we just want to add a taxon.

## we really should check what happened in the SpeciesEditor,
## because we do want to immediately use the object added by the
## user!

from bauble.plugins.plants.species import SpeciesEditor
editor = SpeciesEditor(parent=self.view.get_window())
if editor.start():
self.session.add(editor.model)
taxon_entry.set_text("%s" % editor.model)
self.remove_problem(None, taxon_entry)
self.parent_ref().refresh_sensitivity()

def on_add_clicked(self, *args):
self.add_verification_box()

Expand All @@ -1068,7 +1052,6 @@ def __init__(self, parent, model):
super(VerificationPresenter.VerificationBox, self).__init__(self)
check(not model or isinstance(model, Verification))

self.dirty = False
self.presenter = weakref.ref(parent)
self.model = model
if not self.model:
Expand Down Expand Up @@ -1161,7 +1144,7 @@ def on_sp_select(value):
## add a taxon implies setting the ver_new_taxon_entry
self.presenter().view.connect(
self.widgets.ver_taxon_add_button, 'clicked',
self.presenter().on_taxon_add_button_clicked,
self.on_taxon_add_button_clicked,
ver_new_taxon_entry)

combo = self.widgets.ver_level_combo
Expand Down Expand Up @@ -1249,21 +1232,20 @@ def on_level_combo_changed(self, combo, *args):
def set_model_attr(self, attr, value):
setattr(self.model, attr, value)
if attr != 'date' and not self.model.date:
# this is a little voodoo to set the date on the model
# since when we create a new verification box we add
# today's date to the entry but we don't set the model
# so the presenter doesn't appear dirty...we have to
# use a tmp variable since the changed signal won't
# fire if the new value is the same as the old
# When we create a new verification box we set today's date
# in the GtkEntry but not in the model so the presenter
# doesn't appear dirty. Now that the user is setting
# something, we trigger the 'changed' signal on the 'date'
# entry as well, by first clearing the entry then setting it
# to its intended value.
tmp = self.date_entry.props.text
self.date_entry.props.text = ''
self.date_entry.props.text = tmp
# if the verification is new and isn't yet associated
# with an accession then set the accession when we
# start changing values, this way we can setup a dummy
# verification in the interface
if not self.model.accession:
self.presenter().model.verifications.append(self.model)
# if the verification isn't yet associated with an accession
# then set the accession when we start changing values, this way
# we can setup a dummy verification in the interface
if not self.model.accession:
self.presenter().model.verifications.append(self.model)
self.presenter()._dirty = True
self.update_label()
self.presenter().parent_ref().refresh_sensitivity()
Expand All @@ -1274,9 +1256,9 @@ def update_label(self):
if self.model.date:
parts.append('<b>%(date)s</b> : ')
if self.model.species:
parts.append('verified as %(species)s ')
parts.append(_('verified as %(species)s '))
if self.model.verifier:
parts.append('by %(verifier)s')
parts.append(_('by %(verifier)s'))
label = ' '.join(parts) % dict(date=self.model.date,
species=self.model.species,
verifier=self.model.verifier)
Expand All @@ -1286,6 +1268,23 @@ def update_label(self):
def set_expanded(self, expanded):
self.widgets.ver_expander.props.expanded = expanded

def on_taxon_add_button_clicked(self, button, taxon_entry):
## we come here when we are adding a Verification, and the
## Verification wants to refer to a new taxon.

from bauble.plugins.plants.species import SpeciesEditor
editor = SpeciesEditor(parent=self.presenter().view.get_window())
if editor.start():
logger.debug('new taxon added from within VerificationBox')
# add the new taxon to the session and start using it
self.presenter().session.add(editor.model)
taxon_entry.set_text("%s" % editor.model)
self.presenter().remove_problem(
hash(taxon_entry.get_name()), None)
self.set_model_attr('species', editor.model)
logger.debug('is VerificationPresenter dirty? %s' %
self.presenter()._dirty)


class SourcePresenter(editor.GenericEditorPresenter):
"""
Expand Down Expand Up @@ -1431,6 +1430,7 @@ def dirty(self):
self.collection_presenter.dirty()

def refresh_sensitivity(self):
logger.warning('refresh_sensitivity: %s' % str(self.problems))
self.parent_ref().refresh_sensitivity()

def on_coll_add_button_clicked(self, *args):
Expand Down
4 changes: 3 additions & 1 deletion bauble/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import logging
logger = logging.getLogger(__name__)
#logger.setLevel(logging.DEBUG)


def find_dependent_tables(table, metadata=None):
Expand Down Expand Up @@ -698,7 +699,8 @@ def xml_safe_utf8(obj):
"""
This method is deprecated and just returns xml_safe(obj)
"""
logger.warning('invoking deprecated method')
logger.warning('invoking deprecated function')

return xml_safe(obj)


Expand Down

0 comments on commit 0dd7e53

Please sign in to comment.