Kaynağa Gözat

Provide a hook for cross-form validation

master
Markus Bertheau 12 yıl önce
ebeveyn
işleme
46829eeecc
1 değiştirilmiş dosya ile 12 ekleme ve 2 silme
  1. 12
    2
      oscar/apps/dashboard/catalogue/views.py

+ 12
- 2
oscar/apps/dashboard/catalogue/views.py Dosyayı Görüntüle

@@ -248,11 +248,12 @@ class ProductCreateUpdateView(generic.UpdateView):
248 248
         is_valid = form.is_valid() and all([formset.is_valid()
249 249
                                             for formset in formsets.values()])
250 250
 
251
-        if is_valid:
251
+        cross_form_validation_result = self.clean(form, formsets)
252
+        if is_valid and cross_form_validation_result:
252 253
             return self.forms_valid(form, formsets)
253 254
         else:
254 255
             # delete the temporary product again
255
-            if self.creating and form.is_valid():
256
+            if self.creating and self.object and self.object.pk is not None:
256 257
                 self.object.delete()
257 258
                 self.object = None
258 259
             return self.forms_invalid(form, formsets)
@@ -265,6 +266,15 @@ class ProductCreateUpdateView(generic.UpdateView):
265 266
     # redirect.
266 267
     form_valid = form_invalid = process_all_forms
267 268
 
269
+    def clean(self, form, formsets):
270
+        """
271
+        Perform any cross-form/formset validation. If there are errors, attach
272
+        errors to a form or a form field so that they are displayed to the user
273
+        and return False. If everything is valid, return True. This method will
274
+        be called regardless of whether the individual forms are valid.
275
+        """
276
+        return True
277
+
268 278
     def forms_valid(self, form, formsets):
269 279
         """
270 280
         Save all changes and display a success url.

Loading…
İptal
Kaydet