Commit fb1f2f0e authored by Michal Čihař's avatar Michal Čihař

Report lock update status back to frontend

This allows us to handle more comples scenarios.

Issue #983
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 9db24351
...@@ -747,7 +747,19 @@ $(function () { ...@@ -747,7 +747,19 @@ $(function () {
/* Lock updates */ /* Lock updates */
if ($('#js-lock').length > 0) { if ($('#js-lock').length > 0) {
var jsLockUpdate = window.setInterval(function () { var jsLockUpdate = window.setInterval(function () {
$.get($('#js-lock').attr('href')); $.ajax({
url: $('#js-lock').attr('href'),
success: function(data) {
console.log(data);
if (! data.status) {
$('.lock-error').remove();
var message = $('<div class="alert lock-error alert-danger"></div>');
message.text(data.message);
$('.content').prepend(message);
}
},
dataType: 'json'
});
}, 19000); }, 19000);
window.setInterval(function () { window.setInterval(function () {
window.clearInterval(jsLockUpdate); window.clearInterval(jsLockUpdate);
......
...@@ -349,17 +349,19 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin): ...@@ -349,17 +349,19 @@ class Translation(models.Model, URLMixin, PercentMixin, LoggerMixin):
''' '''
# Check if we can lock # Check if we can lock
if self.is_user_locked(user): if self.is_user_locked(user):
return return False
# Update timestamp # Update timestamp
if self.lock_user == user: if self.lock_user == user:
self.update_lock_time() self.update_lock_time()
return return True
# Auto lock if we should # Auto lock if we should
if appsettings.AUTO_LOCK and create: if appsettings.AUTO_LOCK and create:
self.create_lock(user) self.create_lock(user)
return return True
return False
def _reverse_url_name(self): def _reverse_url_name(self):
''' '''
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# #
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.http import HttpResponse from django.http import HttpResponse, JsonResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
...@@ -37,9 +37,17 @@ from weblate.trans.permissions import ( ...@@ -37,9 +37,17 @@ from weblate.trans.permissions import (
def update_lock(request, project, subproject, lang): def update_lock(request, project, subproject, lang):
obj = get_translation(request, project, subproject, lang) obj = get_translation(request, project, subproject, lang)
obj.update_lock(request.user, False) if obj.update_lock(request.user, False):
return JsonResponse(
data={'status': True}
)
return HttpResponse('ok') return JsonResponse(
data={
'status': False,
'message': _('Failed to update lock, probably session has expired'),
},
)
@login_required @login_required
......
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