summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-02-19 17:36:25 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-24 19:38:56 +0200
commit4f63ed814f96bbc68c22c98b799c3911d62aa737 (patch)
tree1ac2de99841b7a28fee128a68700f59458594f14 /archaeological_warehouse
parentb6d3f2dc4a24bb055b73b7c80815685572a83086 (diff)
downloadIshtar-4f63ed814f96bbc68c22c98b799c3911d62aa737.tar.bz2
Ishtar-4f63ed814f96bbc68c22c98b799c3911d62aa737.zip
Geo: manage container and warehouse - manage geo save dependencies
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/forms.py31
-rw-r--r--archaeological_warehouse/migrations/0034_auto_20190218_1808.py168
-rw-r--r--archaeological_warehouse/models.py30
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container.html12
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse.html15
5 files changed, 242 insertions, 14 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 7a84b2833..4550970c9 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -25,7 +25,7 @@ from django.conf import settings
from django.forms.formsets import formset_factory
from django.utils.translation import ugettext_lazy as _
-from ishtar_common.models import Person, valid_id
+from ishtar_common.models import Person, valid_id, Town, SpatialReferenceSystem
from archaeological_operations.models import ArchaeologicalSite
from archaeological_context_records.models import ContextRecord
from archaeological_finds.models import TreatmentType, FindBasket, \
@@ -40,7 +40,8 @@ from bootstrap_datepicker.widgets import DatePicker
from ishtar_common.forms import name_validator, reverse_lazy, \
get_form_selection, ManageOldType, FinalForm, FormSet, \
- CustomForm, FieldType, HistorySelect
+ CustomForm, FieldType, HistorySelect, FormHeader
+from ishtar_common.forms_common import get_town_field
from archaeological_finds.forms import FindMultipleFormSelection, \
SelectFindBasketForm
@@ -115,16 +116,21 @@ class WarehouseFormSelection(forms.Form):
label="", required=False,
widget=widgets.DataTable(
reverse_lazy('get-warehouse'),
- WarehouseSelect, models.Warehouse),
+ WarehouseSelect, models.Warehouse, gallery=True, map=True),
validators=[valid_id(models.Warehouse)])
class WarehouseForm(CustomForm, ManageOldType, forms.Form):
+ HEADERS = {}
form_label = _(u"Warehouse")
form_admin_name = _(u"Warehouse - 010 - General")
form_slug = "warehouse-010-general"
- associated_models = {'warehouse_type': models.WarehouseType,
- 'person_in_charge': Person}
+ associated_models = {
+ 'warehouse_type': models.WarehouseType,
+ 'person_in_charge': Person,
+ 'precise_town': Town,
+ 'spatial_reference_system': SpatialReferenceSystem
+ }
name = forms.CharField(label=_(u"Name"), max_length=200,
validators=[name_validator])
@@ -145,14 +151,23 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form):
widget=forms.Textarea, required=False)
postal_code = forms.CharField(label=_(u"Postal code"), max_length=10,
required=False)
- town = forms.CharField(label=_(u"Town"), max_length=30, required=False)
+ town = forms.CharField(label=_(u"Town (freeform)"), max_length=150,
+ required=False)
+ precise_town = get_town_field(required=False)
country = forms.CharField(label=_(u"Country"), max_length=30,
required=False)
phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False)
mobile_phone = forms.CharField(label=_(u"Mobile phone"), max_length=18,
required=False)
+ HEADERS['x'] = FormHeader(_(u"Coordinates"))
+ x = forms.FloatField(label=_(u"X"), required=False)
+ y = forms.FloatField(label=_(u"Y"), required=False)
+ spatial_reference_system = forms.ChoiceField(
+ label=_(u"Spatial Reference System"), required=False, choices=[])
+
TYPES = [
- FieldType('warehouse_type', models.WarehouseType)
+ FieldType('warehouse_type', models.WarehouseType),
+ FieldType('spatial_reference_system', SpatialReferenceSystem)
]
def __init__(self, *args, **kwargs):
@@ -347,7 +362,7 @@ ContainerFormSelection = get_form_selection(
MainContainerFormSelection = get_form_selection(
'ContainerFormSelection', _(u"Container search"), 'pk',
models.Container, ContainerSelect, 'get-container',
- _(u"You should select a container.")
+ _(u"You should select a container."), gallery=True, map=True
)
diff --git a/archaeological_warehouse/migrations/0034_auto_20190218_1808.py b/archaeological_warehouse/migrations/0034_auto_20190218_1808.py
new file mode 100644
index 000000000..2832e1706
--- /dev/null
+++ b/archaeological_warehouse/migrations/0034_auto_20190218_1808.py
@@ -0,0 +1,168 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2019-02-18 18:08
+from __future__ import unicode_literals
+
+import django.contrib.gis.db.models.fields
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0088_auto_20190218_1808'),
+ ('archaeological_warehouse', '0033_auto_20190212_1524'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='container',
+ name='estimated_error_x',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour X'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='estimated_error_y',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour Y'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='estimated_error_z',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour Z'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='multi_polygon',
+ field=django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=4326, verbose_name='Polygones multi-parties'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='multi_polygon_source',
+ field=models.CharField(blank=True, choices=[(b'T', 'Commune'), (b'P', 'Precise')], max_length=1, null=True, verbose_name='Multi-polygon source'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='multi_polygon_source_item',
+ field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Multi polygon source item'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='point',
+ field=django.contrib.gis.db.models.fields.PointField(blank=True, dim=3, null=True, srid=4326, verbose_name='Point'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='point_2d',
+ field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='Point (2D)'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='point_source',
+ field=models.CharField(blank=True, choices=[(b'T', 'Commune'), (b'P', 'Precise')], max_length=1, null=True, verbose_name='Point source'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='point_source_item',
+ field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Point source item'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='spatial_reference_system',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SpatialReferenceSystem', verbose_name='Syst\xe8me de r\xe9f\xe9rence spatiale'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='x',
+ field=models.FloatField(blank=True, null=True, verbose_name='X/Long'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='y',
+ field=models.FloatField(blank=True, null=True, verbose_name='Y/Lat'),
+ ),
+ migrations.AddField(
+ model_name='container',
+ name='z',
+ field=models.FloatField(blank=True, null=True, verbose_name='Z'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='estimated_error_x',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour X'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='estimated_error_y',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour Y'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='estimated_error_z',
+ field=models.FloatField(blank=True, null=True, verbose_name='Erreur estim\xe9e pour Z'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='multi_polygon',
+ field=django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=4326, verbose_name='Polygones multi-parties'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='multi_polygon_source',
+ field=models.CharField(blank=True, choices=[(b'T', 'Commune'), (b'P', 'Precise')], max_length=1, null=True, verbose_name='Multi-polygon source'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='multi_polygon_source_item',
+ field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Multi polygon source item'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='point',
+ field=django.contrib.gis.db.models.fields.PointField(blank=True, dim=3, null=True, srid=4326, verbose_name='Point'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='point_2d',
+ field=django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326, verbose_name='Point (2D)'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='point_source',
+ field=models.CharField(blank=True, choices=[(b'T', 'Commune'), (b'P', 'Precise')], max_length=1, null=True, verbose_name='Point source'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='point_source_item',
+ field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Point source item'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='precise_town',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.Town', verbose_name='Town (precise)'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='spatial_reference_system',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SpatialReferenceSystem', verbose_name='Syst\xe8me de r\xe9f\xe9rence spatiale'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='x',
+ field=models.FloatField(blank=True, null=True, verbose_name='X/Long'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='y',
+ field=models.FloatField(blank=True, null=True, verbose_name='Y/Lat'),
+ ),
+ migrations.AddField(
+ model_name='warehouse',
+ name='z',
+ field=models.FloatField(blank=True, null=True, verbose_name='Z'),
+ ),
+ migrations.AlterField(
+ model_name='warehouse',
+ name='town',
+ field=models.CharField(blank=True, max_length=150, null=True, verbose_name='Town (freeform)'),
+ ),
+ ]
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index c80b4476b..795c879e4 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -31,8 +31,8 @@ from ishtar_common.data_importer import post_importer_action
from ishtar_common.models import Document, GeneralType, get_external_id, \
LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \
DashboardFormItem, ExternalIdManager, ShortMenuItem, \
- document_attached_changed, SearchAltName, DynamicRequest
-from ishtar_common.utils import cached_label_changed
+ document_attached_changed, SearchAltName, DynamicRequest, GeoItem
+from ishtar_common.utils import cached_label_changed, post_save_geo
class WarehouseType(GeneralType):
@@ -46,7 +46,7 @@ post_save.connect(post_save_cache, sender=WarehouseType)
post_delete.connect(post_save_cache, sender=WarehouseType)
-class Warehouse(Address, DashboardFormItem, OwnPerms,
+class Warehouse(Address, GeoItem, DashboardFormItem, OwnPerms,
ShortMenuItem):
SLUG = 'warehouse'
SHOW_URL = 'show-warehouse'
@@ -69,6 +69,7 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,
'warehouse_type__label__iexact'
),
}
+ GEO_LABEL = "name"
objects = ExternalIdManager()
@@ -258,6 +259,8 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,
m2m_changed.connect(document_attached_changed,
sender=Warehouse.documents.through)
+post_save.connect(post_save_geo, sender=Warehouse)
+
class Collection(LightHistorizedItem):
name = models.CharField(_(u"Name"), max_length=200,
@@ -319,7 +322,7 @@ post_save.connect(post_save_cache, sender=ContainerType)
post_delete.connect(post_save_cache, sender=ContainerType)
-class Container(LightHistorizedItem, OwnPerms):
+class Container(LightHistorizedItem, GeoItem, OwnPerms):
SLUG = 'container'
SHOW_URL = 'show-container'
TABLE_COLS = ['reference', 'container_type__label', 'cached_location',
@@ -350,6 +353,7 @@ class Container(LightHistorizedItem, OwnPerms):
'cached_division': _(u"Precise localisation"),
'container_type__label': _(u"Type")
}
+ GEO_LABEL = "cached_label"
CACHED_LABELS = ['cached_division', 'cached_label', 'cached_location', ]
# alternative names of fields for searches
@@ -555,6 +559,18 @@ class Container(LightHistorizedItem, OwnPerms):
Q(location__person_in_charge__ishtaruser=ishtaruser) | \
Q(responsible__person_in_charge__ishtaruser=ishtaruser)
+ def get_precise_points(self):
+ precise_points = super(Container, self).get_precise_points()
+ if precise_points:
+ return precise_points
+ return self.location.get_precise_points()
+
+ def get_town_centroid(self):
+ return self.location.get_town_centroid()
+
+ def get_town_polygons(self):
+ return self.location.get_town_polygons()
+
@property
def associated_filename(self):
filename = datetime.date.today().strftime('%Y-%m-%d')
@@ -747,8 +763,12 @@ class Container(LightHistorizedItem, OwnPerms):
loca.delete()
-post_save.connect(cached_label_changed, sender=Container)
+def container_post_save(sender, **kwargs):
+ cached_label_changed(sender=sender, **kwargs)
+ post_save_geo(sender=sender, **kwargs)
+
+post_save.connect(container_post_save, sender=Container)
m2m_changed.connect(document_attached_changed,
sender=Container.documents.through)
diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html
index 27cbf9bee..f40020a92 100644
--- a/archaeological_warehouse/templates/ishtar/sheet_container.html
+++ b/archaeological_warehouse/templates/ishtar/sheet_container.html
@@ -39,6 +39,18 @@
</div>
</div>
+{% if item.point_2d or item.multi_polygon %}
+<h3>{% trans "Localisation"%}</h3>
+<div class='row'>
+ {% with geo_item=item %}
+ {% include "ishtar/blocks/sheet_simple_map.html"%}
+ <div class="col-12 col-lg-6 flex-wrap">
+ {% include "ishtar/blocks/sheet_coordinates.html"%}
+ </div>
+ {% endwith %}
+</div>
+{% endif %}
+
{% if item.finds.count %}
<h4>{% trans "Content" %}</h4>
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
index eed484d5a..6be884e8e 100644
--- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
+++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
@@ -31,13 +31,26 @@
<div class='row'>
{% field_flex "Person in charge" item.person_in_charge %}
{% include "ishtar/blocks/sheet_creation_section.html" %}
- {% include "ishtar/blocks/sheet_address_section.html" %}
{% field_flex "Divisions" item.location_types|join:", " %}
{% field_flex_full "Comment" item.comment "<pre>" "</pre>" %}
{% include "ishtar/blocks/sheet_json.html" %}
</div>
+{% if item.point_2d or item.multi_polygon or item.address or item.address_complement or item.postal_code or item.town %}
+<h3>{% trans "Localisation"%}</h3>
+<div class='row'>
+ {% with geo_item=item %}
+ {% include "ishtar/blocks/sheet_simple_map.html"%}
+ <div class="col-12 col-lg-6 flex-wrap">
+ {% include "ishtar/blocks/sheet_coordinates.html"%}
+ {% with full=True %}{% include "ishtar/blocks/sheet_address_section.html" %}{% endwith %}
+ </div>
+ {% endwith %}
+</div>
+{% endif %}
+
+
{% if item.containers.count %}
<h4>{% trans "Containers" %}</h4>
{% dynamic_table_document '' 'containers' 'location_id' item.pk 'TABLE_COLS' output %}