Просмотр исходного кода

Ensure promotions work correct with modified URL field

master
David Winterbottom 13 лет назад
Родитель
Сommit
6c549bcfa1
3 измененных файлов: 10 добавлений и 8 удалений
  1. 6
    7
      oscar/apps/dashboard/promotions/forms.py
  2. 2
    1
      oscar/apps/promotions/models.py
  3. 2
    0
      oscar/models/fields.py

+ 6
- 7
oscar/apps/dashboard/promotions/forms.py Просмотреть файл

@@ -5,7 +5,6 @@ from django.utils.translation import ugettext_lazy as _
5 5
 
6 6
 from oscar.forms.fields import ExtendedURLField
7 7
 from oscar.core.loading import get_classes
8
-from oscar.apps.promotions.conf import PROMOTION_CLASSES
9 8
 
10 9
 RawHTML, SingleProduct, PagePromotion, HandPickedProductList, OrderedProduct = get_classes('promotions.models',
11 10
     ['RawHTML', 'SingleProduct', 'PagePromotion', 'HandPickedProductList',
@@ -37,10 +36,11 @@ OrderedProductFormSet = inlineformset_factory(HandPickedProductList,
37 36
 
38 37
 
39 38
 class PagePromotionForm(forms.ModelForm):
40
-    page_url = ExtendedURLField(label=_("URL"))
41
-    position = forms.CharField(widget=forms.Select(choices=settings.OSCAR_PROMOTION_POSITIONS),
42
-                               label=_("Position"),
43
-                               help_text=_("Where in the page this content block will appear"))
39
+    page_url = ExtendedURLField(label=_("URL"), verify_exists=True)
40
+    position = forms.CharField(
41
+        widget=forms.Select(choices=settings.PROMOTION_POSITIONS),
42
+        label=_("Position"),
43
+        help_text=_("Where in the page this content block will appear"))
44 44
 
45 45
     class Meta:
46 46
         model = PagePromotion
@@ -49,7 +49,6 @@ class PagePromotionForm(forms.ModelForm):
49 49
     def clean_page_url(self):
50 50
         page_url = self.cleaned_data.get('page_url')
51 51
         if (page_url and page_url.startswith('/') and
52
-            not page_url.endswith('/')):
52
+                not page_url.endswith('/')):
53 53
             page_url += '/'
54 54
         return page_url
55
-

+ 2
- 1
oscar/apps/promotions/models.py Просмотреть файл

@@ -43,7 +43,8 @@ class PagePromotion(LinkedPromotion):
43 43
     """
44 44
     A promotion embedded on a particular page.
45 45
     """
46
-    page_url = ExtendedURLField(_('Page URL'), max_length=128, db_index=True)
46
+    page_url = ExtendedURLField(
47
+        _('Page URL'), max_length=128, db_index=True, verify_exists=True)
47 48
 
48 49
     def __unicode__(self):
49 50
         return u"%s on %s" % (self.content_object, self.page_url)

+ 2
- 0
oscar/models/fields.py Просмотреть файл

@@ -24,6 +24,7 @@ class ExtendedURLField(CharField):
24 24
         # 'verify_exists' was deprecated in Django 1.4. To ensure backwards
25 25
         # compatibility, it is still accepted here, but only passed
26 26
         # on to the parent class if it was specified.
27
+        self.verify_exists = verify_exists
27 28
         if verify_exists is not None:
28 29
             validator = validators.ExtendedURLValidator(
29 30
                 verify_exists=verify_exists)
@@ -36,6 +37,7 @@ class ExtendedURLField(CharField):
36 37
         # twice.
37 38
         defaults = {
38 39
             'form_class': fields.ExtendedURLField,
40
+            'verify_exists': self.verify_exists
39 41
         }
40 42
         defaults.update(kwargs)
41 43
         return super(ExtendedURLField, self).formfield(**defaults)

Загрузка…
Отмена
Сохранить