summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-27 17:20:43 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-27 17:20:43 +0200
commit5d4a7912d085a4af2491e8b413a552f598c943c2 (patch)
tree9201a1616398d4145fe3836821c3ccca788d817d /ishtar_common
parentde5b617a9b575911f09695028b5b650c53dcd6f6 (diff)
downloadIshtar-5d4a7912d085a4af2491e8b413a552f598c943c2.tar.bz2
Ishtar-5d4a7912d085a4af2491e8b413a552f598c943c2.zip
Warehouse: link warehouse to an organization - manage address dependencies
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/forms.py19
-rw-r--r--ishtar_common/models.py54
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_address_section.html8
-rw-r--r--ishtar_common/templates/ishtar/sheet_organization.html19
4 files changed, 90 insertions, 10 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 6cfef1595..823adf811 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -512,16 +512,23 @@ class FieldType(object):
class FormHeader(object):
- def __init__(self, label, level=4, collapse=False):
+ def __init__(self, label, level=4, collapse=False, help_message=""):
self.label = label
self.collapse = collapse
self.level = level
+ self.help_message = help_message
def render(self):
+ help_message = ""
+ if self.help_message:
+ help_message = """
+ <div class="alert alert-info" role="alert">{}</div>""".format(
+ self.help_message)
if not self.collapse:
- return mark_safe(u"<h{level}>{label}</h{level}>".format(
- label=self.label, level=self.level
- ))
+ return mark_safe(
+ "<h{level}>{label}</h{level}>{help_message}".format(
+ label=self.label, level=self.level,
+ help_message=help_message))
html = u"""<div id="collapse-parent-{slug}" class="collapse-form">
<div class="card">
<div class="card-header" id="collapse-head-{slug}">
@@ -540,7 +547,9 @@ class FormHeader(object):
aria-labelledby="collapse-head-{slug}"
data-parent="#colapse-parent-{slug}">
<div class="card-body">
-""".format(label=self.label, slug=slugify(self.label), level=self.level)
+ {help_message}
+""".format(label=self.label, slug=slugify(self.label), level=self.level,
+ help_message=help_message)
return mark_safe(html)
def render_end(self):
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a70399ba7..a03f9f387 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -93,7 +93,13 @@ from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \
__all__ = [
'ImporterModel', 'ImporterType', 'ImporterDefault', 'ImporterDefaultValues',
'ImporterColumn', 'ImporterDuplicateField', 'Regexp', 'ImportTarget',
- 'TargetKey', 'FormaterType', 'Import', 'TargetKeyGroup', 'ValueFormater'
+ 'TargetKey', 'FormaterType', 'Import', 'TargetKeyGroup', 'ValueFormater',
+ 'Organization', 'Person', 'valid_id', 'Town', 'SpatialReferenceSystem',
+ 'OrganizationType', 'Document', 'GeneralType', 'get_external_id',
+ 'LightHistorizedItem', 'OwnPerms', 'Address', 'post_save_cache',
+ 'DashboardFormItem', 'ShortMenuItem', 'document_attached_changed',
+ 'SearchAltName', 'DynamicRequest', 'GeoItem', 'QRCodeItem',
+ 'SearchVectorConfig', 'DocumentItem'
]
logger = logging.getLogger(__name__)
@@ -3565,6 +3571,14 @@ class Area(HierarchicalType):
class Address(BaseHistorizedItem):
+ FIELDS = (
+ "address", "address_complement", "postal_code", "town",
+ "precise_town", "country",
+ "alt_address", "alt_address_complement", "alt_postal_code", "alt_town",
+ "alt_country",
+ "phone", "phone_desc", "phone2", "phone_desc2", "phone3", "phone_desc3",
+ "raw_phone", "mobile_phone", "email", "alt_address_is_prefered"
+ )
address = models.TextField(_("Address"), null=True, blank=True)
address_complement = models.TextField(_("Address complement"), null=True,
blank=True)
@@ -3605,6 +3619,7 @@ class Address(BaseHistorizedItem):
alt_address_is_prefered = models.BooleanField(
_("Alternative address is prefered"), default=False)
history = HistoricalRecords()
+ SUB_ADDRESSES = []
class Meta:
abstract = True
@@ -3612,10 +3627,47 @@ class Address(BaseHistorizedItem):
def get_town_centroid(self):
if self.precise_town:
return self.precise_town.center, self._meta.verbose_name
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if sub_item and sub_item.precise_town:
+ return sub_item.precise_town.center, sub_item._meta.verbose_name
def get_town_polygons(self):
if self.precise_town:
return self.precise_town.limit, self._meta.verbose_name
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if sub_item and sub_item.precise_town:
+ return sub_item.precise_town.limit, sub_item._meta.verbose_name
+
+ def get_attribute(self, attr):
+ if self.town or self.precise_town:
+ return getattr(self, attr)
+ for sub_address in self.SUB_ADDRESSES:
+ sub_item = getattr(self, sub_address)
+ if not sub_item:
+ continue
+ if sub_item.town or sub_item.precise_town:
+ return getattr(sub_item, attr)
+ return getattr(self, attr)
+
+ def get_address(self):
+ return self.get_attribute("address")
+
+ def get_address_complement(self):
+ return self.get_attribute("address_complement")
+
+ def get_postal_code(self):
+ return self.get_attribute("postal_code")
+
+ def get_town(self):
+ return self.get_attribute("town")
+
+ def get_precise_town(self):
+ return self.get_attribute("precise_town")
+
+ def get_country(self):
+ return self.get_attribute("country")
def simple_lbl(self):
return str(self)
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_address_section.html b/ishtar_common/templates/ishtar/blocks/sheet_address_section.html
index a42cd6cca..80dbc07a4 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_address_section.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_address_section.html
@@ -1,10 +1,10 @@
{% load i18n %}
-{% if item.address or item.address_complement or item.postal_code or item.town or item.precise_town%}
+{% if item.get_address or item.get_address_complement or item.get_postal_code or item.get_town or item.get_precise_town%}
<dl class="{% if full %}col-12 col-lg-6{% else %}col-12 col-md-6 col-lg-4 d-flex row{% endif %} flex-wrap">
<dt>{% trans "Address" %}</dt>
<dd>
- <pre>{% if item.address %}{{item.address}}{% endif %}{% if item.address_complement %}
-{{item.address_complement}}{% endif %}{% if item.postal_code or item.town or item.precise_town %}
-{{item.postal_code}} {% if item.precise_town %}{{item.precise_town}}{% else %}{{item.town}}{% endif %}{% endif %}</pre>
+ <pre>{% if item.get_address %}{{item.get_address}}{% endif %}{% if item.get_address_complement %}
+{{item.get_address_complement}}{% endif %}{% if item.get_postal_code or item.get_town or item.get_precise_town %}
+{{item.get_postal_code}} {% if item.get_precise_town %}{{item.get_precise_town}}{% else %}{{item.get_town}}{% endif %}{% endif %}</pre>
</dd>
</dl>{% endif %}
diff --git a/ishtar_common/templates/ishtar/sheet_organization.html b/ishtar_common/templates/ishtar/sheet_organization.html
index 37f7a76ce..798ae7a9b 100644
--- a/ishtar_common/templates/ishtar/sheet_organization.html
+++ b/ishtar_common/templates/ishtar/sheet_organization.html
@@ -37,6 +37,25 @@
{% endfor %}
</table>
+{% if item.warehouses.count %}
+<h3>{%trans "Warehouses"%}</h3>
+
+<table class='table table-striped'>
+ <tr>
+ <th class='link'>&nbsp;</th>
+ <th>{% trans "Name" %}</th>
+ <th>{% trans "Type" %}</th>
+ </tr>
+ {% for warehouse in item.warehouses.all %}
+ <tr>
+ <td class='link'><a class='display_details' href="#" onclick='load_window("{% url "show-warehouse" warehouse.pk "" %}")'><i class="fa fa-info-circle" aria-hidden="true"></i></a></td>
+ <td class='string'>{{warehouse.name|default:""}}</td>
+ <td class='string'>{{warehouse.warehouse_type}}</td>
+ </tr>
+ {% endfor %}
+</table>
+{% endif %}
+
{% trans "General contractor organization of archaeological files" as af %}
{% if item.general_contractor_files.count %}
{% dynamic_table_document af 'files' 'corporation_general_contractor' item.pk '' output %}