summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_warehouse/forms.py1
-rw-r--r--archaeological_warehouse/models.py10
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_warehouse.html1
-rw-r--r--ishtar_common/wizards.py14
4 files changed, 21 insertions, 5 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 350e48814..57992c7e2 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -76,7 +76,6 @@ SelectedDivisionFormset = formset_factory(
SelectedDivisionFormset.form_label = _(u"Divisions")
SelectedDivisionFormset.form_admin_name = _(u"Warehouse - 020 - Divisions")
SelectedDivisionFormset.form_slug = "warehouse-020-divisions"
-SelectedDivisionFormset.form_through_name = "divisions"
class WarehouseSelect(TableSelect):
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index bf7ea1eb6..bbcdd93d7 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -106,6 +106,14 @@ class Warehouse(Address, DashboardFormItem, OwnPerms):
return u"{}/{}".format(self.SLUG, slugify(self.name))
@property
+ def location_types(self):
+ return [
+ wd.division.label
+ for wd in WarehouseDivisionLink.objects.filter(
+ warehouse=self).order_by('order').all()
+ ]
+
+ @property
def associated_filename(self):
return datetime.date.today().strftime('%Y-%m-%d') + '-' + \
slugify(unicode(self))
@@ -254,6 +262,8 @@ post_delete.connect(post_save_cache, sender=WarehouseDivision)
class WarehouseDivisionLink(models.Model):
+ RELATED_SET_NAME = "divisions"
+ RELATED_ATTRS = ["order"]
RELATIVE_MODELS = {Warehouse: 'warehouse'}
warehouse = models.ForeignKey(Warehouse, related_name='divisions')
division = models.ForeignKey(WarehouseDivision)
diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
index 84eb02ae9..1b16819b6 100644
--- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
+++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html
@@ -32,6 +32,7 @@
{% 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>
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 6209a16c3..9a068063b 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -705,8 +705,11 @@ class Wizard(IshtarWizard):
related_model = getattr(obj, model + 's')
# manage through
if hasattr(related_model, 'through') and related_model.through:
- related_set_name = str(
- related_model.through.__name__ + '_set').lower()
+ if hasattr(related_model.through, "RELATED_SET_NAME"):
+ related_set_name = related_model.through.RELATED_SET_NAME
+ else:
+ related_set_name = str(
+ related_model.through.__name__ + '_set').lower()
if hasattr(obj, related_set_name):
related_model = getattr(obj, related_set_name)
# clear real m2m
@@ -732,6 +735,9 @@ class Wizard(IshtarWizard):
(field.related_model == related_model.model or
isinstance(obj, field.related_model)):
continue
+ if field.name in getattr(
+ related_model.through, 'RELATED_ATTRS', []):
+ continue
related_data[field.name] = None
if key not in m2m_items:
@@ -1320,8 +1326,8 @@ class Wizard(IshtarWizard):
# manage through
through = False
if hasattr(related, 'through') and related.through:
- if hasattr(c_form, "form_through_name"):
- related_set_name = c_form.form_through_name
+ if hasattr(related.through, "RELATED_SET_NAME"):
+ related_set_name = related.through.RELATED_SET_NAME
else:
related_set_name = str(
related.through.__name__ + '_set').lower()