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
This commit is contained in:
parent
ef48a3e69c
commit
00bebaf0d1
|
@ -1,9 +1,22 @@
|
||||||
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.flatpages.models import FlatPage
|
from django.contrib.flatpages.models import FlatPage
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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):
|
class FlatPageAdmin(admin.ModelAdmin):
|
||||||
|
form = FlatpageForm
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {'fields': ('url', 'title', 'content', 'sites')}),
|
(None, {'fields': ('url', 'title', 'content', 'sites')}),
|
||||||
(_('Advanced options'), {'classes': ('collapse',), 'fields': ('enable_comments', 'registration_required', 'template_name')}),
|
(_('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')
|
list_filter = ('sites', 'enable_comments', 'registration_required')
|
||||||
search_fields = ('url', 'title')
|
search_fields = ('url', 'title')
|
||||||
|
|
||||||
admin.site.register(FlatPage, FlatPageAdmin)
|
admin.site.register(FlatPage, FlatPageAdmin)
|
||||||
|
|
|
@ -5,8 +5,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class FlatPage(models.Model):
|
class FlatPage(models.Model):
|
||||||
url = models.CharField(_('URL'), max_length=100, validator_list=[validators.isAlphaNumericURL], db_index=True,
|
url = models.CharField(_('URL'), max_length=100, db_index=True)
|
||||||
help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes."))
|
|
||||||
title = models.CharField(_('title'), max_length=200)
|
title = models.CharField(_('title'), max_length=200)
|
||||||
content = models.TextField(_('content'), blank=True)
|
content = models.TextField(_('content'), blank=True)
|
||||||
enable_comments = models.BooleanField(_('enable comments'))
|
enable_comments = models.BooleanField(_('enable comments'))
|
||||||
|
@ -20,7 +19,7 @@ class FlatPage(models.Model):
|
||||||
verbose_name = _('flat page')
|
verbose_name = _('flat page')
|
||||||
verbose_name_plural = _('flat pages')
|
verbose_name_plural = _('flat pages')
|
||||||
ordering = ('url',)
|
ordering = ('url',)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u"%s -- %s" % (self.url, self.title)
|
return u"%s -- %s" % (self.url, self.title)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue