diff options
author | Filipp Lepalaan <filipp@mac.com> | 2021-05-30 10:34:01 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2021-05-30 10:34:01 +0300 |
commit | 9dcc51f2211385239b0272bdbf2466637c874f35 (patch) | |
tree | 8ac9104abcfa817dc1092e5f338b8c90b4b8aaff /servo/forms | |
parent | 467f9fef717cbdc217aae63fef6481150e8e34a7 (diff) | |
download | Servo-9dcc51f2211385239b0272bdbf2466637c874f35.tar.gz Servo-9dcc51f2211385239b0272bdbf2466637c874f35.tar.bz2 Servo-9dcc51f2211385239b0272bdbf2466637c874f35.zip |
Check-in fixes and improvements
Diffstat (limited to 'servo/forms')
-rw-r--r-- | servo/forms/checkin.py | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/servo/forms/checkin.py b/servo/forms/checkin.py index 6a6cf9d..7141bc8 100644 --- a/servo/forms/checkin.py +++ b/servo/forms/checkin.py @@ -7,6 +7,7 @@ from datetime import date from django.conf import settings from django_countries import countries from django.core.validators import RegexValidator +from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from django.forms import SelectDateWidget @@ -40,15 +41,11 @@ class ConfirmationForm(forms.Form): class DeviceForm(forms.ModelForm): - """The form for editing devices in the /checkin view""" - + """ + Form for entering devices in the /checkin view + """ required_css_class = 'required' - purchase_country = forms.ChoiceField( - label=_('Country'), - choices=countries, - initial=settings.INSTALL_COUNTRY - ) accessories = forms.CharField( required=False, label=_('Accessories'), @@ -64,10 +61,10 @@ class DeviceForm(forms.ModelForm): ) condition = forms.CharField( - label=_('Condition of device'), required=False, + label=_('Condition of device'), widget=forms.Textarea(attrs={'class': 'span12', 'rows': 3}), - help_text=_("Please describe the condition of the device") + help_text=_('Please describe the condition of the device. Will be shown on the print-out.') ) queue = forms.ModelChoiceField( @@ -123,9 +120,10 @@ class DeviceForm(forms.ModelForm): class CustomerForm(forms.Form): - - from django.utils.safestring import mark_safe - + """ + Form for entering customer info in /checkin + Not using a ModelForm for a reason. + """ required_css_class = 'required' fname = forms.CharField(label=_('First name')) @@ -139,15 +137,12 @@ class CustomerForm(forms.Form): label=_('Email address'), widget=forms.TextInput(attrs={'class': 'span12'}) ) - phone = forms.CharField( - label=_('Phone number'), - validators=[phone_validator] - ) + phone = forms.CharField(label=_('Phone number')) address = forms.CharField(label=_('Address')) country = forms.ChoiceField( label=_('Country'), choices=Customer.COUNTRY_CHOICES, - initial=settings.INSTALL_COUNTRY + initial=settings.INSTALL_COUNTRY.upper() ) city = forms.CharField(label=_('City')) postal_code = forms.CharField(label=_('Postal Code')) @@ -179,6 +174,24 @@ class CustomerForm(forms.Form): label=_('Notify by Email') ) + def clean(self): + cd = super(CustomerForm, self).clean() + + phone = cd.get('phone') + country = cd.get('country') + + if len(phone) < 1: + return cd + + try: + phonenumbers.parse(phone, country) + except phonenumbers.NumberParseException as e: + print(e) + msg = _('Enter a valid phone number') + self._errors["phone"] = self.error_class([msg]) + + return cd + def clean_fname(self): v = self.cleaned_data.get('fname') return v.capitalize() @@ -242,20 +255,21 @@ class IssueForm(forms.Form): issue_description = forms.CharField( min_length=10, label=_(u'Problem description'), + help_text=_('Will appear on the print-out'), widget=forms.Textarea(attrs={'class': 'span12'}) ) attachment = forms.FileField( required=False, - label=_(u'Attachment'), + label=_('Attachment'), validators=[file_upload_validator], - help_text=_(u'Please use this to attach relevant documents') + help_text=_('Please use this to attach relevant documents') ) notes = forms.CharField( required=False, label=_(u'Notes'), widget=forms.Textarea(attrs={'class': 'span12'}), - help_text=_(u'Will not appear on the print-out') + help_text=_('Will not appear on the print-out') ) |