summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/forms_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/furnitures/forms_common.py')
-rw-r--r--ishtar/furnitures/forms_common.py42
1 files changed, 34 insertions, 8 deletions
diff --git a/ishtar/furnitures/forms_common.py b/ishtar/furnitures/forms_common.py
index c62160df6..2082cd2b7 100644
--- a/ishtar/furnitures/forms_common.py
+++ b/ishtar/furnitures/forms_common.py
@@ -28,6 +28,7 @@ from django.shortcuts import render_to_response
from django.core import validators
from django.core.mail import send_mail
from django.core.exceptions import ObjectDoesNotExist
+from django.utils.safestring import mark_safe
from django.forms.formsets import formset_factory, DELETION_FIELD_NAME
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
@@ -40,11 +41,24 @@ import widgets
from forms import Wizard, FinalForm, FormSet, reverse_lazy, name_validator,\
clean_duplicated
+def get_town_field(required=True):
+ help_text = _(u"<p>Type name, department code and/or postal code of the "
+ u"town you would like to select. The search is insensitive to case.</p>\n"
+ u"<p>Only the first twenty results are displayed but specifying the "
+ u"department code is generally sufficient to get the appropriate result.</p>"
+ u"\n<p class='example'>For instance type \"saint denis 93\" for getting "
+ u"the french town Saint-Denis in the Seine-Saint-Denis department.</p>")
+ return forms.IntegerField(
+ widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
+ 'autocomplete-town', associated_model=models.Town),
+ validators=[models.valid_id(models.Town)], label=_(u"Town"),
+ help_text=mark_safe(help_text), required=required)
+
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())
+ choices=[])
person_in_charge = forms.IntegerField(label=_(u"Person in charge"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-person'), associated_model=models.Person),
@@ -65,6 +79,13 @@ class WarehouseForm(forms.Form):
mobile_phone = forms.CharField(label=_(u"Town"), max_length=18,
required=False)
+ def __init__(self, *args, **kwargs):
+ super(WarehouseForm, self).__init__(*args, **kwargs)
+ self.fields['warehouse_type'].choices = \
+ models.WarehouseType.get_types()
+ self.fields['warehouse_type'].help_text = \
+ models.WarehouseType.get_help()
+
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
@@ -81,7 +102,7 @@ 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())
+ choices=[])
address = forms.CharField(label=_(u"Address"), widget=forms.Textarea,
required=False)
address_complement = forms.CharField(label=_(u"Address complement"),
@@ -95,6 +116,13 @@ class OrganizationForm(forms.Form):
mobile_phone = forms.CharField(label=_(u"Town"), max_length=18,
required=False)
+ def __init__(self, *args, **kwargs):
+ super(OrganizationForm, self).__init__(*args, **kwargs)
+ self.fields['organization_type'].choices = \
+ models.OrganizationType.get_types()
+ self.fields['organization_type'].help_text = \
+ models.OrganizationType.get_help()
+
def save(self, user):
dct = self.cleaned_data
dct['history_modifier'] = user
@@ -128,7 +156,7 @@ class PersonForm(forms.Form):
email = forms.CharField(label=_(u"Email"), max_length=40, required=False,
validators=[validators.validate_email])
person_type = forms.ChoiceField(label=_("Person type"),
- choices=models.PersonType.get_types())
+ choices=[])
attached_to = forms.IntegerField(label=_("Current organization"),
widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'),
associated_model=models.Organization, new=True),
@@ -141,6 +169,7 @@ class PersonForm(forms.Form):
def __init__(self, *args, **kwargs):
super(PersonForm, self).__init__(*args, **kwargs)
self.fields['person_type'].choices = models.PersonType.get_types()
+ self.fields['person_type'].help_text = models.PersonType.get_help()
def save(self, user):
dct = self.cleaned_data
@@ -255,7 +284,7 @@ class AccountForm(forms.Form):
form_label = _("Account")
associated_models = {'pk':models.Person}
currents = {'pk':models.Person}
- pk = forms.IntegerField(widget=forms.HiddenInput, required=False)
+ pk = forms.IntegerField(label=u"", widget=forms.HiddenInput, required=False)
username = forms.CharField(label=_(u"Account"), max_length=30)
email = forms.CharField(label=_(u"Email"), max_length=75,
validators=[validators.validate_email])
@@ -310,10 +339,7 @@ class TownForm(forms.Form):
form_label = _("Towns")
associated_models = {'town':models.Town}
# !FIXME hard_link, reverse_lazy doen't seem to work with formsets
- town = forms.IntegerField(label=_(u"Town"), required=False,
- widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
- 'autocomplete-town', associated_model=models.Town),
- validators=[models.valid_id(models.Town)])
+ town = get_town_field(required=False)
class TownFormSet(FormSet):
def clean(self):