summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-04-24 17:30:07 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-04-24 17:32:01 +0200
commit2b2935ccf265216a33345c2fd953c205ce143827 (patch)
tree5a5f5b3a1bccbc4c738108d50ae396718819af20
parentf2cd1c1326d5fbfbd39a7b2a30a278dd66883c3c (diff)
downloadIshtar-2b2935ccf265216a33345c2fd953c205ce143827.tar.bz2
Ishtar-2b2935ccf265216a33345c2fd953c205ce143827.zip
Sheet area
-rw-r--r--ishtar_common/models.py9
-rw-r--r--ishtar_common/templates/ishtar/sheet_area.html129
-rw-r--r--ishtar_common/templates/ishtar/sheet_area_pdf.html14
-rw-r--r--ishtar_common/templates/ishtar/sheet_area_window.html3
-rw-r--r--ishtar_common/templates/ishtar/sheet_town.html23
-rw-r--r--ishtar_common/templatetags/link_to_window.py4
-rw-r--r--ishtar_common/urls.py5
-rw-r--r--ishtar_common/views.py1
8 files changed, 176 insertions, 12 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 1045adbe5..3e5b44d8a 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -2341,7 +2341,7 @@ class DocumentTemplate(models.Model):
return output_name
-class Area(HierarchicalType, DocumentItem):
+class Area(HierarchicalType, DocumentItem, MainItem):
SLUG = "area"
towns = models.ManyToManyField(
Town, verbose_name=_("Towns"), blank=True, related_name="areas"
@@ -2450,8 +2450,13 @@ class Area(HierarchicalType, DocumentItem):
def _get_base_image_path(self):
return self.SLUG
+ @property
+ def associated_filename(self):
+ value = self.reference if self.reference else self.name
+ return slugify(value)
+
-#m2m_changed.connect(document_attached_changed, sender=Area.documents.through)
+m2m_changed.connect(document_attached_changed, sender=Area.documents.through)
GENDER = (
diff --git a/ishtar_common/templates/ishtar/sheet_area.html b/ishtar_common/templates/ishtar/sheet_area.html
new file mode 100644
index 000000000..8c343f9aa
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_area.html
@@ -0,0 +1,129 @@
+{% extends "ishtar/sheet.html" %}
+{% load i18n ishtar_helpers window_tables window_header window_field from_dict link_to_window %}
+
+{% block head_title %}<strong>{% trans "Area" %}</strong> - {{item.name}}{% if item.reference %} ({{item.reference}}){% endif %}{% endblock %}
+
+{% block toolbar %}
+{% window_nav item window_id 'show-area' %}
+{% endblock %}
+
+{% block content %}
+
+{# trick to set to null non existing variable #}
+{% with permission_view_document=permission_view_document %}
+{% with permission_view_own_document=permission_view_own_document %}
+{% with permission_change_own_geovectordata=permission_change_own_geovectordata %}
+{% with permission_change_geovectordata=permission_change_geovectordata %}
+
+{% with permission_change_geo=permission_change_own_geovectordata|or_:permission_change_geovectordata %}
+
+{% with perm_documents=permission_view_own_document|or_:permission_view_document %}
+{% with has_documents=item|safe_or:"documents.count|documents_list" %}
+{% with display_documents=perm_documents|and_:has_documents %}
+
+{% if output != "ODT" and output != "PDF" %}
+<ul class="nav nav-tabs" id="{{window_id}}-tabs" role="tablist">
+ <li class="nav-item">
+ <a class="nav-link active" id="{{window_id}}-general-tab"
+ data-toggle="tab" href="#{{window_id}}-general" role="tab"
+ aria-controls="{{window_id}}-general" aria-selected="false">
+ {% trans "General" %}
+ </a>
+ </li>
+ {% comment %}
+ TODO: geo for areas
+ {% if not is_external and SHOW_GEO %}
+ <li class="nav-item">
+ <a class="nav-link" id="{{window_id}}-geodata-tab"
+ data-toggle="tab" href="#{{window_id}}-geodata" role="tab"
+ aria-controls="{{window_id}}-geodata" aria-selected="false">
+ {% trans "Geographic data" %}
+ </a>
+ </li>
+ {% endif %}
+ {% endcomment %}
+</ul>
+{% endif %}
+
+<div class="tab-content" id="{{window_id}}-tab-content">
+ <div class="tab-pane fade show active" id="{{window_id}}-general"
+ role="tabpanel" aria-labelledby="{{window_id}}-general-tab">
+
+ <div class="clearfix">
+ <div class="card float-left col-12 col-md-6 col-lg-4">
+ {% include "ishtar/blocks/window_image.html" %}
+ <div class="card-body">
+ <div class="row">
+ <div class="col main text-center">
+ {% if item.reference %}
+ <strong>{{ item.reference }}</strong>{% endif %}
+ </div>
+ </div>
+ <div class="card-text text-center">
+ <p class='window-refs' title="{% trans 'Name' %}">{{item.name}}</p>
+ </div>
+ </div>
+ </div>
+
+ <div class="row">
+ <dl class="col-12 col-md-9 col-lg-9 flex-wrap">
+ <dt>{% trans "Towns" %}</dt>
+ <dd>{% for town in item.towns.all %}{% if forloop.counter0 %}&nbsp;; {% endif %}<span style="white-space: nowrap;">{{town}}{{town|simple_link_to_window}}</span>{% endfor %}</dd>
+ </dl>
+ {% with has_image=item.images.count %}
+ {% if not has_image %}
+ </div>
+ </div>
+ {% endif %}
+ {% if has_image %}
+ </div></div> {# <div> #}
+ {% endif %}
+ {% endwith %}
+ <hr class="clearfix">
+ {% comment %}
+ {% if PROFILE.mapping and geo_item.main_geodata %}
+ <h3>{% trans "Geographic localisation" %}</h3>
+ <div class="row">
+ {% with geo_item=item %}
+ {% include "ishtar/blocks/sheet_map.html"%}
+ {% endwith %}
+ </div>
+ {% endif %}
+ {% endcomment %}
+
+ {% if display_documents and item.documents.count %}
+ {% trans "Documents" as area_docs %}
+ {% dynamic_table_document area_docs 'documents' 'areas' item.pk '' output %}
+ {% endif %}
+
+ </div>
+ {% if not is_external and SHOW_GEO %}
+ <div class="tab-pane fade" id="{{window_id}}-geodata"
+ role="tabpanel" aria-labelledby="{{window_id}}-geodata-tab">
+ {% with geo_item=item %}{% include "ishtar/blocks/sheet_geographic.html" %}{% endwith %}
+ </div>
+ {% endif %}
+
+</div>
+
+
+<script type="text/javascript">
+$(document).ready( function () {
+ datatable_options = {
+ "dom": 'ltip',
+ };
+ $.extend(datatable_options, datatables_static_default);
+ if (datatables_i18n) datatable_options['language'] = datatables_i18n;
+ $('.datatables').each(
+ function(){
+ var dt_id = "#" + $(this).attr('id');
+ if (! $.fn.DataTable.isDataTable(dt_id) ) {
+ $(dt_id).DataTable(datatable_options);
+ }
+ });
+} );
+</script>
+
+{% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %} {% endwith %}
+
+{% endblock %} \ No newline at end of file
diff --git a/ishtar_common/templates/ishtar/sheet_area_pdf.html b/ishtar_common/templates/ishtar/sheet_area_pdf.html
new file mode 100644
index 000000000..fd5dd223c
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_area_pdf.html
@@ -0,0 +1,14 @@
+{% extends "ishtar/sheet_area.html" %}
+{% block header %}
+{% endblock %}
+{% block main_head %}
+{{ block.super }}
+<div id="pdfheader">
+Ishtar &ndash; {{APP_NAME}} &ndash; {{item}}
+</div>
+{% endblock %}
+{%block head_sheet%}{%endblock%}
+{%block main_foot%}
+</body>
+</html>
+{%endblock%}
diff --git a/ishtar_common/templates/ishtar/sheet_area_window.html b/ishtar_common/templates/ishtar/sheet_area_window.html
new file mode 100644
index 000000000..407a6b817
--- /dev/null
+++ b/ishtar_common/templates/ishtar/sheet_area_window.html
@@ -0,0 +1,3 @@
+{% extends "ishtar/sheet_area.html" %}
+{% block main_head %}{%endblock%}
+{% block main_foot %}{%endblock%}
diff --git a/ishtar_common/templates/ishtar/sheet_town.html b/ishtar_common/templates/ishtar/sheet_town.html
index 425effd8b..2b0cf6e4b 100644
--- a/ishtar_common/templates/ishtar/sheet_town.html
+++ b/ishtar_common/templates/ishtar/sheet_town.html
@@ -1,5 +1,5 @@
{% extends "ishtar/sheet.html" %}
-{% load i18n ishtar_helpers window_tables window_header window_field from_dict %}
+{% load i18n ishtar_helpers window_tables window_header window_field from_dict link_to_window %}
{% block head_title %}<strong>{% trans "Town" %}</strong> - {{item.name}}{% if item.numero_insee %} ({{item.numero_insee}}){% endif %}{% endblock %}
@@ -51,13 +51,12 @@
{% include "ishtar/blocks/window_image.html" %}
<div class="card-body">
<div class="row">
- <div class="col main">
+ <div class="col main text-center">
{% if item.numero_insee %}
- <strong>{{ item.numero_insee }}</strong
- >{% endif %}
+ <strong>{{ item.numero_insee }}</strong>{% endif %}
</div>
</div>
- <div class="card-text">
+ <div class="card-text text-center">
<p class='window-refs' title="{% trans 'Name' %}">{{item.name}}</p>
</div>
</div>
@@ -65,29 +64,37 @@
<div class="row">
{% if item.surface %}
- <dl class="col-12 col-md-6 col-lg-3 flex-wrap">
- <dt>{%trans "Surface"%}</dt>
+ <dl class="col-12 col-lg-9 flex-wrap">
+ <dt>{% trans "Surface" %}</dt>
<dd>
{{ item.surface }} m<sup>2</sup> ({{ item.surface_ha }} ha)
</dd>
</dl>
{% endif %}
+ {% if item.areas.count %}
+ <dl class="col-12 col-lg-9 flex-wrap">
+ <dt>{% trans "Areas" %}</dt>
+ <dd>{% for area in item.areas.all %}{% if forloop.counter0 %}&nbsp;; {% endif %}{{area}}{{area|simple_link_to_window}}{% endfor %}</dd>
+ </dl>
+ {% endif %}
{% with has_image=item.images.count %}
{% if not has_image %}
</div>
</div>
{% endif %}
{% if has_image %}
- </div> {# <div> #}
+ </div></div>
{% endif %}
{% endwith %}
<hr class="clearfix">
+ {% if PROFILE.mapping and geo_item.main_geodata %}
<h3>{% trans "Geographic localisation" %}</h3>
<div class="row">
{% with geo_item=item %}
{% include "ishtar/blocks/sheet_map.html"%}
{% endwith %}
</div>
+ {% endif %}
{% if display_documents and item.documents.count %}
{% trans "Documents" as town_docs %}
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py
index 692b9dd8d..210c200c6 100644
--- a/ishtar_common/templatetags/link_to_window.py
+++ b/ishtar_common/templatetags/link_to_window.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from django.urls import reverse
@@ -18,7 +18,7 @@ def simple_link_to_window(item, caption=""):
if getattr(item, "locked", None):
lock = '&nbsp;<i class="fa fa-lock text-danger" aria-hidden="true"></i>'
return mark_safe(
- ' <a class="display_details" href="#" '
+ '&nbsp;<a class="display_details" href="#" '
'onclick="load_window(\'{}\')">'
'<i class="fa fa-info-circle" aria-hidden="true"></i>{}{}</a>'.format(
reverse("show-" + item.SLUG, args=[item.pk, '']), lock, caption))
diff --git a/ishtar_common/urls.py b/ishtar_common/urls.py
index ebd6df0f0..61d15f390 100644
--- a/ishtar_common/urls.py
+++ b/ishtar_common/urls.py
@@ -379,6 +379,11 @@ urlpatterns += [
name="department-by-state",
),
url(
+ r"show-area(?:/(?P<pk>.+))?/(?P<type>.+)?$",
+ views.show_area,
+ name="show-area",
+ ),
+ url(
r"show-town(?:/(?P<pk>.+))?/(?P<type>.+)?$",
views.show_town,
name="show-town",
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index 7af07d6ad..0f0798381 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -1030,6 +1030,7 @@ get_person_for_account = get_item(
get_ishtaruser = get_item(models.IshtarUser, "get_ishtaruser", "ishtaruser")
show_town = show_item(models.Town, "town")
+show_area = show_item(models.Area, "area")
def action(request, action_slug, obj_id=None, *args, **kwargs):