Commit 066f70d3 authored by Michal Čihař's avatar Michal Čihař

Shorten automatic locks (issue #175)

parent 9b656595
......@@ -333,8 +333,10 @@ This can be either done manually on translation page or is done automatically
when somebody starts to work on translation. The automatic locking needs to be
enabled using :setting:`AUTO_LOCK`.
The lock is valid for :setting:`LOCK_TIME` seconds and is automatically
extended on every translation made.
The automatic lock is valid for :setting:`AUTO_LOCK_TIME` seconds and is
automatically extended on every translation made.
User can also explicitly lock translation for :setting:`LOCK_TIME` seconds.
.. _custom-checks:
......
......@@ -41,6 +41,15 @@ Enables automatic locking of translation when somebody is working on it.
.. seealso:: :ref:`locking`
.. setting:: AUTO_LOCK_TIME
AUTO_LOCK_TIME
--------------
Time in seconds for how long the automatic lock for translation will be active.
.. seealso:: :ref:`locking`
.. setting:: CHECK_LIST
CHECK_LIST
......@@ -84,7 +93,7 @@ LOCK_TIME
---------
Time in seconds for how long the translation will be locked for single
translator.
translator when locked manually.
.. seealso:: :ref:`locking`
......
......@@ -316,6 +316,7 @@ OFFLOAD_INDEXING = False
# Translation locking
AUTO_LOCK = True
AUTO_LOCK_TIME = 60
LOCK_TIME = 15 * 60
# Where to put Whoosh index
......
......@@ -1349,18 +1349,35 @@ class Translation(models.Model):
return True
def create_lock(self, user):
def create_lock(self, user, explicit=False):
'''
Creates lock on translation.
'''
is_new = self.lock_user is None
self.lock_user = user
self.update_lock_time()
def update_lock_time(self):
# Clean timestamp on unlock
if user is None:
self.lock_time = datetime.now()
self.save()
return
self.update_lock_time(explicit, is_new)
def update_lock_time(self, explicit=False, is_new=True):
'''
Sets lock timestamp.
'''
self.lock_time = datetime.now() + timedelta(seconds=settings.LOCK_TIME)
if explicit:
seconds = settings.LOCK_TIME
else:
seconds = settings.AUTO_LOCK_TIME
new_lock_time = datetime.now() + timedelta(seconds=seconds)
if is_new or new_lock_time > self.lock_time:
self.lock_time = new_lock_time
self.save()
def update_lock(self, request):
......
......@@ -928,7 +928,7 @@ def lock_translation(request, project, subproject, lang):
)
if not obj.is_user_locked(request):
obj.create_lock(request.user)
obj.create_lock(request.user, True)
messages.info(request, _('Translation is now locked for you.'))
return HttpResponseRedirect(obj.get_absolute_url())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment