Implement record locking for native gui
This commit is contained in:
1 parent
1a6674c819
commit
669c15109a
16 files changed
+162
-66
No files matched your search
@@ -21,6 +21,9 @@ class View:
|
||||
self.user = context.user
|
||||
self._title = title
|
||||
|
||||
self._lock_token = None # record locking
|
||||
self._lock_timerid = None
|
||||
|
||||
locale.bindtextdomain(context.textdomain, context.localedir)
|
||||
locale.textdomain(context.textdomain)
|
||||
|
||||
@@ -36,6 +39,40 @@ class View:
|
||||
|
||||
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=''):
|
||||
if ival is None:
|
||||
return default
|
||||
|
||||
Reference in new issue
Block a user