Implement record locking for native gui

This commit is contained in:
thooge committed 2026-11-04 17:21:39 +01:00
1 parent 1a6674c819
commit 669c15109a
16 files changed
+162 -66

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ class Measurement(DbRecord):
table = "measurement" table = "measurement"
pk_field = "mid" pk_field = "mid"
fields = ('mid', 'mname', 'vid', 'eid', 'nval', 'val1', 'val2', 'val3', fields = ('mid', 'mname', 'vid', 'eid', 'nval', 'val1', 'val2', 'val3',
'unit', 'accuracy', 'mdate', 'note') 'unit', 'accuracy', 'mdate', 'mcat', 'note')
def __init__(self, db, mid=None): def __init__(self, db, mid=None):
super().__init__(db, mid) super().__init__(db, mid)
+3 -3
View File
@@ -3,17 +3,17 @@
<interface> <interface>
<requires lib="gtk+" version="3.24"/> <requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="adj_val1"> <object class="GtkAdjustment" id="adj_val1">
<property name="upper">100</property> <property name="upper">100000</property>
<property name="step-increment">1</property> <property name="step-increment">1</property>
<property name="page-increment">10</property> <property name="page-increment">10</property>
</object> </object>
<object class="GtkAdjustment" id="adj_val2"> <object class="GtkAdjustment" id="adj_val2">
<property name="upper">100</property> <property name="upper">100000</property>
<property name="step-increment">1</property> <property name="step-increment">1</property>
<property name="page-increment">10</property> <property name="page-increment">10</property>
</object> </object>
<object class="GtkAdjustment" id="adj_val3"> <object class="GtkAdjustment" id="adj_val3">
<property name="upper">100</property> <property name="upper">100000</property>
<property name="step-increment">1</property> <property name="step-increment">1</property>
<property name="page-increment">10</property> <property name="page-increment">10</property>
</object> </object>
+8 -4
View File
@@ -143,11 +143,13 @@ class BoxesView(View):
self.topwidget.set_visible_child(self.box['box_edit']) self.topwidget.set_visible_child(self.box['box_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Box"))
boxid = treeview.get_value(self.tree['box'], 0) boxid = treeview.get_value(self.tree['box'], 0)
if not boxid: if not boxid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Box"))
if not self.record_lock('box', boxid):
return
self.sbox.load(boxid) self.sbox.load(boxid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['box_edit']) self.topwidget.set_visible_child(self.box['box_edit'])
@@ -191,7 +193,9 @@ class BoxesView(View):
return return
self.save_record() self.save_record()
print(self.sbox) print(self.sbox)
self.sbox.save() if not self.sbox.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -218,5 +222,5 @@ class BoxesView(View):
return False return False
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['box']) self.topwidget.set_visible_child(self.box['box'])
self.newrecord = False
+6 -2
View File
@@ -162,11 +162,13 @@ class CablesView(View):
self.topwidget.set_visible_child(self.box['cable_edit']) self.topwidget.set_visible_child(self.box['cable_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Cable"))
cableid = treeview.get_value(self.tree['cables'], 0) cableid = treeview.get_value(self.tree['cables'], 0)
if not cableid: if not cableid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Cable"))
if not self.record_lock('cable', cableid):
return
self.cable.load(cableid) self.cable.load(cableid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['cable_edit']) self.topwidget.set_visible_child(self.box['cable_edit'])
@@ -215,6 +217,7 @@ class CablesView(View):
# TODO error in infobox # TODO error in infobox
print(self.context.db.last_error()) print(self.context.db.last_error())
return return
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -222,5 +225,6 @@ class CablesView(View):
self.topwidget.set_visible_child(self.box['cable_detail']) self.topwidget.set_visible_child(self.box['cable_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['cables']) self.topwidget.set_visible_child(self.box['cables'])
+6 -1
View File
@@ -143,6 +143,8 @@ class CompaniesView(View):
compid = treeview.get_value(self.tree['companies'], 0) compid = treeview.get_value(self.tree['companies'], 0)
if not compid: if not compid:
return return
if not self.record_lock('company', compid):
return
self.comp.load(compid) self.comp.load(compid)
self.edit_record() self.edit_record()
self.label['title_edit'].set_text(_("Edit Company")) self.label['title_edit'].set_text(_("Edit Company"))
@@ -187,7 +189,9 @@ class CompaniesView(View):
return return
self.save_record() self.save_record()
print(self.comp) print(self.comp)
self.comp.save() if not self.comp.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -195,4 +199,5 @@ class CompaniesView(View):
self.topwidget.set_visible_child(self.box['comp_detail']) self.topwidget.set_visible_child(self.box['comp_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['companies']) self.topwidget.set_visible_child(self.box['companies'])
+4 -1
View File
@@ -103,7 +103,6 @@ class EquipmentView(View):
self.entry['name'].grab_focus() self.entry['name'].grab_focus()
def display_record(self): def display_record(self):
print(self.equip)
self.label['name'].set_text(self.equip.ename) self.label['name'].set_text(self.equip.ename)
self.label['shortname'].set_text(self.equip.shortname or '') self.label['shortname'].set_text(self.equip.shortname or '')
if self.equip.manufacturer: if self.equip.manufacturer:
@@ -184,6 +183,8 @@ class EquipmentView(View):
if eid is None: if eid is None:
return return
self.label['title_edit'].set_text(_("Edit Equipment")) self.label['title_edit'].set_text(_("Edit Equipment"))
if not self.record_lock('equipment', eid):
return
self.equip.load(eid) self.equip.load(eid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['equip_edit']) self.topwidget.set_visible_child(self.box['equip_edit'])
@@ -239,6 +240,7 @@ class EquipmentView(View):
if not self.equip.save(): if not self.equip.save():
# TODO error handling # TODO error handling
pass pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.add_row() self.add_row()
#self.load_list() #self.load_list()
@@ -249,5 +251,6 @@ class EquipmentView(View):
self.topwidget.set_visible_child(self.box['equip_detail']) self.topwidget.set_visible_child(self.box['equip_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['equipment']) self.topwidget.set_visible_child(self.box['equipment'])
+11 -3
View File
@@ -160,11 +160,13 @@ class FusesView(View):
self.topwidget.set_visible_child(self.box['fuse_edit']) self.topwidget.set_visible_child(self.box['fuse_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
fuseid = treeview.get_value(self.tree['fuses'], 0)
if fuseid is None: if fuseid is None:
return return
self.label['title_edit'].set_text(_("Edit Fuse")) self.label['title_edit'].set_text(_("Edit Fuse"))
self.newrecord = False
fuseid = treeview.get_value(self.tree['fuses'], 0)
if not self.record_lock('fuse', fuseid):
return
self.fuse.load(fuseid) self.fuse.load(fuseid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['fuse_edit']) self.topwidget.set_visible_child(self.box['fuse_edit'])
@@ -211,10 +213,16 @@ class FusesView(View):
return return
self.save_record() self.save_record()
print(self.fuse) print(self.fuse)
self.fuse.save() if not self.fuse.save():
pass
self.record_unlock()
if self.newrecord:
self.load_list()
self.newrecord = False
self.display_record() self.display_record()
self.topwidget.set_visible_child(self.box['fuse_detail']) self.topwidget.set_visible_child(self.box['fuse_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['fuses']) self.topwidget.set_visible_child(self.box['fuses'])
+4 -24
View File
@@ -18,8 +18,6 @@ class InventoryView(View):
self.inv = inventory.Inventory(context.db) # current record self.inv = inventory.Inventory(context.db) # current record
self.newrecord = False self.newrecord = False
self.token = None # record locking
self.timer_id = None
# Inventory gets vessel assignment via # Inventory gets vessel assignment via
# - storage direct # - storage direct
@@ -73,10 +71,6 @@ class InventoryView(View):
# restore previous selected row # restore previous selected row
selection.select_iter(treeiter) selection.select_iter(treeiter)
def lock_timer(self):
self.context.db.lock_refresh(self.token)
return True # continue timer
def on_page_activated(self): def on_page_activated(self):
print("Inventory activated") print("Inventory activated")
@@ -180,20 +174,13 @@ class InventoryView(View):
invid = treeview.get_value(self.tree['inventory'], 0) invid = treeview.get_value(self.tree['inventory'], 0)
if invid is None: if invid is None:
return return
self.token = self.context.db.lock_acquire('inventory', invid, self.user.user_id)
if self.token is None:
gtkutils.messagebox(
_("Record is locked!\n"
"Edit prohibited."), title="YMS"
)
return
self.timer_id = GLib.timeout_add(120000, self.lock_timer) # 2 minutes lock refresh timer
self.newrecord = False self.newrecord = False
self.label['title_edit'].set_text(_("Edit Inventory")) self.label['title_edit'].set_text(_("Edit Inventory"))
if not self.record_lock('inventory', invid):
return
self.inv.load(invid) self.inv.load(invid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['inv_edit']) self.topwidget.set_visible_child(self.box['inv_edit'])
# TODO start timer to refresh record lock
def on_but_detail_clicked(self, widget): def on_but_detail_clicked(self, widget):
invid = treeview.get_value(self.tree['inventory'], 0) invid = treeview.get_value(self.tree['inventory'], 0)
@@ -262,22 +249,15 @@ class InventoryView(View):
print(self.inv) print(self.inv)
if not self.inv.save(): if not self.inv.save():
pass pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
else: else:
pass pass
# TODO aktuelle Listenzeile aktualisieren!
self.display_record() self.display_record()
self.topwidget.set_visible_child(self.box['inv_detail']) self.topwidget.set_visible_child(self.box['inv_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
if not self.newrecord: self.record_unlock()
if self.timer_id is not None:
# remove locking timer
GLib.source_remove(self.timer_id)
self.timer_id = None
if not self.token is None:
if not self.context.db.lock_release(self.token):
print("Error while releasing lock!")
self.topwidget.set_visible_child(self.box['inventory']) self.topwidget.set_visible_child(self.box['inventory'])
+10 -3
View File
@@ -133,11 +133,13 @@ class MaintenanceView(View):
self.topwidget.set_visible_child(self.box['maint_edit']) self.topwidget.set_visible_child(self.box['maint_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Maintenance"))
maintid = treeview.get_value(self.tree['maintenance'], 0) maintid = treeview.get_value(self.tree['maintenance'], 0)
if not maintid: if not maintid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Maintenance"))
if not self.record_lock('maintenance', maintid):
return
self.maint.load(maintid) self.maint.load(maintid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['maint_edit']) self.topwidget.set_visible_child(self.box['maint_edit'])
@@ -178,13 +180,17 @@ class MaintenanceView(View):
if not self.entry['activities'].get_text().strip(): if not self.entry['activities'].get_text().strip():
# TODO error marker # TODO error marker
return return
self.save_record() if not self.save_record():
pass
if not self.record_lock('maintenance', self.maint.maintid):
return
print(self.maint) print(self.maint)
if not self.maint.save(): if not self.maint.save():
print("Save error") print("Save error")
# TODO error in infobox # TODO error in infobox
print(self.context.db.last_error()) print(self.context.db.last_error())
return return
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -192,4 +198,5 @@ class MaintenanceView(View):
self.topwidget.set_visible_child(self.box['maint_detail']) self.topwidget.set_visible_child(self.box['maint_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['maintenance']) self.topwidget.set_visible_child(self.box['maintenance'])
+30 -12
View File
@@ -2,6 +2,7 @@
import os import os
from gi.repository import Gtk from gi.repository import Gtk
from dateutil.parser import parse
from .view import View from .view import View
from yms import gtkutils, combobox, treeview from yms import gtkutils, combobox, treeview
@@ -51,6 +52,9 @@ class MeasurementView(View):
treeview.add_column(self.tree['measurement'], _('Note'), 5) treeview.add_column(self.tree['measurement'], _('Note'), 5)
self.tree['measurement'].set_model(self.lst_measurement) self.tree['measurement'].set_model(self.lst_measurement)
self.entry['date'].set_placeholder_text(context.get_datefmt_placeholder())
DatePicker(self.entry['date'], self.button['date'], context.get_datefmt())
def load_list(self): def load_list(self):
selected_id = treeview.get_value(self.tree['measurement']) selected_id = treeview.get_value(self.tree['measurement'])
self.lst_measurement.clear() self.lst_measurement.clear()
@@ -64,12 +68,13 @@ class MeasurementView(View):
self.db.dcur.execute(sql, (self.context.vessel.vid,)) self.db.dcur.execute(sql, (self.context.vessel.vid,))
selection = self.tree['measurement'].get_selection() selection = self.tree['measurement'].get_selection()
for row in self.db.dcur.fetchall(): for row in self.db.dcur.fetchall():
unit = self.dd_unit[row['unit']]
if row['nval'] == 1: if row['nval'] == 1:
value = "{} {}".format(row['val1'], row['unit']) value = "{} {}".format(row['val1'], unit)
elif row['nval'] == 2: elif row['nval'] == 2:
value = "{}x{} {}".format(row['val1'], row['val2'], row['unit']) value = "{}x{} {}".format(row['val1'], row['val2'], unit)
elif row['nval'] == 3: elif row['nval'] == 3:
value = "{}x{}x{} {}".format(row['val1'], row['val2'], row['val3'], row['unit']) value = "{}x{}x{} {}".format(row['val1'], row['val2'], row['val3'], unit)
else: else:
#invalid #invalid
value = "#invalid" value = "#invalid"
@@ -82,7 +87,7 @@ class MeasurementView(View):
row['note'] or '' row['note'] or ''
) )
treeiter = self.lst_measurement.append(data) treeiter = self.lst_measurement.append(data)
if row[0] == selected_id: if row['mid'] == selected_id:
# restore previous selected row # restore previous selected row
selection.select_iter(treeiter) selection.select_iter(treeiter)
@@ -120,7 +125,7 @@ class MeasurementView(View):
self.label['unit'].set_text(self.dd_unit.get(self.measure.unit, '')) self.label['unit'].set_text(self.dd_unit.get(self.measure.unit, ''))
self.label['accuracy'].set_text(self.dd_accuracy[self.measure.accuracy]) self.label['accuracy'].set_text(self.dd_accuracy[self.measure.accuracy])
self.label['date'].set_text(self.format_date(self.measure.mdate)) self.label['date'].set_text(self.format_date(self.measure.mdate))
self.label['category'].set_text(self.dd_category[self.measure.mcat]) self.label['category'].set_text(self.dd_category.get(self.measure.mcat, ''))
self.label['note'].set_text(self.measure.note or '') self.label['note'].set_text(self.measure.note or '')
def edit_record(self): def edit_record(self):
@@ -140,10 +145,10 @@ class MeasurementView(View):
self.spin['val3'].set_value(self.measure.val3) self.spin['val3'].set_value(self.measure.val3)
combobox.activate_row(self.combo['unit'], self.measure.unit or 1) combobox.activate_row(self.combo['unit'], self.measure.unit or 1)
combobox.activate_row(self.combo['accuracy'], self.measure.accuracy) combobox.activate_row(self.combo['accuracy'], self.measure.accuracy)
self.entry['date'].set_text(self.measure.mdate) self.entry['date'].set_text(self.format_date(self.measure.mdate))
combobox.activate_row(self.combo['equipment'], self.measure.eid) combobox.activate_row(self.combo['equipment'], self.measure.eid)
combobox.activate_row(self.combo['category'], self.measure.mcat) combobox.activate_row(self.combo['category'], self.measure.mcat)
self.text['note'].get_buffer().set_text(self.task.note or '') self.text['note'].get_buffer().set_text(self.measure.note or '')
self.entry['name'].grab_focus() self.entry['name'].grab_focus()
self.label['edit_val2'].set_visible(self.measure.nval > 1) self.label['edit_val2'].set_visible(self.measure.nval > 1)
@@ -153,15 +158,24 @@ class MeasurementView(View):
def save_record(self): def save_record(self):
# fields must have been validated beforehand # fields must have been validated beforehand
self.measure.vid = self.context.vessel.vid
self.measure.mname = self.entry['name'].get_text() self.measure.mname = self.entry['name'].get_text()
self.measure.nval = combobox.get_list_value(self.combo['dimensions']) self.measure.nval = combobox.get_list_value(self.combo['dimensions'])
self.measure.val1 = self.spin['val1'].get_value_as_int() self.measure.val1 = self.spin['val1'].get_value_as_int()
self.measure.val2 = self.spin['val2'].get_value_as_int() self.measure.val2 = self.spin['val2'].get_value_as_int()
self.measure.val3 = self.spin['val3'].get_value_as_int() self.measure.val3 = self.spin['val3'].get_value_as_int()
self.measure.unit = combobox.get_list_value(self.combo['unit'])
self.measure.accuracy = combobox.get_list_value(self.combo['accuracy']) self.measure.accuracy = combobox.get_list_value(self.combo['accuracy'])
self.measure.mdate = self.entry['date'].get_text() try:
self.measure.mdate = parse(self.entry['date'].get_text(), dayfirst=True)
except ValueError:
self.measure.mdate = None
self.measure.eid = combobox.get_list_value(self.combo['equipment']) self.measure.eid = combobox.get_list_value(self.combo['equipment'])
if self.measure.eid == -1:
self.measure.eid = None
self.measure.mcat = combobox.get_list_value(self.combo['category']) self.measure.mcat = combobox.get_list_value(self.combo['category'])
if self.measure.mcat == -1:
self.measure.mcat = None
self.measure.note = gtkutils.get_text_contents(self.text['note']) self.measure.note = gtkutils.get_text_contents(self.text['note'])
# buttons on list page # buttons on list page
@@ -172,11 +186,13 @@ class MeasurementView(View):
self.topwidget.set_visible_child(self.box['measure_edit']) self.topwidget.set_visible_child(self.box['measure_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Measurement"))
mid = treeview.get_value(self.tree['measurement'], 0) mid = treeview.get_value(self.tree['measurement'], 0)
if not mid: if not mid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Measurement"))
if not self.record_lock('measurement', mid):
return
self.measure.load(mid) self.measure.load(mid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['measure_edit']) self.topwidget.set_visible_child(self.box['measure_edit'])
@@ -233,13 +249,15 @@ class MeasurementView(View):
self.infobar.set_revealed(False) self.infobar.set_revealed(False)
self.save_record() self.save_record()
print(self.measure) print(self.measure)
self.measure.save() if not self.measure.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
self.display_record() self.display_record()
self.topwidget.set_visible_child(self.box['measure_detail']) self.topwidget.set_visible_child(self.box['measure_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['measurement']) self.topwidget.set_visible_child(self.box['measurement'])
+7 -2
View File
@@ -2,6 +2,7 @@
import os import os
from gi.repository import Gtk from gi.repository import Gtk
from dateutil.parser import parse
from gettext import pgettext from gettext import pgettext
from .view import View from .view import View
@@ -120,11 +121,13 @@ class ProjectsView(View):
self.topwidget.set_visible_child(self.box['proj_edit']) self.topwidget.set_visible_child(self.box['proj_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Project"))
projid = treeview.get_value(self.tree['projects'], 0) projid = treeview.get_value(self.tree['projects'], 0)
if not projid: if not projid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Project"))
if not self.record_lock('project', projid):
return
self.project.load(projid) self.project.load(projid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['proj_edit']) self.topwidget.set_visible_child(self.box['proj_edit'])
@@ -172,6 +175,7 @@ class ProjectsView(View):
# TODO error in infobox # TODO error in infobox
print(self.context.db.last_error()) print(self.context.db.last_error())
return return
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -179,4 +183,5 @@ class ProjectsView(View):
self.topwidget.set_visible_child(self.box['proj_detail']) self.topwidget.set_visible_child(self.box['proj_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['projects']) self.topwidget.set_visible_child(self.box['projects'])
+8 -3
View File
@@ -167,11 +167,13 @@ class ProvisionsView(View):
self.topwidget.set_visible_child(self.box['prov_edit']) self.topwidget.set_visible_child(self.box['prov_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Provision"))
provid = treeview.get_value(self.tree['provisions'], 0) provid = treeview.get_value(self.tree['provisions'], 0)
if not provid: if not provid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Provision"))
if not self.record_lock('provision', provid):
return
self.prov.load(provid) self.prov.load(provid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['prov_edit']) self.topwidget.set_visible_child(self.box['prov_edit'])
@@ -230,7 +232,9 @@ class ProvisionsView(View):
return return
self.save_record() self.save_record()
print(self.prov) print(self.prov)
self.prov.save() if not self.prov.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
else: else:
@@ -241,4 +245,5 @@ class ProvisionsView(View):
self.topwidget.set_visible_child(self.box['prov_detail']) self.topwidget.set_visible_child(self.box['prov_detail'])
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['provisions']) self.topwidget.set_visible_child(self.box['provisions'])
+6 -2
View File
@@ -142,6 +142,8 @@ class StorageView(View):
return return
self.newrecord = False self.newrecord = False
self.label['title_edit'].set_text(_("Edit Storage")) self.label['title_edit'].set_text(_("Edit Storage"))
if not self.record_lock('storage', sid):
return
self.storage.load(sid) self.storage.load(sid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['stor_edit']) self.topwidget.set_visible_child(self.box['stor_edit'])
@@ -185,7 +187,9 @@ class StorageView(View):
return return
self.save_record() self.save_record()
print(self.storage) print(self.storage)
self.storage.save() if not self.storage.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.context.publish("storage_added", (self.storage.pk_value, self.storage.sname)) self.context.publish("storage_added", (self.storage.pk_value, self.storage.sname))
@@ -212,5 +216,5 @@ class StorageView(View):
return False return False
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['storage']) self.topwidget.set_visible_child(self.box['storage'])
self.newrecord = False
+8 -3
View File
@@ -149,11 +149,13 @@ class TasksView(View):
self.topwidget.set_visible_child(self.box['task_edit']) self.topwidget.set_visible_child(self.box['task_edit'])
def on_but_edit_clicked(self, widget): def on_but_edit_clicked(self, widget):
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Task"))
taskid = treeview.get_value(self.tree['tasks'], 0) taskid = treeview.get_value(self.tree['tasks'], 0)
if not taskid: if not taskid:
return return
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Task"))
if not self.record_lock('task', taskid):
return
self.task.load(taskid) self.task.load(taskid)
self.edit_record() self.edit_record()
self.topwidget.set_visible_child(self.box['task_edit']) self.topwidget.set_visible_child(self.box['task_edit'])
@@ -195,7 +197,9 @@ class TasksView(View):
return return
self.save_record() self.save_record()
print(self.task) print(self.task)
self.task.save() if not self.task.save():
pass
self.record_unlock()
if self.newrecord: if self.newrecord:
self.load_list() self.load_list()
self.newrecord = False self.newrecord = False
@@ -218,4 +222,5 @@ class TasksView(View):
pass pass
def on_but_cancel_clicked(self, widget): def on_but_cancel_clicked(self, widget):
self.record_unlock()
self.topwidget.set_visible_child(self.box['tasks']) self.topwidget.set_visible_child(self.box['tasks'])
+37
View File
@@ -21,6 +21,9 @@ class View:
self.user = context.user self.user = context.user
self._title = title self._title = title
self._lock_token = None # record locking
self._lock_timerid = None
locale.bindtextdomain(context.textdomain, context.localedir) locale.bindtextdomain(context.textdomain, context.localedir)
locale.textdomain(context.textdomain) locale.textdomain(context.textdomain)
@@ -36,6 +39,40 @@ class View:
gtkutils.init_named_controls(self, self.builder) gtkutils.init_named_controls(self, self.builder)
def record_lock(self, table, pk_value):
self._lock_token = self.context.db.lock_acquire(table, pk_value, self.user.user_id)
if self._lock_token is None:
gtkutils.messagebox(
_("Record #%(id)d in table '%(table)s' is locked!\n"
"Edit prohibited.") % {'id': pk_value, 'table': table},
title="YMS"
)
return False
# 2 minutes lock refresh timer
self._lock_timerid = GLib.timeout_add(120000, self.on_lock_timer)
return True
def record_unlock(self):
if self._lock_timerid is not None:
# remove locking timer
GLib.source_remove(self._lock_timerid)
self._lock_timerid = None
if not self._lock_token is None:
# remove lock from database
if not self.context.db.lock_release(self._lock_token):
print(_("Error while releasing record lock!"))
return False
self._lock_token = None
return True
def on_lock_timer(self):
if self._lock_token is not None:
self.context.db.lock_refresh(self._lock_token)
return True # continue timer
# no valid token, better stop our timer
self._lock_timerid = None
return False
def format_int(self, ival, separator=True, suffix=None, default=''): def format_int(self, ival, separator=True, suffix=None, default=''):
if ival is None: if ival is None:
return default return default
+13 -2
View File
@@ -225,6 +225,12 @@ class Frontend:
def run(self): def run(self):
self.window.show_all() self.window.show_all()
Gtk.main() Gtk.main()
# cleanup code for all modules
for module in self.modules.values():
method = getattr(module, "record_unlock", None)
if callable(method):
# remove all pending record locks
method()
def db_change_poller(self): def db_change_poller(self):
# dynamic combobox data refresh # dynamic combobox data refresh
@@ -339,8 +345,13 @@ if __name__ == "__main__":
errno, errtxt = context.db.last_error() errno, errtxt = context.db.last_error()
gtkutils.messagebox( gtkutils.messagebox(
_("Database connection cannot be established.\n\n" _("Database connection cannot be established.\n\n"
"Server: {}\nDatabase: {}\n" "Server: %(host)s\nDatabase: %(db)s\n"
"Error: {} ({})").format(context.cfg['host'], context.cfg['db'], errtxt, errno), "Error: %(errtxt)s (%(errno)d)") % {
'host': context.cfg['host'],
'db': context.cfg['db'],
'errtxt': errtxt,
'errno': errno
},
title="YMS") title="YMS")
# Another fine product of the sirius cybernetics corporation # Another fine product of the sirius cybernetics corporation