From 00bebaf0d1e6024c7a24a6132bf648c623290bfd Mon Sep 17 00:00:00 2001
From: Gary Wilson Jr <gary.wilson@gmail.com>
Date: Mon, 11 Aug 2008 04:28:33 +0000
Subject: [PATCH] Refs #7742 -- newforms-admin does not use oldforms
 `validator_list` argument, made a custom `FlatPageForm` to check the entered
 URL.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8292 bcc190cf-cafb-0310-a4f2-bffc1f526a37
---
 django/contrib/flatpages/admin.py  | 15 ++++++++++++++-
 django/contrib/flatpages/models.py |  5 ++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/django/contrib/flatpages/admin.py b/django/contrib/flatpages/admin.py
index 02bbaf6b1a..b6fdba3d53 100644
--- a/django/contrib/flatpages/admin.py
+++ b/django/contrib/flatpages/admin.py
@@ -1,9 +1,22 @@
+from django import forms
 from django.contrib import admin
 from django.contrib.flatpages.models import FlatPage
 from django.utils.translation import ugettext_lazy as _
 
 
+class FlatpageForm(forms.ModelForm):
+    url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/]+$',
+        help_text = _("Example: '/about/contact/'. Make sure to have leading"
+                      " and trailing slashes."),
+        error_message = _("This value must contain only letters, numbers,"
+                          " underscores, dashes or slashes."))
+
+    class Meta:
+        model = FlatPage
+
+
 class FlatPageAdmin(admin.ModelAdmin):
+    form = FlatpageForm
     fieldsets = (
         (None, {'fields': ('url', 'title', 'content', 'sites')}),
         (_('Advanced options'), {'classes': ('collapse',), 'fields': ('enable_comments', 'registration_required', 'template_name')}),
@@ -12,4 +25,4 @@ class FlatPageAdmin(admin.ModelAdmin):
     list_filter = ('sites', 'enable_comments', 'registration_required')
     search_fields = ('url', 'title')
 
-admin.site.register(FlatPage, FlatPageAdmin)
\ No newline at end of file
+admin.site.register(FlatPage, FlatPageAdmin)
diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
index 466425cb46..02005dd07d 100644
--- a/django/contrib/flatpages/models.py
+++ b/django/contrib/flatpages/models.py
@@ -5,8 +5,7 @@ from django.utils.translation import ugettext_lazy as _
 
 
 class FlatPage(models.Model):
-    url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
-        help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
+    url = models.CharField(_('URL'), max_length=100, db_index=True)
     title = models.CharField(_('title'), max_length=200)
     content = models.TextField(_('content'), blank=True)
     enable_comments = models.BooleanField(_('enable comments'))
@@ -20,7 +19,7 @@ class FlatPage(models.Model):
         verbose_name = _('flat page')
         verbose_name_plural = _('flat pages')
         ordering = ('url',)
-    
+
     def __unicode__(self):
         return u"%s -- %s" % (self.url, self.title)