Skip to content

Commit

Permalink
added all the logic to have several accession code formats stored in …
Browse files Browse the repository at this point in the history
…the database.

still to implement, the interface to add them to the database.
related to Bauble/bauble.classic#59
  • Loading branch information
mfrasca committed Jan 28, 2016
1 parent 9a3b0e7 commit 3c07892
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 23 deletions.
136 changes: 113 additions & 23 deletions bauble/plugins/garden/acc_editor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@
<!-- column-name gchararray1 -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0"></col>
</row>
<row>
<col id="0">%Y.####</col>
</row>
<row>
<col id="0">%{Y-1}.####</col>
</row>
<row>
<col id="0">XXXX.####</col>
</row>
<row>
<col id="0">SD.#####</col>
</row>
<row>
<col id="0">H.#####</col>
</row>
<row>
<col id="0">######</col>
</row>
</data>
</object>
<object class="GtkDialog" id="accession_dialog">
<property name="can_focus">False</property>
Expand Down Expand Up @@ -2858,6 +2835,119 @@
<placeholder/>
</child>
</object>
<object class="GtkDialog" id="dialog1">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Accession Code Formats</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow8">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="border_width">1</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title" translatable="yes">item</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title" translatable="yes">accession code format</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2">
<signal name="edited" handler="on_cellrenderertext2_edited" swapped="no"/>
</object>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
<action-widget response="0">button1</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name gchararray1 -->
<column type="gchararray"/>
<!-- column-name gchararray2 -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="source_details_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
Expand Down
14 changes: 14 additions & 0 deletions bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import bauble
import bauble.db as db
import bauble.editor as editor
from bauble import meta
from bauble.error import check
import bauble.paths as paths
from bauble.plugins.garden.propagation import SourcePropagationPresenter, \
Expand Down Expand Up @@ -1732,6 +1733,9 @@ 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:
Expand Down Expand Up @@ -1914,6 +1918,16 @@ 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):
ls = self.view.widgets.acc_code_format_liststore
ls.clear()
ls.append([''])
for row in self.session.\
query(meta.BaubleMeta).\
filter(meta.BaubleMeta.name.like(u'acidf_%')).\
order_by(meta.BaubleMeta.name):
ls.append([row.value])

def on_acc_code_format_comboentry_changed(self, widget, *args):
code_format = self.view.widget_get_value(widget)
code = Accession.get_next_code(code_format)
Expand Down

0 comments on commit 3c07892

Please sign in to comment.