diff options
Diffstat (limited to 'ishtar/furnitures/forms_common.py')
-rw-r--r-- | ishtar/furnitures/forms_common.py | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/ishtar/furnitures/forms_common.py b/ishtar/furnitures/forms_common.py index 387e8ec17..c62160df6 100644 --- a/ishtar/furnitures/forms_common.py +++ b/ishtar/furnitures/forms_common.py @@ -40,6 +40,70 @@ import widgets from forms import Wizard, FinalForm, FormSet, reverse_lazy, name_validator,\ clean_duplicated +class WarehouseForm(forms.Form): + name = forms.CharField(label=_(u"Name"), max_length=40, + validators=[name_validator]) + warehouse_type = forms.ChoiceField(label=_(u"Warehouse type"), + choices=models.WarehouseType.get_types()) + person_in_charge = forms.IntegerField(label=_(u"Person in charge"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-person'), associated_model=models.Person), + validators=[models.valid_id(models.Person)], + required=False) + comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + required=False) + address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, + required=False) + address_complement = forms.CharField(label=_(u"Address complement"), + widget=forms.Textarea, required=False) + postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + required=False) + town = forms.CharField(label=_(u"Town"), max_length=30, required=False) + country = forms.CharField(label=_(u"Country"), max_length=30, + required=False) + phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) + mobile_phone = forms.CharField(label=_(u"Town"), max_length=18, + required=False) + + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['warehouse_type'] = models.WarehouseType.objects.get( + pk=dct['warehouse_type']) + if 'person_in_charge' in dct and dct['person_in_charge']: + dct['person_in_charge'] = models.Person.objects.get( + pk=dct['person_in_charge']) + new_item = models.Warehouse(**dct) + new_item.save() + return new_item + +class OrganizationForm(forms.Form): + name = forms.CharField(label=_(u"Name"), max_length=40, + validators=[name_validator]) + organization_type = forms.ChoiceField(label=_(u"Organization type"), + choices=models.OrganizationType.get_types()) + address = forms.CharField(label=_(u"Address"), widget=forms.Textarea, + required=False) + address_complement = forms.CharField(label=_(u"Address complement"), + widget=forms.Textarea, required=False) + postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + required=False) + town = forms.CharField(label=_(u"Town"), max_length=30, required=False) + country = forms.CharField(label=_(u"Country"), max_length=30, + required=False) + phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) + mobile_phone = forms.CharField(label=_(u"Town"), max_length=18, + required=False) + + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['organization_type'] = models.OrganizationType.objects.get( + pk=dct['organization_type']) + new_item = models.Organization(**dct) + new_item.save() + return new_item + class PersonWizard(Wizard): model = models.Person @@ -67,7 +131,7 @@ class PersonForm(forms.Form): choices=models.PersonType.get_types()) attached_to = forms.IntegerField(label=_("Current organization"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'), - associated_model=models.Organization), + associated_model=models.Organization, new=True), validators=[models.valid_id(models.Organization)], required=False) is_author = forms.BooleanField(label=_(u"Is an author?"), required=False) @@ -78,11 +142,24 @@ class PersonForm(forms.Form): super(PersonForm, self).__init__(*args, **kwargs) self.fields['person_type'].choices = models.PersonType.get_types() + def save(self, user): + dct = self.cleaned_data + dct['history_modifier'] = user + dct['person_type'] = models.PersonType.objects.get( + pk=dct['person_type']) + if 'attached_to' in dct and dct['attached_to']: + dct['attached_to'] = models.Organization.objects.get( + pk=dct['attached_to']) + new_item = models.Person(**dct) + new_item.save() + return new_item + person_creation_wizard = PersonWizard([ ('identity-person_creation', PersonForm), ('final-person_creation', FinalForm)], url_name='person_creation',) + person_modification_wizard = PersonWizard([ ('selec-person_modification', PersonFormSelection), ('identity-person_modification', PersonForm), |