summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_finds/models_finds.py2
-rw-r--r--archaeological_finds/views.py2
-rw-r--r--archaeological_operations/models.py2
-rw-r--r--ishtar_common/forms.py4
-rw-r--r--ishtar_common/models.py9
-rw-r--r--ishtar_common/templates/ishtar/blocks/window_nav.html6
-rw-r--r--ishtar_common/templates/ishtar/sheet.html7
-rw-r--r--ishtar_common/templatetags/ishtar_helpers.py7
-rw-r--r--ishtar_common/templatetags/window_header.py1
-rw-r--r--ishtar_common/views.py6
-rw-r--r--ishtar_common/views_item.py12
11 files changed, 44 insertions, 14 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index fc8483329..71fafbbe8 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -1766,7 +1766,7 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,
# own basket
actions = super(Find, self).get_extra_actions(request)
- is_locked = getattr(self, "locked", False)
+ is_locked = hasattr(self, "is_locked") and self.is_locked(request.user)
can_edit_find = self.can_do(request, 'change_find')
if can_edit_find and not is_locked:
actions += [
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 0bb835bb7..8c787836f 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -1080,7 +1080,7 @@ class QAFindTreatmentFormView(QAItemForm):
returned = super(QAFindTreatmentFormView, self).dispatch(
request, *args, **kwargs)
for item in self.items:
- if item.locked:
+ if item.is_locked(request.user):
return HttpResponseRedirect(reverse("qa-not-available"))
return returned
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 19e528de1..d826d3c79 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -1324,7 +1324,7 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem, QRCodeItem,
actions = super(Operation, self).get_extra_actions(request)
can_add_cr = self.can_do(request, 'add_contextrecord')
- if can_add_cr and not self.locked:
+ if can_add_cr and not self.is_locked(request.user):
actions += [
(reverse('operation-qa-contextrecord', args=[self.pk]),
_("Add context record"), "fa fa-plus",
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index c9c88b805..a7774df1f 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -383,11 +383,13 @@ class CustomFormSearch(forms.Form):
if 'user' in kwargs:
user = kwargs.pop('user')
super(CustomFormSearch, self).__init__(*args, **kwargs)
+ self.request_user = user
if user and 'pk' in self.fields:
self.fields['pk'].widget.user = user
class LockForm(object):
+ need_user_for_initialization = True
associated_models = {}
def clean(self):
@@ -412,7 +414,7 @@ class LockForm(object):
item = model.objects.get(pk=pk)
except model.DoesNotExist:
raise forms.ValidationError(_("Invalid selection."))
- if item.locked:
+ if item.is_locked(self.request_user):
raise forms.ValidationError(_("This item is locked "
"for edition."))
return self.cleaned_data
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index cb1325af1..f3ef8103c 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1852,7 +1852,9 @@ class DocumentItem(object):
return actions
can_add_doc = self.can_do(request, 'add_document')
- if can_add_doc and not getattr(self, "locked", False):
+ if can_add_doc and (
+ not hasattr(self, "is_locked") or
+ not self.is_locked(request.user)):
actions = [
(
reverse("create-document") + "?{}={}".format(
@@ -2164,6 +2166,11 @@ class BaseHistorizedItem(StatisticItem, TemplateItem, FullSearch, Imported,
def get_verbose_name(cls):
return cls._meta.verbose_name
+ def is_locked(self, user=None):
+ if not user:
+ return self.locked
+ return self.locked and (not self.lock_user or self.lock_user != user)
+
def merge(self, item, keep_old=False):
merge_model_objects(self, item, keep_old=keep_old)
diff --git a/ishtar_common/templates/ishtar/blocks/window_nav.html b/ishtar_common/templates/ishtar/blocks/window_nav.html
index c248bae82..60e620f16 100644
--- a/ishtar_common/templates/ishtar/blocks/window_nav.html
+++ b/ishtar_common/templates/ishtar/blocks/window_nav.html
@@ -1,4 +1,4 @@
-{% load i18n %}
+{% load i18n ishtar_helpers %}
<div class="row toolbar">
{% if previous or next %}
<div class='col-md-2'>
@@ -44,7 +44,7 @@
{% endif %}
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans 'Actions' %}">
{% block extra_actions %}{% endblock %}
- {% if modify_url and not item.locked %}
+ {% if modify_url and not item|is_locked:current_user %}
<a class="btn btn-success wait-button" href='{% url modify_url item.pk %}'
title="{% trans 'Modify' %}">
<i class="fa fa-pencil"></i>
@@ -56,7 +56,7 @@
<i class="{{icon}}"></i> {{extra_text}}
</a>
{% endfor %}
- {% if delete_url and not item.locked %}
+ {% if delete_url and not item|is_locked:current_user %}
<a class="btn btn-danger wait-button" href='{% url delete_url item.pk %}'
title="{% trans 'Delete' %}">
<i class="fa fa-trash" aria-hidden="true"></i>
diff --git a/ishtar_common/templates/ishtar/sheet.html b/ishtar_common/templates/ishtar/sheet.html
index 5676a4419..1c3ae37a0 100644
--- a/ishtar_common/templates/ishtar/sheet.html
+++ b/ishtar_common/templates/ishtar/sheet.html
@@ -1,4 +1,4 @@
-{% load i18n %}{% block main_head %}<html lang="en">
+{% load i18n ishtar_helpers %}{% block main_head %}<html lang="en">
<head>
<title>{% block title %}Ishtar{% if APP_NAME %} - {{APP_NAME}}{%endif%}{% endblock %}
</title>
@@ -121,12 +121,17 @@
<div class="body">
{% if item.locked %}
<div class="alert alert-warning" role="alert">
+ {% if item|is_locked:request.user %}
<i class="fa fa-lock text-danger" aria-hidden="true"></i>&nbsp;
{% if item.lock_user %}{% blocktrans with locker=item.lock_user.ishtaruser %}
This item has been locked by {{locker}}. Edition is disabled.
{% endblocktrans %}{% else %}
{% trans "This item has been locked. Edition is disabled." %}
{% endif %}
+ {% else %}
+ <i class="fa fa-lock text-success" aria-hidden="true"></i>&nbsp;
+ {% trans "You have locked this item." %}
+ {% endif %}
</div>
{% endif %}
{% block content %}
diff --git a/ishtar_common/templatetags/ishtar_helpers.py b/ishtar_common/templatetags/ishtar_helpers.py
index b6040487a..51f5e722e 100644
--- a/ishtar_common/templatetags/ishtar_helpers.py
+++ b/ishtar_common/templatetags/ishtar_helpers.py
@@ -22,3 +22,10 @@ def file_content(value):
if value:
return mark_safe(value.read())
return ""
+
+
+@register.filter
+def is_locked(item, user):
+ if not hasattr(item, "is_locked"):
+ return False
+ return item.is_locked(user)
diff --git a/ishtar_common/templatetags/window_header.py b/ishtar_common/templatetags/window_header.py
index 3c77ccf43..583101e66 100644
--- a/ishtar_common/templatetags/window_header.py
+++ b/ishtar_common/templatetags/window_header.py
@@ -27,6 +27,7 @@ def window_nav(context, item, window_id, show_url, modify_url='', histo_url='',
modify_url_value = modify_url
delete_url = getattr(item, "DELETE_URL", False)
return {
+ 'current_user': context['request'].user,
'show_url': show_url,
'modify_url': modify_url_value,
'delete_url': delete_url,
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 44831ba9f..d8474e6b0 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -92,7 +92,7 @@ def wizard_is_available(wizard, request, model, pk):
if not q.count():
raise Http404()
obj = q.all()[0]
- if hasattr(obj, "locked") and obj.locked:
+ if hasattr(obj, "is_locked") and obj.is_locked(request.user):
raise Http404()
return obj
@@ -2277,9 +2277,9 @@ class QAItemEditForm(QAItemForm):
request, *args, **kwargs)
if redirected:
return redirected
- if hasattr(self.model, "locked"):
+ if hasattr(self.model, "is_locked"):
for item in self.items:
- if item.locked:
+ if item.is_locked(request.user):
redirected = HttpResponseRedirect(
reverse("qa-not-available", args=["locked"]))
return redirected
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 4e29a2bcf..6f5dba236 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1159,6 +1159,7 @@ def _get_data_from_query(items, query_table_cols, extra_request_keys,
values += ['point_x', 'point_y']
if hasattr(items.model, "locked"):
values.append("locked")
+ values.append("lock_user_id")
data_list = items.values_list(*values)
return data_list
@@ -1233,6 +1234,7 @@ def _get_data_from_query_old(items, query_table_cols, request,
data.append(u" & ".join(my_vals) or u"")
if has_lock:
data.append(item.locked)
+ data.append(item.lock_user_id)
datas.append(data)
return datas
@@ -1860,7 +1862,10 @@ def get_item(model, func_name, default_name, extra_request_keys=None,
"<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i><lock></a>"
link_ext_template = '<a href="{}" target="_blank"></a>'
lock = '&nbsp;<i class="fa fa-lock text-danger" aria-hidden="true"></i>'
+ own_lock = '&nbsp;<i class="fa fa-lock text-success" ' \
+ 'aria-hidden="true"></i>'
has_locks = hasattr(model, "locked")
+ current_user_id = request.user and request.user.id
if data_type.startswith("json"):
rows = []
if data_type == 'json-map':
@@ -1881,8 +1886,11 @@ def get_item(model, func_name, default_name, extra_request_keys=None,
lnk_template = link_template
lnk = lnk_template.format(
reverse('show-' + default_name, args=[data[0], '']))
- if has_locks and data[-1]:
- lnk = lnk.replace('<lock>', lock)
+ if has_locks and data[-2]:
+ if data[-1] == current_user_id:
+ lnk = lnk.replace('<lock>', own_lock)
+ else:
+ lnk = lnk.replace('<lock>', lock)
else:
lnk = lnk.replace('<lock>', "")
except NoReverseMatch: