diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-04-15 13:17:12 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | 582be0e5c7e43674b3dee79e3838f650f87893b8 (patch) | |
tree | 128f885d5edef830d669466dccc3f313482aaa2e | |
parent | 3bba23e35348744b58809a2068d6a8536b6c02e1 (diff) | |
download | Ishtar-582be0e5c7e43674b3dee79e3838f650f87893b8.tar.bz2 Ishtar-582be0e5c7e43674b3dee79e3838f650f87893b8.zip |
Fix warehouse division forms
-rw-r--r-- | archaeological_warehouse/admin.py | 3 | ||||
-rw-r--r-- | archaeological_warehouse/forms.py | 12 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 8 | ||||
-rw-r--r-- | archaeological_warehouse/templates/ishtar/sheet_warehouse.html | 9 | ||||
-rw-r--r-- | archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html | 10 | ||||
-rw-r--r-- | archaeological_warehouse/urls.py | 4 | ||||
-rw-r--r-- | archaeological_warehouse/views.py | 4 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 9 |
8 files changed, 30 insertions, 29 deletions
diff --git a/archaeological_warehouse/admin.py b/archaeological_warehouse/admin.py index 22e53490b..39f1d9136 100644 --- a/archaeological_warehouse/admin.py +++ b/archaeological_warehouse/admin.py @@ -41,7 +41,8 @@ class WarehouseAdmin(HistorizedObjectAdmin): ajax_form_dict.update({ 'town': 'town', 'precise_town': 'town', - 'person_in_charge': 'person' + 'person_in_charge': 'person', + 'organization': 'organization' }) form = make_ajax_form(model, ajax_form_dict) inlines = [DivisionInline] diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 3e754b84a..fb345032e 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -61,25 +61,25 @@ def get_warehouse_field(label=_("Warehouse"), required=True): class SelectedDivisionForm(ManageOldType, forms.Form): form_label = _("Division") base_model = 'associated_division' - associated_models = {'division': models.ContainerType, + associated_models = {'container_type': models.ContainerType, 'associated_division': models.WarehouseDivisionLink} - division = forms.ChoiceField( + container_type = forms.ChoiceField( label=_("Container type"), choices=(), validators=[valid_id(models.ContainerType)]) order = forms.IntegerField(label=_("Order"), min_value=0, required=False) def __init__(self, *args, **kwargs): super(SelectedDivisionForm, self).__init__(*args, **kwargs) - self.fields['division'].choices = \ + self.fields['container_type'].choices = \ models.ContainerType.get_types( - initial=self.init_data.get('division') - ) + initial=self.init_data.get('container_type')) class DivisionFormSet(FormSet): def clean(self): """Checks that no divisions are duplicated.""" - self.check_duplicate(('division',), _("There are identical divisions.")) + self.check_duplicate(('container_type',), + _("There are identical divisions.")) self.check_duplicate(('order',), _("Order fields must be different."), check_null=True) diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 6de87ee36..a99db2ef7 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -186,9 +186,9 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem, @property def location_types(self): return [ - wd.division.label + wd.container_type.label for wd in WarehouseDivisionLink.objects.filter( - warehouse=self).order_by('order').all() + warehouse=self).order_by('order').all() if wd.container_type ] @property @@ -326,7 +326,7 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem, DashboardFormItem, ) loca.delete() container.save() # force label regeneration - for container in list(item.owned_containers.all()): + for container in list(item.containers.all()): if Container.objects.filter(index=container.index, responsible=self).count(): container.index = Container.objects.filter( @@ -400,7 +400,7 @@ post_delete.connect(post_save_cache, sender=ContainerType) class WarehouseDivisionLink(models.Model): RELATED_SET_NAME = "divisions" - RELATED_ATTRS = ["order"] + RELATED_ATTRS = ["order", "container_type"] RELATIVE_MODELS = {Warehouse: 'warehouse'} warehouse = models.ForeignKey(Warehouse, related_name='divisions') container_type = models.ForeignKey(ContainerType, blank=True, null=True) diff --git a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html index 30d48d6bd..feb8b786a 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_warehouse.html +++ b/archaeological_warehouse/templates/ishtar/sheet_warehouse.html @@ -3,7 +3,7 @@ {% block head_title %}<strong>{% trans "Warehouse" %}</strong> - {{item.name}} ({{item.warehouse_type}}){% endblock %} {% block toolbar %} -{% window_nav item window_id 'show-warehouse' 'warehouse_modify' '' '' previous next 1 %} +{% window_nav item window_id 'show-warehouse' 'warehouse_modify' 'show-historized-warehouse' 'revert-warehouse' previous next 1 %} {% endblock %} {% block content %} @@ -32,7 +32,8 @@ {% include "ishtar/blocks/sheet_creation_section.html" %} {% field_flex_detail "Person in charge" item.person_in_charge %} {% field_flex_detail "Organization" item.organization %} - {% field_flex "Divisions" item.location_types|join:", " %} + {% trans "Default divisions" as def_div_label %} + {% field_flex def_div_label item.location_types|join:", " %} {% field_flex_full "Comment" item.comment "<pre>" "</pre>" %} {% include "ishtar/blocks/sheet_json.html" %} </div> @@ -57,10 +58,6 @@ {% dynamic_table_document '' 'containers' 'location_id' item.pk 'TABLE_COLS' output %} {% endif %} -{% if item.owned_containers.count %} -<h4>{% trans "Attached containers" %}</h4> -{% dynamic_table_document '' 'containers' 'responsible_id' item.pk 'TABLE_COLS' output %} -{% endif %} <h3>{% trans "Statistics" %}</h3> <small class="centered"><em>{% trans "These numbers are updated hourly" %}</em></small> diff --git a/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html b/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html index cceabb4a0..dff23bc6c 100644 --- a/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html +++ b/archaeological_warehouse/templates/ishtar/wizard/wizard_warehouse_divisions.html @@ -1,10 +1,8 @@ {% extends "ishtar/wizard/default_wizard.html" %} {% load i18n %} {% block form_head %} -{% if wizard.form.readonly %} -<p class="alert"> - <i class="fa fa-exclamation-triangle"></i> - {% trans "Containers with localisation are associated to this warehouse. You cannot change divisions." %}<br/> -</p> -{% endif %} +<div class="alert alert-info"> + <i class="fa fa-exclamation-triangle"></i> + {% trans "Default division for this warehouse. Theses divisions are only used for imports." %}<br/> +</div> {% endblock %} diff --git a/archaeological_warehouse/urls.py b/archaeological_warehouse/urls.py index 56f554edf..0285d292f 100644 --- a/archaeological_warehouse/urls.py +++ b/archaeological_warehouse/urls.py @@ -36,6 +36,10 @@ urlpatterns = [ views.new_warehouse, name='new-warehouse'), url(r'^show-warehouse(?:/(?P<pk>.+))?/(?P<type>.+)?$', views.show_warehouse, name=models.Warehouse.SHOW_URL), + url(r'^show-historized-warehouse/(?P<pk>.+)?/(?P<date>.+)?$', + views.show_warehouse, name='show-historized-warehouse'), + url(r'^revert-warehouse/(?P<pk>.+)/(?P<date>.+)$', + views.revert_warehouse, name='revert-warehouse'), url(r'autocomplete-warehouse/$', views.autocomplete_warehouse, name='autocomplete-warehouse'), url(r'new-container/(?P<parent_name>.+)?/$', diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index 801c2255c..4c98b8ac3 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -34,7 +34,8 @@ from ishtar_common.forms import FinalForm from ishtar_common.views import QABaseLockView, wizard_is_available, \ merge_action, ManualMergeMixin, ManualMergeItemsMixin, IshtarMixin, \ LoginRequiredMixin -from ishtar_common.views_item import get_item, show_item, new_qa_item +from ishtar_common.views_item import get_item, show_item, new_qa_item, \ + revert_item from archaeological_finds.views import treatment_add from archaeological_warehouse.wizards import PackagingWizard, WarehouseSearch, \ @@ -50,6 +51,7 @@ show_container = show_item(models.Container, 'container') get_warehouse = get_item(models.Warehouse, 'get_warehouse', 'warehouse', search_form=forms.WarehouseSelect) show_warehouse = show_item(models.Warehouse, 'warehouse') +revert_warehouse = revert_item(models.Warehouse) new_warehouse = new_qa_item(models.Warehouse, forms.WarehouseForm) new_container = new_qa_item(models.Container, forms.ContainerForm) diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index eac8d1868..db2cb7829 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -297,7 +297,7 @@ class Wizard(IshtarWizard): else: # formset for formset_idx, v in enumerate(values): - prefix = u"-%d-" % formset_idx + prefix = "-%d-" % formset_idx for key in v: form_key = next_step + prefix + key if isinstance(v, MultiValueDict): @@ -420,9 +420,9 @@ class Wizard(IshtarWizard): value = _(value) if type(value) == bool: if value: - value = _(u"Yes") + value = _("Yes") else: - value = _(u"No") + value = _("No") elif key in associated_models: values = [] if type(value) in (tuple, list): @@ -440,7 +440,7 @@ class Wizard(IshtarWizard): else: value = str(item) rendered_values.append(value) - value = u" ; ".join(rendered_values) + value = " ; ".join(rendered_values) current_form_data.append((lbl, value, '')) if is_formset: @@ -1418,7 +1418,6 @@ class Wizard(IshtarWizard): query = related if not through and not obj._meta.ordering: query = query.order_by('pk') - # an intermediary model is used through_fields = [] if through and not related.model._meta.auto_created: |