summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-12-01 09:53:00 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-19 14:45:57 +0100
commit847ae9bab5afbc2d62fa6e4b1e751096e74e4c4d (patch)
treead5c77410653a240c1224f3107bb59ffb677ca41 /archaeological_finds
parenteae583cfaddfad42ccffb7e7f09773d00c051d10 (diff)
downloadIshtar-847ae9bab5afbc2d62fa6e4b1e751096e74e4c4d.tar.bz2
Ishtar-847ae9bab5afbc2d62fa6e4b1e751096e74e4c4d.zip
✨ exhibitions: "GAM" export
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models_treatments.py37
-rw-r--r--archaeological_finds/templates/ishtar/forms/qa_gam_result.html9
-rw-r--r--archaeological_finds/templates/ishtar/sheet_exhibition.html15
-rw-r--r--archaeological_finds/urls.py22
-rw-r--r--archaeological_finds/views.py56
5 files changed, 113 insertions, 26 deletions
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index d687199db..ce9066fc7 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -18,6 +18,12 @@
# See the file COPYING for details.
import datetime
+import lxml.etree
+import lxml.builder
+import os
+import shutil
+import tempfile
+import zipfile
from django.conf import settings
from django.contrib.gis.db import models
@@ -1379,6 +1385,36 @@ class TreatmentFile(
def natural_key(self):
return (self.year, self.index)
+ def is_gam_exportable(self):
+ self.gam_errors = []
+ is_ok = True
+ return is_ok
+
+ def gam_export(self):
+ filename = f"export_gam-{self.exhibition_start_date.year}-{slugify(self.name).replace('-', '_')}.zip"
+ maker = lxml.builder.ElementMaker()
+ document = maker.proposition(
+ maker.action("CREATION"),
+ maker.categorie("PRET"),
+ )
+ content = b'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'
+ content += lxml.etree.tostring(document, pretty_print=True)
+ gam_dir = os.path.join(settings.MEDIA_ROOT, "GAM")
+ if not os.path.exists(gam_dir):
+ os.mkdir(gam_dir)
+ media_dir = os.path.join("GAM", str(datetime.date.today().year))
+ full_media_dir = os.path.join(settings.MEDIA_ROOT, media_dir)
+ if not os.path.exists(full_media_dir):
+ os.mkdir(full_media_dir)
+ final_name = os.path.join(full_media_dir, filename)
+ with tempfile.TemporaryDirectory() as tmp_dir_name:
+ new_file = os.path.join(tmp_dir_name, filename)
+ with zipfile.ZipFile(
+ new_file, mode="a", compression=zipfile.ZIP_DEFLATED) as zf:
+ zf.writestr("pret.xml", content)
+ shutil.move(new_file, final_name)
+ return f"{settings.MEDIA_URL}{media_dir}/{filename}"
+
@property
def short_class_name(self):
return _("Treatment request")
@@ -1598,7 +1634,6 @@ class Exhibition(
request, "archaeological_finds.add_treatmentfile"
)
if can_add_tf:
-
actions += [
(
reverse("exhibition-qa-add-loan", args=[self.pk]),
diff --git a/archaeological_finds/templates/ishtar/forms/qa_gam_result.html b/archaeological_finds/templates/ishtar/forms/qa_gam_result.html
new file mode 100644
index 000000000..15ad6e356
--- /dev/null
+++ b/archaeological_finds/templates/ishtar/forms/qa_gam_result.html
@@ -0,0 +1,9 @@
+{% extends "ishtar/forms/qa_form.html" %}
+{% load i18n inline_formset table_form %}
+{% block main_form %}
+<div class="text-center">
+ <a class="btn btn-success" href="{{gam_file}}" title="Fichier GAM" target="_blank">
+ <i class="fa fa-share-square-o"></i>&nbsp;&nbsp;Fichier GAM
+ </a>
+</div>
+{% endblock %}
diff --git a/archaeological_finds/templates/ishtar/sheet_exhibition.html b/archaeological_finds/templates/ishtar/sheet_exhibition.html
index cd37bac4b..71cad264a 100644
--- a/archaeological_finds/templates/ishtar/sheet_exhibition.html
+++ b/archaeological_finds/templates/ishtar/sheet_exhibition.html
@@ -98,13 +98,20 @@
{% for loan in item.treatment_files.all %}
<div class="tab-pane fade" id="{{window_id}}-loan{{forloop.counter}}"
role="tabpanel" aria-labelledby="{{window_id}}-loan{{forloop.counter}}-tab">
+ {% if ISHTAR_MUSEUM_GAM %}
+ <div class="row">
+ <p class="col-12 text-center m-3">
+ <a class="btn-qa btn btn-success" href="#" data-target="{% url 'exhibition-qa-gam-export' loan.pk %}" title="Export GAM">
+ <i class="fa fa-share-square-o"></i>&nbsp;&nbsp;export GAM
+ </a>
+ </p>
+ </div>
+ {% endif %}
<div class="row">
- {% with loan.exhibition_start_date|date:"SHORT_DATE_FORMAT" as exhibition_start_date %}
<dl class="col-12 col-md-6 col-lg-3 flex-wrap">
<dt>{% trans "Dates" %}</dt>
<dd>{{loan.exhibition_start_date|date:"SHORT_DATE_FORMAT"}} / {{loan.exhibition_end_date|date:"SHORT_DATE_FORMAT"}}</dd>
</dl>
- {% endwith %}
{% field_flex_detail _("Beneficiary of the loan") loan.applicant_organisation %}
{% field_flex_detail _("Scientific manager of the exhibition") loan.in_charge %}
{% field_flex_detail _("Exhibition location") loan.exhibition_location %}
@@ -116,8 +123,8 @@
{% if perm_change_basket %}
<p class="col-12 col-md-6 col-lg-3 flex-wrap">
- <a class="wait-button btn btn-success" href="/find_basket_modification_add/{{loan.associated_basket.pk}}/?back_url={% url 'display-exhibition' loan.pk %}" title="{% trans 'Manage basket' %}">
- <i class="fa fa-shopping-basket"></i>&nbsp; {% trans "manage items of this basket" %}
+ <a class="wait-button btn btn-success" href="/find_basket_modification_add/{{loan.associated_basket.pk}}/?back_url={% url 'display-exhibition' loan.pk %}" title="{% trans 'Manage basket' %}">
+ <i class="fa fa-shopping-basket"></i>&nbsp; {% trans "manage items of this basket" %}
</a>
</p>
{% endif %}
diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py
index 8ddea481d..b99140e00 100644
--- a/archaeological_finds/urls.py
+++ b/archaeological_finds/urls.py
@@ -451,13 +451,6 @@ urlpatterns = [
name="exhibition-create",
),
path(
- "exhibition/qa/add-loan/<int:pks>/",
- check_permissions(
- ["archaeological_finds.add_treatmentfile"]
- )(views.QAExhibitionLoanFormView.as_view()),
- name="exhibition-qa-add-loan",
- ),
- path(
"exhibition/modify/<int:pk>/",
check_permissions(
["archaeological_finds.change_exhibition",
@@ -481,6 +474,21 @@ urlpatterns = [
name="exhibition-revert"
),
path(
+ "exhibition/qa/add-loan/<int:pks>/",
+ check_permissions(
+ ["archaeological_finds.add_treatmentfile"]
+ )(views.QAExhibitionLoanFormView.as_view()),
+ name="exhibition-qa-add-loan",
+ ),
+ path(
+ "exhibition/qa/gam-export/<int:pk>/",
+ check_permissions(
+ ["archaeological_finds.view_treatmentfile",
+ "archaeological_finds.view_own_treatmentfile"]
+ )(views.qa_gam_export_views),
+ name="exhibition-qa-gam-export",
+ ),
+ path(
"exhibition/<step>/",
check_permissions(
["archaeological_finds.view_exhibition",
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 11509f4aa..7fdc83197 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -24,14 +24,14 @@ from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import HttpResponseRedirect, HttpResponse, Http404
-from django.shortcuts import redirect
+from django.shortcuts import redirect, render
from django.urls import reverse
from ishtar_common.utils import ugettext_lazy as _, BSMessage
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView, FormView, UpdateView
-from ishtar_common.models import get_current_profile, IshtarUser, QuickAction
+from ishtar_common.models import get_current_profile, IshtarUser
from archaeological_operations.models import AdministrativeAct, Operation
from archaeological_context_records.models import ContextRecord
from archaeological_finds import models
@@ -143,7 +143,13 @@ get_treatmentfile = get_item(
search_form=forms.TreatmentFileSelect,
)
-show_exhibition = show_item(models.Exhibition, "exhibition")
+
+def show_exhibition_extra(request, exhibition):
+ return {"ISHTAR_MUSEUM_GAM": settings.ISHTAR_MUSEUM_GAM}
+
+
+show_exhibition = show_item(models.Exhibition, "exhibition",
+ extra_dct=show_exhibition_extra)
revert_exhibition = revert_item(models.Exhibition)
get_exhibition = get_item(
models.Exhibition, "get_exhibition", "exhibition",
@@ -1410,16 +1416,7 @@ class QAExhibitionLoanFormView(QAItemForm):
base_url = "exhibition-qa-add-loan"
icon = "fa fa-plus"
action_name = _("Create")
-
- def get_quick_action(self):
- return QuickAction(
- url=self.base_url,
- icon_class=self.icon,
- text=self.page_name,
- rights=[
- "archaeological_finds.add_treatmentfile",
- ],
- )
+ permisssions = ["archaeological_finds.add_treatmentfile"]
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
@@ -1431,7 +1428,7 @@ class QAExhibitionLoanFormView(QAItemForm):
if not self.items[0].associated_basket_id:
data["messages"] = [
BSMessage(
- _("No basket associted to the exhibition."),
+ _("No basket associated to the exhibition."),
"danger", "fa fa-exclamation-triangle")
]
return data
@@ -1439,3 +1436,34 @@ class QAExhibitionLoanFormView(QAItemForm):
def form_valid(self, form):
form.save()
return HttpResponseRedirect(reverse("success"))
+
+
+def qa_gam_export_views(request, pk, *args, **kwargs):
+ # TODO: verify treatement file own view
+ try:
+ loan = models.TreatmentFile.objects.get(pk=pk)
+ except models.TreatmentFile.DoesNotExist:
+ raise Http404()
+ dct = {
+ "loan": loan,
+ "page_name": "Export GAM",
+ "url": reverse("exhibition-qa-gam-export", args=[pk]),
+ "icon": "fa fa-share-square-o",
+ "action_name": "Export GAM",
+ "cancel_name": _("Close")
+ }
+ if request.POST:
+ dct["gam_file"] = loan.gam_export()
+ dct["unavailable"] = True
+ return render(request, "ishtar/forms/qa_gam_result.html", dct)
+ if loan.is_gam_exportable():
+ dct["messages"] = [
+ BSMessage("Prêt OK pour export GAM", "info", no_dismiss=True)
+ ]
+ else:
+ dct["messages"] = [
+ BSMessage(error, "danger", no_dismiss=True)
+ for error in loan.gam_errors
+ ]
+ dct["unavailable"] = True
+ return render(request, "ishtar/forms/qa_form.html", dct)