summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models.py4
-rw-r--r--ishtar_common/models_common.py4
-rw-r--r--ishtar_common/templates/ishtar/blocks/api_document_list.html4
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_document_list.html53
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_geographic.html16
-rw-r--r--ishtar_common/templates/ishtar/sheet_area.html7
-rw-r--r--ishtar_common/templates/ishtar/sheet_document.html2
-rw-r--r--ishtar_common/templates/ishtar/sheet_town.html7
-rw-r--r--ishtar_common/templatetags/ishtar_helpers.py12
-rw-r--r--ishtar_common/templatetags/link_to_window.py2
-rw-r--r--ishtar_common/urls.py7
-rw-r--r--ishtar_common/views.py55
-rw-r--r--ishtar_common/views_item.py1
13 files changed, 156 insertions, 18 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index ae0656c6d..6a793e326 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2480,6 +2480,10 @@ class Area(HierarchicalType, DocumentItem, MainItem):
return self.label
return "{} ({})".format(self.label, self.reference)
+ def can_edit(self, request):
+ print("TODO: define specific permissions for areas")
+ return False
+
@classmethod
def get_or_create_by_towns(cls, towns, get_geo=False):
if hasattr(towns, "all"): # queryset
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index 0b1be5313..8f6ff5338 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -3605,6 +3605,10 @@ class Town(GeographicItem, Imported, DocumentItem, MainItem, models.Model):
def history_compress(self):
return {"numero_insee": self.numero_insee, "year": self.year or ""}
+ def can_edit(self, request):
+ print("TODO: define specific permissions for towns")
+ return False
+
@classmethod
def get_documentation_string(cls):
"""
diff --git a/ishtar_common/templates/ishtar/blocks/api_document_list.html b/ishtar_common/templates/ishtar/blocks/api_document_list.html
index 251885a19..2b2380496 100644
--- a/ishtar_common/templates/ishtar/blocks/api_document_list.html
+++ b/ishtar_common/templates/ishtar/blocks/api_document_list.html
@@ -2,7 +2,9 @@
id="{{window_id}}-docs-table">
{% for values in item.documents_list %}{% if not forloop.counter0 %}
<thead>
- {% for value in values %}<th class="text-center">{{value}}</th>{% endfor %}
+ <tr>
+ {% for value in values %}<th class="text-center">{{value}}</th>{% endfor %}
+ </tr>
</thead>
{% else %}
<tr>
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_document_list.html b/ishtar_common/templates/ishtar/blocks/sheet_document_list.html
new file mode 100644
index 000000000..1a1849636
--- /dev/null
+++ b/ishtar_common/templates/ishtar/blocks/sheet_document_list.html
@@ -0,0 +1,53 @@
+{% load i18n l10n ishtar_helpers link_to_window %}
+ {% with can_edit_current_item=item|can_edit_item:request %}
+ <h3>{% trans "Associated documents" %}</h3>
+ {% if item.documents.count %}
+ <table class='table table-striped datatables'
+ id="{{window_id}}-docs-table">
+ {% for doc in item.documents.all %}{% if not forloop.counter0 %}
+ <thead>
+ <tr>
+ <th>&nbsp;</th>
+ <th>{% trans "Title" %}</th>
+ <th>{% trans "Type" %}</th>
+ <th>{% trans "Authors" %}</th>
+ <th>{% trans "Numerical ressource" %}</th>
+ {% if not IS_HISTORY and permission_change_document %}<th>&nbsp;</th>{% endif %}
+ {% if not IS_HISTORY and permission_change_item %}<th>&nbsp;</th>{% endif %}
+ </tr>
+ </thead>
+ {% endif %}
+ <tr>
+ <td>
+ <a class="display_details" href="#" onclick="load_window('{% url 'show-document' doc.id '' %}')"><i class="fa fa-info-circle" aria-hidden="true"></i></a>
+ </td>
+ <td>
+ {{doc.title|default:'-'}}
+ </td>
+ <td>
+ {{doc.source_type|default:'-'}}
+ </td>
+ <td>
+ {{doc.authors_list|default:'-'}}
+ </td>
+ <td>{% if doc.associated_url %}
+ <a href='{{doc.associated_url}}' target="_blank">{% trans "Link" %} <i class="fa fa-external-link" aria-hidden="true"></i></a>
+ {% else%}-{% endif %}
+ </td>
+ {% if not IS_HISTORY and permission_change_document %}<td>
+ {% autoescape off %}{% if doc|can_edit_item:request %}
+ <a class="btn btn-success btn-sm" title="{% trans 'Edit' %}" href="{% url 'edit-document' doc.pk %}"><i class="fa fa-pencil"></i></a>
+ {% else %}&ndash;{% endif %}{% endautoescape %}
+ </td>{% endif %}
+ {% if not IS_HISTORY and permission_change_item %}<td>
+ {% autoescape off %}
+ <a class="btn-qa btn btn-danger btn-sm wait-button" title="{% trans 'Unlink' %}" href="#" data-target='{% url 'document-qa-unlink' doc.pk model_slug item.pk %}'><i class="fa fa-chain-broken" aria-hidden="true"></i></a>
+ {% endautoescape %}
+ </td>{% endif %}
+ </tr>
+ {% endfor %}
+ </table>
+ {% elif item.documents_list %}
+ {% include "ishtar/blocks/api_document_list.html" %}
+ {% endif %}
+ {% endwith %}
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
index 12846ef78..6212c9573 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_geographic.html
@@ -2,7 +2,6 @@
{% with search_url=item.get_search_url %}
<table id='{{window_id}}-geographic-data' class="table table-striped">
<tr>
- {% if not IS_HISTORY and permission_change_geo %}<th>&nbsp;</th>{% endif %}
<th>{% trans "Main" %}</th>
<th>{% trans "Data type" %}</th>
<th>{% trans "Source" %}</th>
@@ -13,14 +12,10 @@
<th>{% trans "Acquisition date" %}</th>
<th>{% trans "Comment" %}</th>
{% if not IS_HISTORY and permission_change_geo %}<th>&nbsp;</th>{% endif %}
+ {% if not IS_HISTORY and permission_change_geo %}<th>&nbsp;</th>{% endif %}
</tr>
{% for geo in geo_item.geodata.all %}
<tr>
- {% if not IS_HISTORY and permission_change_geo %}<td>
- {% autoescape off %}
- <a title="{% trans 'Edit' %}" href="{% url 'edit-geo' geo.pk %}{% if search_url or find_id %}?{% endif %}{% if find_id %}find_id={{find_id|unlocalize}}&{% endif %}{% if search_url %}back_url={{search_url}}%3Fopen_item={{geo_item.pk|unlocalize}}{% endif %}">{% if geo|can_edit_item:request %}<i class="fa fa-pencil"></i></a>{% else %}&ndash;{% endif %}
- {% endautoescape %}
- </td>{% endif %}
<td>{% if geo.id == geo_item.main_geodata_id %}<i class="fa fa-check-circle text-success" aria-hidden="true"></i>{% else %}&ndash;{% endif %}</td>
<td>{% if geo.data_type %}{{ geo.data_type }}{% else %}-{% endif %}</td>
<td>{{ geo.source_label }}</td>
@@ -30,11 +25,16 @@
<td>{% if geo.provider %}{{ geo.provider }}{% else %}-{% endif %}</td>
<td>{% if geo.acquisition_date %}{{ geo.acquisition_date|date:"DATE_FORMAT"|default:"-" }}{% else %}-{% endif %}</td>
<td>{% if geo.comment %}{{ geo.comment }}{% else %}-{% endif %}</td>
+ {% if not IS_HISTORY and permission_change_geo %}<td>
+ {% autoescape off %}
+ {% if geo|can_edit_item:request %}<a class="btn btn-success btn-sm" title="{% trans 'Edit' %}" href="{% url 'edit-geo' geo.pk %}{% if search_url or find_id %}?{% endif %}{% if find_id %}find_id={{find_id|unlocalize}}&{% endif %}{% if search_url %}back_url={{search_url}}%3Fopen_item={{geo_item.pk|unlocalize}}{% endif %}"><i class="fa fa-pencil"></i></a>{% else %}&ndash;{% endif %}
+ {% endautoescape %}
+ </td>{% endif %}
{% if not IS_HISTORY and permission_change_geo and output != "ODT" and output != "PDF" %}<td>
{% autoescape off %}
- <a title="{% trans 'Delete' %}"
+ {% if geo|can_edit_item:request %}<a class="btn btn-danger btn-sm" title="{% trans 'Delete' %}"
href="{% url 'delete-geo' geo.pk %}{% if search_url or find_id %}?{% endif %}{% if find_id %}find_id={{find_id|unlocalize}}&{% endif %}{% if search_url %}back_url={{search_url}}%3Fopen_item={{geo_item.pk|unlocalize}}{% endif %}">
- {% if geo|can_edit_item:request %}<i class="fa fa-trash text-danger"></i></a>{% else %}&ndash;{% endif %}
+ <i class="fa fa-trash"></i></a>{% else %}&ndash;{% endif %}
{% endautoescape %}
</td>{% endif %}
</tr>
diff --git a/ishtar_common/templates/ishtar/sheet_area.html b/ishtar_common/templates/ishtar/sheet_area.html
index c4f67885e..682722dcd 100644
--- a/ishtar_common/templates/ishtar/sheet_area.html
+++ b/ishtar_common/templates/ishtar/sheet_area.html
@@ -92,8 +92,9 @@
{% endcomment %}
{% if display_documents and item.documents.count %}
- {% trans "Documents" as area_docs %}
- {% dynamic_table_document area_docs 'documents' 'areas' item.pk '' output %}
+ {% with permission_change_item=item|can_edit_item:request %}
+ {% include "ishtar/blocks/sheet_document_list.html" %}
+ {% endwith %}
{% endif %}
</div>
@@ -126,4 +127,4 @@ $(document).ready( function () {
{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}
-{% endblock %} \ No newline at end of file
+{% endblock %}
diff --git a/ishtar_common/templates/ishtar/sheet_document.html b/ishtar_common/templates/ishtar/sheet_document.html
index 02c32638b..ca382f137 100644
--- a/ishtar_common/templates/ishtar/sheet_document.html
+++ b/ishtar_common/templates/ishtar/sheet_document.html
@@ -58,7 +58,7 @@
<h4 class="col-12">{% trans "Content" %}</h4>
{% trans "File" context "Not directory" as file_label %}
{% field_flex_file file_label item.associated_file %}
- {% trans "Web link" as weblink_label %}
+ {% trans "Numerical ressource (web address)" as weblink_label %}
{% field_flex_url weblink_label item.associated_url %}
{% field_flex_multiple_obj "Tags" item 'tags' %}
{% endif %}
diff --git a/ishtar_common/templates/ishtar/sheet_town.html b/ishtar_common/templates/ishtar/sheet_town.html
index e92c03b54..235182993 100644
--- a/ishtar_common/templates/ishtar/sheet_town.html
+++ b/ishtar_common/templates/ishtar/sheet_town.html
@@ -116,8 +116,9 @@
{% endif %}
{% if display_documents and item.documents.count %}
- {% trans "Documents" as town_docs %}
- {% dynamic_table_document town_docs 'documents' 'towns' item.pk '' output %}
+ {% with permission_change_item=item|can_edit_item:request %}
+ {% include "ishtar/blocks/sheet_document_list.html" %}
+ {% endwith %}
{% endif %}
{% if perm_files and item.file.count %}
@@ -167,4 +168,4 @@ $(document).ready( function () {
{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}
-{% endblock %} \ No newline at end of file
+{% endblock %}
diff --git a/ishtar_common/templatetags/ishtar_helpers.py b/ishtar_common/templatetags/ishtar_helpers.py
index cfd04a5d7..b668b8f0b 100644
--- a/ishtar_common/templatetags/ishtar_helpers.py
+++ b/ishtar_common/templatetags/ishtar_helpers.py
@@ -114,6 +114,18 @@ def can_edit_item(item, context):
@register.filter
+def can_delete_item(item, context):
+ if hasattr(context, "request"): # WSGIRequest
+ request = context.request
+ elif "request" in context: # RequestContext
+ request = context['request']
+ else:
+ request = context
+ if item.can_delete(request):
+ return True
+
+
+@register.filter
def user_can_do(ishtar_user, permission):
return ishtar_user.user_ptr.has_perm(permission)
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py
index 285d9b1fd..0f857c8c5 100644
--- a/ishtar_common/templatetags/link_to_window.py
+++ b/ishtar_common/templatetags/link_to_window.py
@@ -76,7 +76,7 @@ def add_links(items, extra_attr=''):
lbl = item.fancy_str()
else:
lbl = str(item)
- html.append("{} {}".format(lbl, simple_link_to_window(item_lnk)))
+ html.append("{} {}".format(simple_link_to_window(item_lnk), lbl))
return mark_safe("<br/>".join(html))
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index aa1f1948e..d2c954e58 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -686,6 +686,13 @@ urlpatterns += [
)(views.QADocumentDuplicateFormView.as_view()),
name="document-qa-duplicate",
),
+ path(
+ "document-qa-unlink/<int:pks>/<slug:related_model>-<int:related_id>/",
+ check_permissions(
+ ["ishtar_common.change_document", "ishtar_common.change_own_document"]
+ )(views.QADocumentUnlink.as_view()),
+ name="document-qa-unlink",
+ ),
url(
r"^document-qa-packaging/(?P<pks>[0-9-]+)?/$",
check_permissions(
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 4c83fd818..5f175c186 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -77,6 +77,7 @@ from ishtar_common.models_common import QuickAction
from ishtar_common.templatetags.link_to_window import simple_link_to_window
from ishtar_common.utils_migrations import HOMEPAGE_TITLE
from ishtar_common.utils import (
+ BSMessage,
clean_session_cache,
CSV_OPTIONS,
get_current_item_keys,
@@ -1236,10 +1237,12 @@ ACTION_MODEL_DICT = {
"archaeological_operations", "AdministrativeAct"),
'file': apps.get_model("archaeological_files", "File"),
'site': apps.get_model("archaeological_operations", "ArchaeologicalSite"),
+ 'contextrecord': apps.get_model("archaeological_context_records", "ContextRecord"),
'record': apps.get_model("archaeological_context_records", "ContextRecord"),
'find': apps.get_model("archaeological_finds", "Find"),
'treatment': apps.get_model("archaeological_finds", "Treatment"),
'treatmentfle': apps.get_model("archaeological_finds", "TreatmentFile"),
+ 'treatmentfile': apps.get_model("archaeological_finds", "TreatmentFile"),
'exhibition': apps.get_model("archaeological_finds", "Exhibition"),
'container': apps.get_model("archaeological_warehouse", "Container"),
'warehouse': apps.get_model("archaeological_warehouse", "Warehouse"),
@@ -3160,6 +3163,9 @@ class QAItemForm(IshtarMixin, LoginRequiredMixin, FormView):
action_name = None
permissions = []
+ def get_permissions(self):
+ return self.permissions
+
def get_quick_action(self):
quick_action = self.model.get_quick_action_by_url(self.base_url)
if quick_action:
@@ -3169,7 +3175,7 @@ class QAItemForm(IshtarMixin, LoginRequiredMixin, FormView):
url=self.base_url,
icon_class=self.icon,
text=self.page_name,
- rights=self.permissions
+ rights=self.get_permissions()
)
def pre_dispatch(self, request, *args, **kwargs):
@@ -3401,6 +3407,53 @@ class QADocumentDuplicateFormView(QAItemForm):
return data
+class QADocumentUnlink(QAItemForm):
+ model = models.Document
+ page_name = _("Unlink")
+ form_class = forms.QAForm
+ base_url = "document-qa-unlink"
+ icon = "fa fa-chain-broken"
+ action_name = _("Unlink")
+
+ def pre_dispatch(self, request, *args, **kwargs):
+ related_model = kwargs.get("related_model")
+ # model, related_id
+ if related_model not in ACTION_MODEL_DICT:
+ raise Http404()
+ related_model = ACTION_MODEL_DICT[related_model]
+ related_id = kwargs.get("related_id")
+ try:
+ self.related_item = related_model.objects.get(pk=related_id)
+ except related_model.DoesNotExist:
+ raise Http404()
+ return super().pre_dispatch(request, *args, **kwargs)
+
+ def get_permissions(self):
+ rel_meta = self.related_item.__class__._meta
+ return [
+ f"{rel_meta.app_label}.change_{rel_meta.model_name}",
+ f"{rel_meta.app_label}.change_own_{rel_meta.model_name}",
+ ]
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["confirm"] = True
+ return kwargs
+
+ def form_valid(self, form):
+ self.related_item.documents.remove(self.items[0])
+ return HttpResponseRedirect(reverse("success"))
+
+ def get_context_data(self, **kwargs):
+ data = super().get_context_data(**kwargs)
+ data["messages"] = [
+ BSMessage(
+ str(_('Unlink document "{}" from this item.')).format(self.items[0]),
+ "info", "", no_dismiss=True)
+ ]
+ return data
+
+
class QADocumentPackagingFormView(QAItemForm):
template_name = "ishtar/forms/qa_document_packaging.html"
model = models.Document
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 9ee5b9040..080a6600b 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -530,6 +530,7 @@ def show_item(model, name, extra_dct=None, model_for_perms=None, callback=None):
if current_language not in PUNCTUATION:
current_language = "en"
dct["PUNCTUATION"] = PUNCTUATION[current_language]
+ dct["model_slug"] = model.SLUG
dct["current_window_url"] = url_name
date = None
if "date" in dct: