diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-05-11 17:33:47 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:44:34 +0200 |
commit | cb2bdf1cf1ee85ddf68e93c29611024571961c5d (patch) | |
tree | 9730565001c023b38104b04fafad2ec1ff183373 /archaeological_warehouse | |
parent | 481279913a62416ce038b8eb82ad16b581fee7cf (diff) | |
download | Ishtar-cb2bdf1cf1ee85ddf68e93c29611024571961c5d.tar.bz2 Ishtar-cb2bdf1cf1ee85ddf68e93c29611024571961c5d.zip |
Adapt forms and wizards to manage M2M images (refs #4076)
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r-- | archaeological_warehouse/forms.py | 11 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 12 | ||||
-rw-r--r-- | archaeological_warehouse/views.py | 2 |
3 files changed, 20 insertions, 5 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index e13255efc..27f03e752 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -33,7 +33,8 @@ from bootstrap_datepicker.widgets import DatePicker from ishtar_common.forms import name_validator, reverse_lazy, \ get_form_selection, TableSelect, ManageOldType, FinalForm, FormSet, \ CustomForm, FieldType -from ishtar_common.forms_common import get_image_help +from ishtar_common.forms_common import get_image_help, BaseImageFormset, \ + BaseImageForm from archaeological_finds.forms import FindMultipleFormSelection, \ SelectFindBasketForm @@ -160,6 +161,14 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form): return new_item +ImagesFormset = formset_factory(BaseImageForm, can_delete=True, + formset=BaseImageFormset) +ImagesFormset.file_upload = True +ImagesFormset.form_label = _(u"Images") +ImagesFormset.form_admin_name = _(u"Warehouse - 025 - Images") +ImagesFormset.form_slug = "warehouse-020-images" + + class WarehouseDeletionForm(FinalForm): confirm_msg = _(u"Would you like to delete this warehouse?") confirm_end_msg = _(u"Would you like to delete this warehouse?") diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 4edfe0d15..40de49d60 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -46,7 +46,12 @@ post_delete.connect(post_save_cache, sender=WarehouseType) class Warehouse(Address, DashboardFormItem, OwnPerms): + SLUG = 'warehouse' SHOW_URL = 'show-warehouse' + TABLE_COLS = ['name', 'warehouse_type'] + BASE_SEARCH_VECTORS = ['name', 'warehouse_type__label', "external_id", + "town", "comment"] + name = models.CharField(_(u"Name"), max_length=200) warehouse_type = models.ForeignKey(WarehouseType, verbose_name=_(u"Warehouse type")) @@ -64,10 +69,6 @@ class Warehouse(Address, DashboardFormItem, OwnPerms): auto_external_id = models.BooleanField( _(u"External ID is set automatically"), default=False) - TABLE_COLS = ['name', 'warehouse_type'] - BASE_SEARCH_VECTORS = ['name', 'warehouse_type__label', "external_id", - "town", "comment"] - class Meta: verbose_name = _(u"Warehouse") verbose_name_plural = _(u"Warehouses") @@ -82,6 +83,9 @@ class Warehouse(Address, DashboardFormItem, OwnPerms): def __unicode__(self): return u"%s (%s)" % (self.name, unicode(self.warehouse_type)) + def _get_base_image_path(self): + return u"{}/{}".format(self.SLUG, slugify(self.name)) + @property def associated_filename(self): return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ diff --git a/archaeological_warehouse/views.py b/archaeological_warehouse/views.py index f33991d8b..913fbd3be 100644 --- a/archaeological_warehouse/views.py +++ b/archaeological_warehouse/views.py @@ -103,6 +103,7 @@ warehouse_search_wizard = SearchWizard.as_view([ warehouse_creation_steps = [ ("warehouse-warehouse_creation", WarehouseForm), + ('images-warehouse_creation', ImagesFormset), ('divisions-warehouse_creation', SelectedDivisionFormset), ('final-warehouse_creation', FinalForm)] @@ -116,6 +117,7 @@ warehouse_creation_wizard = WarehouseWizard.as_view( warehouse_modification_wizard = WarehouseModificationWizard.as_view([ ('selec-warehouse_modification', WarehouseFormSelection), ("warehouse-warehouse_modification", WarehouseForm), + ('images-warehouse_modifcation', ImagesFormset), ('divisions-warehouse_modification', SelectedDivisionFormset), ('final-warehouse_modification', FinalForm)], label=_(u"Warehouse modification"), |