Commits

Alex Ulianytskyi committed baaa876

При первой загрузки форма бронирования чистая. Валидация is_agree.

Comments (0)

Files changed (4)

catalogue/forms.py

     cleaned_data = form.cleaned_data
     start = cleaned_data.get('start', None)
     end = cleaned_data.get('end', None)
-    if start is None and end is None:
+    if start is None or end is None:
         return cleaned_data
     if start > end:
         raise forms.ValidationError(form.error_fields['order'])
 PHONE_REGEX = r'\+\d{1,2} ?\(?\d{3}\)? ?\d{3}( |\-)?\d{2}( |\-)?\d{2}'
 # TODO: Доделать форму
 class ReservationForm(forms.Form):
+    quiet = False
     error_fields = {
     'order': _('Check-in date later then departure date'),
     'occupied': _('The apartment occupied during this period, please select a different dates.'),
+    'not_agree': _('You must agree with public agreement'),
     }
     apartment = forms.IntegerField(label=_('apartment'), widget=forms.HiddenInput)
     start = forms.DateField(label=_('check-in date'), widget=JqueyUiDatepicker, input_formats=['%d.%m.%Y'])
     email = forms.EmailField(label=_('email'))
     is_agree = forms.BooleanField(label=_('I am agree'))
     captcha = ReCaptchaField()
+    def has_changed(self):
+        if not self.quiet:
+            return super(ReservationForm, self).has_changed()
+        else:
+            return False
     def clean(self):
         return clean_reservation_period(self)
+    def clean_is_agree(self):
+        is_agree = self.cleaned_data.get('is_agree', False)
+        if not is_agree:
+            raise forms.ValidationError(form.error_fields['not_agree'])
+        return is_agree

catalogue/views.py

         apartment = get_object_or_404(models.Apartment, code=code)
     search_form = forms.SearchForm()
     find_by_id_form = forms.FindByIdForm()
-    reservation_form = forms.ReservationForm({'apartment': apartment.id})
+    reservation_form = forms.ReservationForm({'apartment': apartment.id}, empty_permitted=True)
+    reservation_form.quiet = True
     return {
         'apartment': apartment,
         'search_form': search_form,

db/development.sqlite

Binary file modified.

templates/catalogue/apartment.html

         reservationForm.find('input').live('change', function(event){
             reservationForm.submit();
         });
-        reservationForm.ajaxForm({
+        var ajaxOptions = {
             target: '#reservation_form_body',
             url: '{% url catalogue:validate_reservation_form %}',
             success: function(response) {
                 initDatepickers();
             }
-        });
+        }
+        reservationForm.ajaxForm(ajaxOptions);
     });
 </script>
 {% endblock %}