diff options
| -rw-r--r-- | archaeological_context_records/forms.py | 69 | ||||
| -rw-r--r-- | archaeological_context_records/models.py | 2 | ||||
| -rw-r--r-- | archaeological_context_records/templates/ishtar/sheet_contextrecord.html | 11 | ||||
| -rw-r--r-- | archaeological_context_records/urls.py | 8 | ||||
| -rw-r--r-- | archaeological_context_records/views.py | 41 | ||||
| -rw-r--r-- | archaeological_finds/templates/ishtar/sheet_find.html | 9 | ||||
| -rw-r--r-- | archaeological_finds/urls.py | 8 | ||||
| -rw-r--r-- | archaeological_finds/views.py | 4 | ||||
| -rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_dating_list.html | 22 |
9 files changed, 140 insertions, 34 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index df074c768..9f7dfa0b4 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -43,7 +43,6 @@ from archaeological_context_records import models from ishtar_common.forms import ( FinalForm, - FormSet, reverse_lazy, get_form_selection, ManageOldType, @@ -512,28 +511,6 @@ class RecordFormGeneral(CustomForm, ManageOldType): return cleaned_data -class DatingForm(ManageOldType, forms.Form): - form_label = _("Dating") - base_model = "dating" - associated_models = { - "dating_type": models.DatingType, - "quality": models.DatingQuality, - "period": models.Period, - } - period = forms.ChoiceField(label=_("Chronological period"), choices=[]) - start_date = forms.IntegerField(label=_("Start date"), required=False) - end_date = forms.IntegerField(label=_("End date"), required=False) - quality = forms.ChoiceField(label=_("Quality"), required=False, choices=[]) - dating_type = forms.ChoiceField(label=_("Dating type"), required=False, choices=[]) - precise_dating = forms.CharField(label=_("Precise on this dating"), required=False) - - TYPES = [ - FieldType("dating_type", models.DatingType), - FieldType("quality", models.DatingQuality), - FieldType("period", models.Period), - ] - - class RecordFormInterpretation(CustomForm, ManageOldType): HEADERS = {} form_label = _("Interpretation") @@ -921,3 +898,49 @@ class QAContextRecordFormMulti(QAForm): def _set_qa_relation_type(self, item, __): pass + + +class QADating(ManageOldType, forms.Form): + form_label = _("Dating") + associated_models = { + "dating_type_id": models.DatingType, + "quality_id": models.DatingQuality, + "period_id": models.Period, + } + pk = forms.IntegerField(required=False, widget=forms.HiddenInput) + reference = forms.CharField( + label=_("Reference"), validators=[validators.MaxLengthValidator(400)], + required=False + ) + period_id = forms.ChoiceField(label=_("Chronological period"), choices=[], + required=False) + start_date = forms.IntegerField(label=_("Start date"), required=False) + end_date = forms.IntegerField(label=_("End date"), required=False) + quality_id = forms.ChoiceField(label=_("Quality"), required=False, choices=[]) + dating_type_id = forms.ChoiceField(label=_("Dating type"), required=False, choices=[]) + precise_dating = forms.CharField(label=_("Precise on this dating"), required=False, + widget=forms.Textarea) + + TYPES = [ + FieldType("dating_type_id", models.DatingType), + FieldType("quality_id", models.DatingQuality), + FieldType("period_id", models.Period), + ] + + def clean(self): + cleaned_data = self.cleaned_data + if any(1 for k in self.cleaned_data if self.cleaned_data[k]): + return cleaned_data + raise forms.ValidationError(_("No data provided.")) + + def save(self, model, item): + data = copy(self.cleaned_data) + data[model.CURRENT_MODEL_ATTR + "_id"] = item.pk + for attr in ['period_id', 'quality_id', 'dating_type_id']: + if not data.get(attr, None): + data[attr] = None + if data.get("pk", None): + pk = data.pop("pk") + model.objects.filter(pk=pk).update(**data) + return + model.objects.create(**data) diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 0c8a18f43..63e6a773d 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -1376,7 +1376,7 @@ class ContextRecord( return self.full_label() def _generate_cached_periods(self): - return " & ".join(dating.period.label for dating in self.datings.all()) + return " & ".join(period.label for period in self.periods.all()) def _generate_cached_related_context_records(self): return self.detailed_related_context_records() diff --git a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html index 869d6edd5..bd766f9f6 100644 --- a/archaeological_context_records/templates/ishtar/sheet_contextrecord.html +++ b/archaeological_context_records/templates/ishtar/sheet_contextrecord.html @@ -28,6 +28,7 @@ {% with display_interpretation=item|safe_or:"identifications.count"|or_:item.interpretation|or_:item.activity %} {% with display_datations=dating_list|or_:item.taq|or_:item.taq_estimated|or_:item.tpq|or_:item.tpq_estimated|or_:has_cultural_attributions %} {% with can_view_finds=permission_view_own_find|or_:permission_view_find %} +{% with can_change=permission_change_own_find|or_:permission_change_find %} {% with has_finds=item|safe_or:"base_finds.count"|safe_and_not:"base_finds_not_available" %} {% with display_finds=has_finds|and_:can_view_finds %} {% with display_data=item.data %} @@ -50,7 +51,7 @@ </a> </li> {% endif %} - {% if display_datations %} + {% if display_datations or can_change %} <li class="nav-item"> <a class="nav-link" id="{{window_id}}-datations-tab" data-toggle="tab" href="#{{window_id}}-datations" role="tab" @@ -211,14 +212,14 @@ </div> {% endif %} - {% if display_datations %} + {% if display_datations or can_change %} <div class="tab-pane fade" id="{{window_id}}-datations" role="tabpanel" aria-labelledby="{{window_id}}-datations-tab"> - {% if dating_list or item.periods_count %} <h3>{% trans "Periods / Datings" %}</h3> - {% endif %} {% field_flex_multiple_obj _("Periods") item 'periods' %} + {% with url_dating="context-record-dating" %} {% include "ishtar/blocks/sheet_dating_list.html" %} + {% endwith %} {% if item.cultural_attributions_count or item.taq or item.taq_estimated or item.tpq or item.tpq_estimated or datings_comment %} <h3>{% trans "Dating complements" %}</h3> <div class='row'> @@ -370,6 +371,6 @@ {% endif %} </div> -{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} +{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endblock %} diff --git a/archaeological_context_records/urls.py b/archaeological_context_records/urls.py index bb06e9945..ec529deeb 100644 --- a/archaeological_context_records/urls.py +++ b/archaeological_context_records/urls.py @@ -162,6 +162,14 @@ urlpatterns = [ name="context-record-relation-modify", ), re_path( + r"^context-record-dating/(?P<pk>.+)/$", + check_permissions(["archaeological_context_records.change_contextrecord", + "archaeological_context_records.change_own_contextrecord"])( + views.context_record_dating_add + ), + name="context-record-dating-add", + ), + re_path( r"^operation-qa-contextrecord/(?P<pks>[0-9]+)/$", check_permissions(["archaeological_context_records.add_contextrecord"])( views.QAOperationContextRecordView.as_view() diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py index 69f995932..8c222f395 100644 --- a/archaeological_context_records/views.py +++ b/archaeological_context_records/views.py @@ -19,9 +19,10 @@ import json +from django.core.exceptions import PermissionDenied from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect, Http404 -from django.shortcuts import redirect +from django.shortcuts import redirect, render from django.urls import reverse from ishtar_common.utils import gettext_lazy as _ from django.views.generic import RedirectView @@ -194,6 +195,44 @@ context_record_modify_relations = get_relation_modify( ) +def get_dating_form(model, dating_model, url_name, action='add'): + def _dating_add(request, pk, current_right=None): + try: + item = model.objects.get(pk=pk) + except model.DoesNotExist: + raise Http404() + if "_own_" in current_right: + if not request.user.has_perm(current_right, item): + raise PermissionDenied() + elif current_right: + if not request.user.has_perm(current_right): + raise PermissionDenied() + if request.method == 'POST': + form = forms.QADating(request.POST) + if form.is_valid(): + form.save(dating_model, item) + return redirect(reverse(url_name, args=[pk])) + else: + form = forms.QADating() + button_name = _("Add") if action == "add" else _("Modify") + icon = "fa fa-plus" if action == "add" else "fa fa-pencil" + return render( + request, + "ishtar/forms/qa_form.html", { + "page_name": _("Dating"), + "icon": icon, + "action_name": button_name, + "form": form, + "url": reverse(url_name, args=[pk]) + }) + return _dating_add + + +context_record_dating_add = get_dating_form( + models.ContextRecord, models.ContextRecordDating, "context-record-dating-add" +) + + class GenerateRelationImage(IshtarMixin, LoginRequiredMixin, RedirectView): upper_model = models.Operation model = models.ContextRecord diff --git a/archaeological_finds/templates/ishtar/sheet_find.html b/archaeological_finds/templates/ishtar/sheet_find.html index 34c442542..c460cd579 100644 --- a/archaeological_finds/templates/ishtar/sheet_find.html +++ b/archaeological_finds/templates/ishtar/sheet_find.html @@ -29,6 +29,7 @@ {% with can_view_container=permission_view_own_container|or_:permission_view_container %} {% with display_warehouse_treatments=item.container|or_:item.container_ref|or_:item.upstream_treatment|or_:item.downstream_treatment|or_:non_modif_treatments_count|or_:associated_treatment_files_count %} {% with can_view_documents=permission_view_own_document|or_:permission_view_document %} +{% with can_change=permission_change_own_find|or_:permission_change_find %} {% with has_documents=item|safe_or:"documents.count|documents_list"|safe_and_not:"documents_not_available" %} {% with display_documents=can_view_documents|and_:has_documents %} {% with has_image=item.images_number %} @@ -252,7 +253,7 @@ {% endif %} {% with dating_list=item|m2m_listing:"datings" %} - {% if dating_list or item.dating_comment or item.cultural_attributions_count or item.periods_count %} + {% if can_change or dating_list or item.dating_comment or item.cultural_attributions_count or item.periods_count %} <h3>{% trans "Periods / Datings" %}</h3> {% if item.cultural_attributions_count or item.periods_count %} <div class='row'> @@ -260,8 +261,10 @@ {% field_flex_multiple_obj "Cultural attributions" item 'cultural_attributions' %} </div> {% endif %} - {% if dating_list %} + {% if can_change or dating_list %} + {% with url_dating="context-record-dating" %} {% include "ishtar/blocks/sheet_dating_list.html" %} + {% endwith %} {% endif %} <div class='row'> {% field_flex_full "Comment on dating" item.dating_comment "<pre>" "</pre>" %} @@ -321,7 +324,7 @@ {% endif %} </div> -{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %} +{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %}{% endwith %} {% endwith %} {% endblock %} diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py index a690b8698..f36157c75 100644 --- a/archaeological_finds/urls.py +++ b/archaeological_finds/urls.py @@ -75,6 +75,14 @@ urlpatterns = [ )(views.QAFindDuplicateFormView.as_view()), name="find-qa-duplicate", ), + re_path( + r"^find-dating/(?P<pk>.+)/$", + check_permissions(["archaeological_finds.change_find", + "archaeological_finds.change_own_find"])( + views.find_dating_add + ), + name="find-dating-add", + ), re_path(r"get-findbasket/$", views.get_find_basket, name="get-findbasket"), re_path( r"get-findbasket-write/$", diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index 6b612af43..0e9d46c16 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -61,6 +61,7 @@ from ishtar_common.views_item import ( get_autocomplete_queries, get_autocomplete_query ) +from archaeological_context_records.views import get_dating_form from archaeological_operations.wizards import AdministrativeActDeletionWizard from archaeological_finds import wizards @@ -1426,6 +1427,9 @@ class QAFindLockView(QABaseLockView): base_url = "find-qa-lock" +find_dating_add = get_dating_form(models.Find, models.FindDating, "find-dating-add") + + def get_geo_items(request, current_right=None): operation_pk = request.GET.get("operation_id") context_record_pk = request.GET.get("context_record_id") diff --git a/ishtar_common/templates/ishtar/blocks/sheet_dating_list.html b/ishtar_common/templates/ishtar/blocks/sheet_dating_list.html index e79d9f201..f4ec6c33a 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_dating_list.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_dating_list.html @@ -8,6 +8,7 @@ <th>{% trans "Dating type" %}</th> <th>{% trans "Quality" %}</th> <th>{% trans "Precise on this dating" %}</th> + {% if can_change %}<th colspan='2'></th>{% endif %} </tr> {% for dating in dating_list %} <tr> @@ -32,6 +33,25 @@ <td> {{dating.precise_dating|default_if_none:"-"}} </td> + {% if can_change %} + <td> + <a class="btn btn-success btn-sm" title="Modifier" href="/geo/edit/37130/?find_id=94034&back_url=/find_search/%3Fopen_item=46434"><i class="fa fa-pencil"></i></a> + </td> + <td> + <a class="btn btn-danger btn-sm" title="Supprimer" href="/geo/delete/37130/?find_id=94034&back_url=/find_search/%3Fopen_item=46434"> + <i class="fa fa-trash"></i></a> + + </td> + {% endif %} </tr> - {% endfor %} + {% empty %}<tr> + <td colspan='9'>{% trans "No datation attached." %}</td> + </tr>{% endfor %} </table> +{% if can_change %}<div class="text-center mb-2"> + <a class="btn btn-qa btn-success" href="#" + data-target="{% url url_dating|add:'-add' item.pk %}"> + <i class="fa fa-plus"></i> {% trans "dating" %} + </a> +</div> +{% endif %} |
