summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/migrations/0108_auto_20190910_1323.py43
-rw-r--r--ishtar_common/models.py3
-rw-r--r--ishtar_common/templates/ishtar/sheet.html10
-rw-r--r--ishtar_common/templatetags/link_to_window.py7
-rw-r--r--ishtar_common/views_item.py31
5 files changed, 82 insertions, 12 deletions
diff --git a/ishtar_common/migrations/0108_auto_20190910_1323.py b/ishtar_common/migrations/0108_auto_20190910_1323.py
new file mode 100644
index 000000000..ef7e16ba3
--- /dev/null
+++ b/ishtar_common/migrations/0108_auto_20190910_1323.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-09-10 13:23
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('ishtar_common', '0107_auto_20190910_1248'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='document',
+ name='lock_user',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Locked by'),
+ ),
+ migrations.AddField(
+ model_name='historicalorganization',
+ name='lock_user',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL),
+ ),
+ migrations.AddField(
+ model_name='historicalperson',
+ name='lock_user',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL),
+ ),
+ migrations.AddField(
+ model_name='organization',
+ name='lock_user',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Locked by'),
+ ),
+ migrations.AddField(
+ model_name='person',
+ name='lock_user',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL, verbose_name='Locked by'),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index e83f26640..bc9e68c02 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2097,6 +2097,9 @@ class BaseHistorizedItem(StatisticItem, TemplateItem, FullSearch, Imported,
verbose_name=_("Need update"), default=False)
locked = models.BooleanField(
verbose_name=_("Item locked for edition"), default=False)
+ lock_user = models.ForeignKey(
+ User, related_name='+', on_delete=models.SET_NULL,
+ verbose_name=_("Locked by"), blank=True, null=True)
ALT_NAMES = {
'history_creator': SearchAltName(
diff --git a/ishtar_common/templates/ishtar/sheet.html b/ishtar_common/templates/ishtar/sheet.html
index 0dda760b8..5676a4419 100644
--- a/ishtar_common/templates/ishtar/sheet.html
+++ b/ishtar_common/templates/ishtar/sheet.html
@@ -119,6 +119,16 @@
{% endblock %}
{% endif %}
<div class="body">
+ {% if item.locked %}
+ <div class="alert alert-warning" role="alert">
+ <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 %}
+ </div>
+ {% endif %}
{% block content %}
{% endblock %}
</div>
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py
index 610c5d017..86a1978de 100644
--- a/ishtar_common/templatetags/link_to_window.py
+++ b/ishtar_common/templatetags/link_to_window.py
@@ -12,11 +12,14 @@ register = Library()
def simple_link_to_window(item):
if not hasattr(item, 'SLUG'):
return ""
+ lock = ""
+ if getattr(item, "locked", None):
+ lock = '&nbsp;<i class="fa fa-lock text-danger" aria-hidden="true"></i>'
return mark_safe(
u' <a class="display_details" href="#" '
u'onclick="load_window(\'{}\')">'
- u'<i class="fa fa-info-circle" aria-hidden="true"></i></a>'.format(
- reverse("show-" + item.SLUG, args=[item.pk, ''])))
+ u'<i class="fa fa-info-circle" aria-hidden="true"></i>{}</a>'.format(
+ reverse("show-" + item.SLUG, args=[item.pk, '']), lock))
@register.filter
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 62aff2e81..2c4cc1a55 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1146,6 +1146,8 @@ def _get_data_from_query(items, query_table_cols, extra_request_keys,
items = items.annotate(point_x=exp_x)
items = items.annotate(point_y=exp_y)
values += ['point_x', 'point_y']
+ if hasattr(items.model, "locked"):
+ values.append("locked")
data_list = items.values_list(*values)
return data_list
@@ -1838,17 +1840,22 @@ def get_item(model, func_name, default_name, extra_request_keys=None,
if sign == '-':
datas = reversed(datas)
datas = list(datas)[start:end]
- link_template = "<a class='display_details' href='#' " \
- "onclick='load_window(\"%s\")'>" \
- "<i class=\"fa fa-info-circle\" aria-hidden=\"true\"></i></a>"
- link_ext_template = '<a href="{}" target="_blank">{}</a>'
+ link_template = \
+ "<a class='display_details' href='#' " \
+ "onclick='load_window(\"{}\")'>" \
+ "<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>'
+ has_locks = hasattr(model, "locked")
if data_type.startswith("json"):
rows = []
if data_type == 'json-map':
-
- lnk = link_template % reverse('show-' + default_name,
- args=[999999, ''])
+ lnk = link_template.format(
+ reverse('show-' + default_name, args=[999999, '']),
+ )
lnk = lnk.replace('999999', "<pk>")
+ if not has_locks:
+ lnk = lnk.replace('<lock>', "")
data = json.dumps(_format_geojson(datas, lnk))
return HttpResponse(data, content_type='application/json')
for data in datas:
@@ -1858,8 +1865,12 @@ def get_item(model, func_name, default_name, extra_request_keys=None,
if not no_link:
try:
lnk_template = link_template
- lnk = lnk_template % reverse('show-' + default_name,
- args=[data[0], ''])
+ lnk = lnk_template.format(
+ reverse('show-' + default_name, args=[data[0], '']))
+ if has_locks and data[-1]:
+ lnk = lnk.replace('<lock>', lock)
+ else:
+ lnk = lnk.replace('<lock>', "")
except NoReverseMatch:
logger.warning(
'**WARN "show-' + default_name + '" args ('
@@ -1867,7 +1878,7 @@ def get_item(model, func_name, default_name, extra_request_keys=None,
lnk = ''
res["link"] = lnk
for idx, value in enumerate(data[1:]):
- if not value:
+ if not value or idx >= len(table_cols):
continue
table_col = table_cols[idx]
if type(table_col) not in (list, tuple):