Ticket #12972: flatpages_admin_trunk.diff
File flatpages_admin_trunk.diff, 2.1 KB (added by , 15 years ago) |
---|
-
django/contrib/flatpages/admin.py
3 3 from django.contrib.flatpages.models import FlatPage 4 4 from django.utils.translation import ugettext_lazy as _ 5 5 6 from django.conf import settings 6 7 8 URL_REGEX = r'^/[-\w/]+$' 9 if settings.APPEND_SLASH and 'django.middleware.common.CommonMiddleware' in settings.MIDDLEWARE_CLASSES: 10 URL_REGEX = r'^/[-\w/]+/$' 11 7 12 class FlatpageForm(forms.ModelForm): 8 url = forms.RegexField(label=_("URL"), max_length=100, regex= r'^[-\w/]+$',13 url = forms.RegexField(label=_("URL"), max_length=100, regex=URL_REGEX, 9 14 help_text = _("Example: '/about/contact/'. Make sure to have leading" 10 15 " and trailing slashes."), 11 16 error_message = _("This value must contain only letters, numbers," -
tests/regressiontests/flatpage_tests/tests.py
1 # -*- coding: utf-8 -*- 2 from django.test import TestCase 3 from django.core.exceptions import ValidationError 4 from django.contrib.flatpages.admin import FlatpageForm 5 6 urltest = FlatpageForm.base_fields['url'].clean 7 8 class FlatpageTests(TestCase): 9 10 def testURLValidation(self): 11 PASS = ('/some/page/', '/about/', 12 '/cheese/shoppe/comments/') 13 FAIL = ('white space', 'bad&char', '/trailing/slash', 14 'leading/slash/', 'noslashes') 15 for url in PASS: 16 self.assertEquals(urltest(url), url) 17 for url in FAIL: 18 self.assertRaises(ValidationError, urltest, url) 19