diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-04-08 18:06:26 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | 9be03de7917bb321119641b9d0063cd060d9b3c1 (patch) | |
tree | 47c2df9adb1820c3993f1e50743dafcf86262e15 /archaeological_warehouse/forms.py | |
parent | b2bb294b82a968b899a852f4fa64495e9cc2984f (diff) | |
download | Ishtar-9be03de7917bb321119641b9d0063cd060d9b3c1.tar.bz2 Ishtar-9be03de7917bb321119641b9d0063cd060d9b3c1.zip |
New container management - merge action
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r-- | archaeological_warehouse/forms.py | 170 |
1 files changed, 100 insertions, 70 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index a7390a890..83289819e 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -44,12 +44,13 @@ from ishtar_common.forms import name_validator, reverse_lazy, \ get_form_selection, ManageOldType, FinalForm, FormSet, \ CustomForm, FieldType, DocumentItemSelect, FormHeader, TableSelect, \ CustomFormSearch, MultiSearchForm, LockForm -from ishtar_common.forms_common import get_town_field +from ishtar_common.forms_common import get_town_field, MergeForm, ManualMerge,\ + MergeIntoForm from archaeological_finds.forms import FindMultipleFormSelection, \ SelectFindBasketForm -def get_warehouse_field(label=_(u"Warehouse"), required=True): +def get_warehouse_field(label=_("Warehouse"), required=True): # !FIXME hard_link, reverse_lazy doen't seem to work with formsets url = "/" + settings.URL_PATH + 'autocomplete-warehouse' widget = widgets.JQueryAutoComplete(url, associated_model=models.Warehouse) @@ -58,14 +59,14 @@ def get_warehouse_field(label=_(u"Warehouse"), required=True): class SelectedDivisionForm(ManageOldType, forms.Form): - form_label = _(u"Division") + form_label = _("Division") base_model = 'associated_division' associated_models = {'division': models.WarehouseDivision, 'associated_division': models.WarehouseDivisionLink} division = forms.ChoiceField( - label=_(u"Division"), choices=(), + label=_("Division"), choices=(), validators=[valid_id(models.WarehouseDivision)]) - order = forms.IntegerField(label=_(u"Order"), min_value=0, required=False) + order = forms.IntegerField(label=_("Order"), min_value=0, required=False) def __init__(self, *args, **kwargs): super(SelectedDivisionForm, self).__init__(*args, **kwargs) @@ -79,24 +80,24 @@ class DivisionFormSet(FormSet): def clean(self): """Checks that no divisions are duplicated.""" self.check_duplicate(('division',), _("There are identical divisions.")) - self.check_duplicate(('order',), _(u"Order fields must be different."), + self.check_duplicate(('order',), _("Order fields must be different."), check_null=True) SelectedDivisionFormset = formset_factory( SelectedDivisionForm, can_delete=True, formset=DivisionFormSet) -SelectedDivisionFormset.form_label = _(u"Divisions") -SelectedDivisionFormset.form_admin_name = _(u"Warehouse - 020 - Divisions") +SelectedDivisionFormset.form_label = _("Divisions") +SelectedDivisionFormset.form_admin_name = _("Warehouse - 020 - Divisions") SelectedDivisionFormset.form_slug = "warehouse-020-divisions" class WarehouseSelect(CustomForm, TableSelect): _model = models.Warehouse - form_admin_name = _(u"Warehouse - 001 - Search") + form_admin_name = _("Warehouse - 001 - Search") form_slug = "warehouse-001-search" search_vector = forms.CharField( - label=_(u"Full text search"), widget=widgets.SearchWidget( + label=_("Full text search"), widget=widgets.SearchWidget( 'archaeological-warehouse', 'warehouse' )) name = forms.CharField(label=_("Name")) @@ -139,8 +140,8 @@ class WarehouseFormMultiSelection(LockForm, MultiSearchForm): class WarehouseForm(CustomForm, ManageOldType, forms.Form): HEADERS = {} - form_label = _(u"Warehouse") - form_admin_name = _(u"Warehouse - 010 - General") + form_label = _("Warehouse") + form_admin_name = _("Warehouse - 010 - General") form_slug = "warehouse-010-general" extra_form_modals = ["organization", "person"] associated_models = { @@ -151,9 +152,9 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form): 'spatial_reference_system': SpatialReferenceSystem } - name = forms.CharField(label=_(u"Name"), max_length=200, + name = forms.CharField(label=_("Name"), max_length=200, validators=[name_validator]) - warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"), + warehouse_type = forms.ChoiceField(label=_("Warehouse type"), choices=[]) organization = forms.IntegerField( label=_("Organization"), @@ -173,28 +174,28 @@ class WarehouseForm(CustomForm, ManageOldType, forms.Form): label=_("Create a new organization from this warehouse"), required=False ) - comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) HEADERS['address'] = FormHeader( - _(u"Address"), collapse=True, + _("Address"), collapse=True, help_message=_( "Only fill the following fields if no organization is provided or " "if the address of the warehouse is different from the one of the " "organization. If a new organization is created from this " "warehouse, the following fields are used for the organization.")) - address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, + address = forms.CharField(label=_("Address"), widget=forms.Textarea, required=False) - address_complement = forms.CharField(label=_(u"Address complement"), + address_complement = forms.CharField(label=_("Address complement"), widget=forms.Textarea, required=False) - postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + postal_code = forms.CharField(label=_("Postal code"), max_length=10, required=False) - town = forms.CharField(label=_(u"Town (freeform)"), max_length=150, + town = forms.CharField(label=_("Town (freeform)"), max_length=150, required=False) precise_town = get_town_field(required=False) - country = forms.CharField(label=_(u"Country"), max_length=30, + country = forms.CharField(label=_("Country"), max_length=30, required=False) - phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) - mobile_phone = forms.CharField(label=_(u"Mobile phone"), max_length=18, + phone = forms.CharField(label=_("Phone"), max_length=18, required=False) + mobile_phone = forms.CharField(label=_("Mobile phone"), max_length=18, required=False) HEADERS['x'] = FormHeader(_("Coordinates")) x = forms.FloatField(label=_("X"), required=False) @@ -250,13 +251,13 @@ class WarehouseModifyForm(WarehouseForm): class WarehouseDeletionForm(FinalForm): - confirm_msg = _(u"Would you like to delete this warehouse?") - confirm_end_msg = _(u"Would you like to delete this warehouse?") + confirm_msg = _("Would you like to delete this warehouse?") + confirm_end_msg = _("Would you like to delete this warehouse?") class ContainerForm(CustomForm, ManageOldType, forms.Form): - form_label = _(u"Container") - form_admin_name = _(u"Container - 010 - General") + form_label = _("Container") + form_admin_name = _("Container - 010 - General") form_slug = "container-010-general" file_upload = True extra_form_modals = ["warehouse", "organization", "person", "container"] @@ -264,10 +265,10 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): 'location': models.Warehouse, 'parent': models.Container, 'responsible': models.Warehouse} - reference = forms.CharField(label=_(u"Ref."), max_length=200) - old_reference = forms.CharField(label=_(u"Old reference"), required=False, + reference = forms.CharField(label=_("Ref."), max_length=200) + old_reference = forms.CharField(label=_("Old reference"), required=False, max_length=200) - container_type = forms.ChoiceField(label=_(u"Container type"), choices=[]) + container_type = forms.ChoiceField(label=_("Container type"), choices=[]) parent = forms.IntegerField( label=_("Parent container"), widget=widgets.JQueryAutoComplete( @@ -277,18 +278,18 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): required=False ) responsible = forms.IntegerField( - label=_(u"Responsible warehouse"), + label=_("Responsible warehouse"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse, new=True), validators=[valid_id(models.Warehouse)]) location = forms.IntegerField( - label=_(u"Current location (warehouse)"), + label=_("Current location (warehouse)"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse, new=True), validators=[valid_id(models.Warehouse)]) - comment = forms.CharField(label=_(u"Comment"), + comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) TYPES = [ FieldType('container_type', models.ContainerType), @@ -306,12 +307,15 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): cleaned_data = self.cleaned_data warehouse = cleaned_data.get("location") q = models.Container.objects.filter( - reference=cleaned_data.get("reference"), location__pk=warehouse) + reference=cleaned_data.get("reference"), location__pk=warehouse, + container_type_id=cleaned_data.get("container_type"), + parent_id=cleaned_data.get("parent") + ) if 'pk' in cleaned_data and cleaned_data['pk']: q = q.exclude(pk=int(cleaned_data['pk'])) if q.count(): - raise forms.ValidationError(_(u"This reference already exists for " - u"this warehouse.")) + raise forms.ValidationError(_("This reference already exists for " + "this warehouse.")) return cleaned_data def save(self, user): @@ -328,7 +332,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): class ContainerModifyForm(ContainerForm): pk = forms.IntegerField(required=False, widget=forms.HiddenInput) - index = forms.IntegerField(label=_(u"ID"), required=False) + index = forms.IntegerField(label=_("ID"), required=False) def __init__(self, *args, **kwargs): super(ContainerModifyForm, self).__init__(*args, **kwargs) @@ -358,25 +362,25 @@ class ContainerModifyForm(ContainerForm): if 'pk' in cleaned_data and cleaned_data['pk']: q = q.exclude(pk=int(cleaned_data['pk'])) if q.count(): - raise forms.ValidationError(_(u"This ID already exists for " - u"this warehouse.")) + raise forms.ValidationError(_("This ID already exists for " + "this warehouse.")) return cleaned_data class ContainerSelect(DocumentItemSelect): _model = models.Container - form_admin_name = _(u"Container - 001 - Search") + form_admin_name = _("Container - 001 - Search") form_slug = "container-001-search" search_vector = forms.CharField( - label=_(u"Full text search"), widget=widgets.SearchWidget( + label=_("Full text search"), widget=widgets.SearchWidget( 'archaeological-warehouse', 'container' )) location_name = get_warehouse_field(label=_("Warehouse")) container_type = forms.ChoiceField(label=_("Container type"), choices=[]) reference = forms.CharField(label=_("Ref.")) old_reference = forms.CharField(label=_("Old reference")) - comment = forms.CharField(label=_(u"Comment")) + comment = forms.CharField(label=_("Comment")) contain_containers = forms.NullBooleanField(label=_("Contain containers")) empty = forms.NullBooleanField(label=_("Currently empty")) is_stationary = forms.NullBooleanField(label=_("Is stationary")) @@ -388,7 +392,7 @@ class ContainerSelect(DocumentItemSelect): associated_model=ArchaeologicalSite), validators=[valid_id(ArchaeologicalSite)]) archaeological_sites_name = forms.CharField( - label=_(u"Archaeological site name (attached to the operation)") + label=_("Archaeological site name (attached to the operation)") ) archaeological_sites_context_record = forms.IntegerField( label=_("Archaeological site (attached to the context record)"), @@ -397,7 +401,7 @@ class ContainerSelect(DocumentItemSelect): associated_model=ArchaeologicalSite), validators=[valid_id(ArchaeologicalSite)]) archaeological_sites_context_record_name = forms.CharField( - label=_(u"Archaeological site name (attached to the context record)") + label=_("Archaeological site name (attached to the context record)") ) code_patriarche = forms.IntegerField(label=_("Operation - Code PATRIARCHE"), widget=OAWidget) @@ -415,33 +419,33 @@ class ContainerSelect(DocumentItemSelect): validators=[valid_id(ContextRecord)]) find_label = forms.CharField(label=_("Find - Label")) find_denomination = forms.CharField(label=_("Find - Denomination")) - description = forms.CharField(label=_(u"Find - Description")) + description = forms.CharField(label=_("Find - Description")) material_types = forms.IntegerField( - label=_(u"Material type"), + label=_("Material type"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-materialtype'), associated_model=MaterialType), ) object_types = forms.IntegerField( - label=_(u"Object type"), + label=_("Object type"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-objecttype'), associated_model=ObjectType), ) - integrities = forms.ChoiceField(label=_(u"Integrity / interest"), + integrities = forms.ChoiceField(label=_("Integrity / interest"), choices=[]) - remarkabilities = forms.ChoiceField(label=_(u"Remarkability"), + remarkabilities = forms.ChoiceField(label=_("Remarkability"), choices=[]) - conservatory_state = forms.ChoiceField(label=_(u"Conservatory state"), + conservatory_state = forms.ChoiceField(label=_("Conservatory state"), choices=[]) alterations = forms.ChoiceField( - label=_(u"Alteration"), choices=[]) + label=_("Alteration"), choices=[]) alteration_causes = forms.ChoiceField( - label=_(u"Alteration cause"), choices=[]) + label=_("Alteration cause"), choices=[]) preservation_to_considers = forms.ChoiceField( - choices=[], label=_(u"Preservation type")) + choices=[], label=_("Preservation type")) treatment_emergency = forms.ChoiceField( - choices=[], label=_(u"Treatment emergency") + choices=[], label=_("Treatment emergency") ) TYPES = [ @@ -463,56 +467,82 @@ class ContainerSelect(DocumentItemSelect): ContainerFormSelection = get_form_selection( - 'ContainerFormSelection', _(u"Container search"), 'container', + 'ContainerFormSelection', _("Container search"), 'container', models.Container, ContainerSelect, 'get-container', - _(u"You should select a container."), new=True, - new_message=_(u"Add a new container"), + _("You should select a container."), new=True, + new_message=_("Add a new container"), base_form_select=(LockForm, CustomFormSearch) ) MainContainerFormSelection = get_form_selection( - 'ContainerFormSelection', _(u"Container search"), 'pk', + 'ContainerFormSelection', _("Container search"), 'pk', models.Container, ContainerSelect, 'get-container', - _(u"You should select a container."), gallery=True, map=True, + _("You should select a container."), gallery=True, map=True, base_form_select=CustomFormSearch ) MainContainerFormMultiSelection = get_form_selection( - 'ContainerFormSelection', _(u"Container search"), 'pks', + 'ContainerFormSelection', _("Container search"), 'pks', models.Container, ContainerSelect, 'get-container', - _(u"You should select a container."), gallery=True, map=True, + _("You should select a container."), gallery=True, map=True, alt_pk_field="pk", multi=True, base_form_select=(LockForm, MultiSearchForm) ) +class MergeContainerForm(MergeForm): + class Meta: + model = models.Container + fields = [] + + FROM_KEY = 'from_container' + TO_KEY = 'to_container' + + +class ContainerMergeFormSelection(ManualMerge, forms.Form): + SEARCH_AND_SELECT = True + form_label = _("Container to merge") + associated_models = {'to_merge': models.Container} + currents = {'to_merge': models.Container} + to_merge = forms.CharField( + label="", required=False, + widget=widgets.DataTable( + reverse_lazy('get-container'), ContainerSelect, + models.Container, + multiple_select=True,),) + + +class ContainerMergeIntoForm(MergeIntoForm): + associated_model = models.Container + + class BasePackagingForm(SelectFindBasketForm): - form_label = _(u"Packaging") + form_label = _("Packaging") associated_models = {'treatment_type': TreatmentType, 'person': Person, 'location': models.Warehouse, 'basket': FindBasket} person = forms.IntegerField( - label=_(u"Packager"), + label=_("Packager"), widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-person'), associated_model=Person, new=True), validators=[valid_id(Person)]) start_date = forms.DateField( - label=_(u"Date"), required=False, widget=DatePicker, + label=_("Date"), required=False, widget=DatePicker, initial=datetime.date.today ) class FindPackagingFormSelection(FindMultipleFormSelection): - form_label = _(u"Packaged finds") + form_label = _("Packaged finds") class LocalisationForm(CustomForm, forms.Form): - form_admin_name = _(u"Container - 020 - Localisation") + form_admin_name = _("Container - 020 - Localisation") form_slug = "container-020-localisation" - form_label = _(u"Localisation") + form_label = _("Localisation") def __init__(self, *args, **kwargs): self.container, self.warehouse = None, None @@ -524,7 +554,7 @@ class LocalisationForm(CustomForm, forms.Form): if not self.warehouse: return for divlink in self.warehouse.divisions.order_by('order').all(): - initial = u"-" + initial = "-" if self.container: q = models.ContainerLocalisation.objects.filter( division__division=divlink.division, @@ -537,5 +567,5 @@ class LocalisationForm(CustomForm, forms.Form): class ContainerDeletionForm(FinalForm): - confirm_msg = _(u"Would you like to delete this container?") - confirm_end_msg = _(u"Would you like to delete this container?") + confirm_msg = _("Would you like to delete this container?") + confirm_end_msg = _("Would you like to delete this container?") |