From 3d766fae8dd27b097eadd66993a091aa32af1aec Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 27 Jun 2019 17:20:43 +0200 Subject: Warehouse: link warehouse to an organization - manage address dependencies --- ishtar_common/forms.py | 19 ++++++-- ishtar_common/models.py | 54 +++++++++++++++++++++- .../ishtar/blocks/sheet_address_section.html | 8 ++-- .../templates/ishtar/sheet_organization.html | 19 ++++++++ 4 files changed, 90 insertions(+), 10 deletions(-) (limited to 'ishtar_common') 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 = """ + """.format( + self.help_message) if not self.collapse: - return mark_safe(u"{label}".format( - label=self.label, level=self.level - )) + return mark_safe( + "{label}{help_message}".format( + label=self.label, level=self.level, + help_message=help_message)) html = u"""
@@ -540,7 +547,9 @@ class FormHeader(object): aria-labelledby="collapse-head-{slug}" data-parent="#colapse-parent-{slug}">
-""".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%}
{% trans "Address" %}
-
{% 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 %}
+
{% 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 %}
{% 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 %} +{% if item.warehouses.count %} +

{%trans "Warehouses"%}

+ + + + + + + + {% for warehouse in item.warehouses.all %} + + + + + + {% endfor %} +
 {% trans "Name" %}{% trans "Type" %}
{{warehouse.name|default:""}}{{warehouse.warehouse_type}}
+{% 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 %} -- cgit v1.2.3