Skip to content

Commit

Permalink
Refs #7742 -- newforms-admin does not use oldforms validator_list a…
Browse files Browse the repository at this point in the history
…rgument, 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
  • Loading branch information
gdub committed Aug 11, 2008
1 parent ef48a3e commit 00bebaf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 14 additions & 1 deletion 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')}),
Expand All @@ -12,4 +25,4 @@ class FlatPageAdmin(admin.ModelAdmin):
list_filter = ('sites', 'enable_comments', 'registration_required')
search_fields = ('url', 'title')

admin.site.register(FlatPage, FlatPageAdmin)
admin.site.register(FlatPage, FlatPageAdmin)
5 changes: 2 additions & 3 deletions django/contrib/flatpages/models.py
Expand Up @@ -5,8 +5,7 @@


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'))
Expand All @@ -20,7 +19,7 @@ class Meta:
verbose_name = _('flat page')
verbose_name_plural = _('flat pages')
ordering = ('url',)

def __unicode__(self):
return u"%s -- %s" % (self.url, self.title)

Expand Down

0 comments on commit 00bebaf

Please sign in to comment.