Skip to content

Commit

Permalink
user can store alternative accession code formats stored in database.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jan 28, 2016
1 parent a40c370 commit 5c36d96
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bauble/plugins/garden/acc_editor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
<action-widget response="0">button1</action-widget>
<action-widget response="-1">button2</action-widget>
<action-widget response="1">button1</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="acc_codes_liststore">
Expand Down
55 changes: 38 additions & 17 deletions bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,19 +1733,15 @@ def __init__(self, model, view):
self._original_code = self.model.code
self.current_source_box = None

self.populate_code_formats()

# set the default code and add it to the top of the code formats
ls = view.widgets.acc_code_format_liststore
first_row = ls.get_iter_first()
if not model.code:
model.code = model.get_next_code()
if self.model.species:
self._dirty = True
top_value = u''
else:
top_value = model.code
ls.set_value(first_row, 0, top_value)
self.populate_code_formats(top_value)
self.view.widget_set_value('acc_code_format_comboentry', top_value)

self.ver_presenter = VerificationPresenter(self, self.model, self.view,
Expand Down Expand Up @@ -1918,18 +1914,23 @@ def on_loc2_select(value):
if self.model not in self.session.new:
self.view.widgets.acc_ok_and_add_button.set_sensitive(True)

def populate_code_formats(self):
def populate_code_formats(self, entry_one=None, values=None):
print 'populate_code_formats', entry_one, values
ls = self.view.widgets.acc_code_format_liststore
if entry_one is None:
entry_one = ls.get_value(ls.get_iter_first(), 0)
ls.clear()
ls.append([''])
query = self.session.\
query(meta.BaubleMeta).\
filter(meta.BaubleMeta.name.like(u'acidf_%')).\
order_by(meta.BaubleMeta.name)
if query.count():
Accession.code_format = query.first().value
for row in query:
ls.append([row.value])
ls.append([entry_one])
if values is None:
query = self.session.\
query(meta.BaubleMeta).\
filter(meta.BaubleMeta.name.like(u'acidf_%')).\
order_by(meta.BaubleMeta.name)
if query.count():
Accession.code_format = query.first().value
values = [r.value for r in query]
for v in values:
ls.append([v])

def on_acc_code_format_comboentry_changed(self, widget, *args):
code_format = self.view.widget_get_value(widget)
Expand Down Expand Up @@ -1964,8 +1965,28 @@ def on_acc_cf_renderer_edited(self, widget, iter, value):
ls.set_value(i, 0, ls.get_value(i, 0)-1)
i = ls.iter_next(i)

presenter = Presenter(ls, view)
presenter.start() # does not save them yet
presenter = Presenter(ls, view, session=db.Session())
if presenter.start() > 0:
presenter.session.\
query(meta.BaubleMeta).\
filter(meta.BaubleMeta.name.like(u'acidf_%')).\
delete(synchronize_session=False)
i = 1
iter = ls.get_iter_first()
values = []
while iter:
value = ls.get_value(iter, 1)
iter = ls.iter_next(iter)
i += 1
if not value:
continue
obj = meta.BaubleMeta(name=u'acidf_%02d' % i,
value=value)
values.append(value)
presenter.session.add(obj)
self.populate_code_formats(values=values)
presenter.session.commit()
presenter.session.close()

def refresh_id_qual_rank_combo(self):
"""
Expand Down

1 comment on commit 5c36d96

@mfrasca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.