Copied django.forms to django.oldforms and changed all code to reference django.oldforms instead of django.forms. Updated docs/forms.txt to add 'Forwards-compatibility' section that says you should not be using django.oldforms for any new projects.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4208 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
06a5370e6a
commit
706fcec164
|
@ -2,7 +2,7 @@ from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django import forms, template
|
from django import oldforms, template
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ def user_add_stage(request):
|
||||||
return HttpResponseRedirect('../%s/' % new_user.id)
|
return HttpResponseRedirect('../%s/' % new_user.id)
|
||||||
else:
|
else:
|
||||||
errors = new_data = {}
|
errors = new_data = {}
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = oldforms.FormWrapper(manipulator, new_data, errors)
|
||||||
return render_to_response('admin/auth/user/add_form.html', {
|
return render_to_response('admin/auth/user/add_form.html', {
|
||||||
'title': _('Add user'),
|
'title': _('Add user'),
|
||||||
'form': form,
|
'form': form,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from django import forms, template
|
from django import oldforms, template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.admin.filterspecs import FilterSpec
|
from django.contrib.admin.filterspecs import FilterSpec
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
|
@ -283,7 +283,7 @@ def add_stage(request, app_label, model_name, show_delete=False, form_url='', po
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
# Populate the FormWrapper.
|
# Populate the FormWrapper.
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = oldforms.FormWrapper(manipulator, new_data, errors)
|
||||||
|
|
||||||
c = template.RequestContext(request, {
|
c = template.RequestContext(request, {
|
||||||
'title': _('Add %s') % opts.verbose_name,
|
'title': _('Add %s') % opts.verbose_name,
|
||||||
|
@ -374,7 +374,7 @@ def change_stage(request, app_label, model_name, object_id):
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
# Populate the FormWrapper.
|
# Populate the FormWrapper.
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = oldforms.FormWrapper(manipulator, new_data, errors)
|
||||||
form.original = manipulator.original_object
|
form.original = manipulator.original_object
|
||||||
form.order_objects = []
|
form.order_objects = []
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import template, forms
|
from django import template, oldforms
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
@ -25,17 +25,17 @@ def template_validator(request):
|
||||||
request.user.message_set.create(message='The template is valid.')
|
request.user.message_set.create(message='The template is valid.')
|
||||||
return render_to_response('admin/template_validator.html', {
|
return render_to_response('admin/template_validator.html', {
|
||||||
'title': 'Template validator',
|
'title': 'Template validator',
|
||||||
'form': forms.FormWrapper(manipulator, new_data, errors),
|
'form': oldforms.FormWrapper(manipulator, new_data, errors),
|
||||||
}, context_instance=template.RequestContext(request))
|
}, context_instance=template.RequestContext(request))
|
||||||
template_validator = staff_member_required(template_validator)
|
template_validator = staff_member_required(template_validator)
|
||||||
|
|
||||||
class TemplateValidator(forms.Manipulator):
|
class TemplateValidator(oldforms.Manipulator):
|
||||||
def __init__(self, settings_modules):
|
def __init__(self, settings_modules):
|
||||||
self.settings_modules = settings_modules
|
self.settings_modules = settings_modules
|
||||||
site_list = Site.objects.in_bulk(settings_modules.keys()).values()
|
site_list = Site.objects.in_bulk(settings_modules.keys()).values()
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.SelectField('site', is_required=True, choices=[(s.id, s.name) for s in site_list]),
|
oldforms.SelectField('site', is_required=True, choices=[(s.id, s.name) for s in site_list]),
|
||||||
forms.LargeTextField('template', is_required=True, rows=25, validator_list=[self.isValidTemplate]),
|
oldforms.LargeTextField('template', is_required=True, rows=25, validator_list=[self.isValidTemplate]),
|
||||||
)
|
)
|
||||||
|
|
||||||
def isValidTemplate(self, field_data, all_data):
|
def isValidTemplate(self, field_data, all_data):
|
||||||
|
|
|
@ -3,16 +3,16 @@ from django.contrib.auth import authenticate
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import oldforms
|
||||||
|
|
||||||
class UserCreationForm(forms.Manipulator):
|
class UserCreationForm(oldforms.Manipulator):
|
||||||
"A form that creates a user, with no privileges, from the given username and password."
|
"A form that creates a user, with no privileges, from the given username and password."
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
|
oldforms.TextField(field_name='username', length=30, maxlength=30, is_required=True,
|
||||||
validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
|
validator_list=[validators.isAlphaNumeric, self.isValidUsername]),
|
||||||
forms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
|
oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True),
|
||||||
forms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
|
oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True,
|
||||||
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
|
validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class UserCreationForm(forms.Manipulator):
|
||||||
"Creates the user."
|
"Creates the user."
|
||||||
return User.objects.create_user(new_data['username'], '', new_data['password1'])
|
return User.objects.create_user(new_data['username'], '', new_data['password1'])
|
||||||
|
|
||||||
class AuthenticationForm(forms.Manipulator):
|
class AuthenticationForm(oldforms.Manipulator):
|
||||||
"""
|
"""
|
||||||
Base class for authenticating users. Extend this to get a form that accepts
|
Base class for authenticating users. Extend this to get a form that accepts
|
||||||
username/password logins.
|
username/password logins.
|
||||||
|
@ -41,9 +41,9 @@ class AuthenticationForm(forms.Manipulator):
|
||||||
"""
|
"""
|
||||||
self.request = request
|
self.request = request
|
||||||
self.fields = [
|
self.fields = [
|
||||||
forms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
|
oldforms.TextField(field_name="username", length=15, maxlength=30, is_required=True,
|
||||||
validator_list=[self.isValidUser, self.hasCookiesEnabled]),
|
validator_list=[self.isValidUser, self.hasCookiesEnabled]),
|
||||||
forms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
|
oldforms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True),
|
||||||
]
|
]
|
||||||
self.user_cache = None
|
self.user_cache = None
|
||||||
|
|
||||||
|
@ -68,11 +68,11 @@ class AuthenticationForm(forms.Manipulator):
|
||||||
def get_user(self):
|
def get_user(self):
|
||||||
return self.user_cache
|
return self.user_cache
|
||||||
|
|
||||||
class PasswordResetForm(forms.Manipulator):
|
class PasswordResetForm(oldforms.Manipulator):
|
||||||
"A form that lets a user request a password reset"
|
"A form that lets a user request a password reset"
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.EmailField(field_name="email", length=40, is_required=True,
|
oldforms.EmailField(field_name="email", length=40, is_required=True,
|
||||||
validator_list=[self.isValidUserEmail]),
|
validator_list=[self.isValidUserEmail]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,16 +105,16 @@ class PasswordResetForm(forms.Manipulator):
|
||||||
}
|
}
|
||||||
send_mail('Password reset on %s' % site_name, t.render(Context(c)), None, [self.user_cache.email])
|
send_mail('Password reset on %s' % site_name, t.render(Context(c)), None, [self.user_cache.email])
|
||||||
|
|
||||||
class PasswordChangeForm(forms.Manipulator):
|
class PasswordChangeForm(oldforms.Manipulator):
|
||||||
"A form that lets a user change his password."
|
"A form that lets a user change his password."
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
self.user = user
|
self.user = user
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
|
oldforms.PasswordField(field_name="old_password", length=30, maxlength=30, is_required=True,
|
||||||
validator_list=[self.isValidOldPassword]),
|
validator_list=[self.isValidOldPassword]),
|
||||||
forms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
|
oldforms.PasswordField(field_name="new_password1", length=30, maxlength=30, is_required=True,
|
||||||
validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
|
validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]),
|
||||||
forms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
|
oldforms.PasswordField(field_name="new_password2", length=30, maxlength=30, is_required=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
def isValidOldPassword(self, new_data, all_data):
|
def isValidOldPassword(self, new_data, all_data):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm
|
from django.contrib.auth.forms import PasswordResetForm, PasswordChangeForm
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
@ -26,7 +26,7 @@ def login(request, template_name='registration/login.html'):
|
||||||
errors = {}
|
errors = {}
|
||||||
request.session.set_test_cookie()
|
request.session.set_test_cookie()
|
||||||
return render_to_response(template_name, {
|
return render_to_response(template_name, {
|
||||||
'form': forms.FormWrapper(manipulator, request.POST, errors),
|
'form': oldforms.FormWrapper(manipulator, request.POST, errors),
|
||||||
REDIRECT_FIELD_NAME: redirect_to,
|
REDIRECT_FIELD_NAME: redirect_to,
|
||||||
'site_name': Site.objects.get_current().name,
|
'site_name': Site.objects.get_current().name,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
@ -62,7 +62,7 @@ def password_reset(request, is_admin_site=False, template_name='registration/pas
|
||||||
else:
|
else:
|
||||||
form.save(email_template_name=email_template_name)
|
form.save(email_template_name=email_template_name)
|
||||||
return HttpResponseRedirect('%sdone/' % request.path)
|
return HttpResponseRedirect('%sdone/' % request.path)
|
||||||
return render_to_response(template_name, {'form': forms.FormWrapper(form, new_data, errors)},
|
return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
def password_reset_done(request, template_name='registration/password_reset_done.html'):
|
def password_reset_done(request, template_name='registration/password_reset_done.html'):
|
||||||
|
@ -77,7 +77,7 @@ def password_change(request, template_name='registration/password_change_form.ht
|
||||||
if not errors:
|
if not errors:
|
||||||
form.save(new_data)
|
form.save(new_data)
|
||||||
return HttpResponseRedirect('%sdone/' % request.path)
|
return HttpResponseRedirect('%sdone/' % request.path)
|
||||||
return render_to_response(template_name, {'form': forms.FormWrapper(form, new_data, errors)},
|
return render_to_response(template_name, {'form': oldforms.FormWrapper(form, new_data, errors)},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
password_change = login_required(password_change)
|
password_change = login_required(password_change)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.core.mail import mail_admins, mail_managers
|
from django.core.mail import mail_admins, mail_managers
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
@ -28,37 +28,37 @@ class PublicCommentManipulator(AuthenticationForm):
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
self.fields.extend([
|
self.fields.extend([
|
||||||
forms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
|
oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
|
||||||
validator_list=[self.hasNoProfanities]),
|
validator_list=[self.hasNoProfanities]),
|
||||||
forms.RadioSelectField(field_name="rating1", choices=choices,
|
oldforms.RadioSelectField(field_name="rating1", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 0,
|
is_required=ratings_required and num_rating_choices > 0,
|
||||||
validator_list=get_validator_list(1),
|
validator_list=get_validator_list(1),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating2", choices=choices,
|
oldforms.RadioSelectField(field_name="rating2", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 1,
|
is_required=ratings_required and num_rating_choices > 1,
|
||||||
validator_list=get_validator_list(2),
|
validator_list=get_validator_list(2),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating3", choices=choices,
|
oldforms.RadioSelectField(field_name="rating3", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 2,
|
is_required=ratings_required and num_rating_choices > 2,
|
||||||
validator_list=get_validator_list(3),
|
validator_list=get_validator_list(3),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating4", choices=choices,
|
oldforms.RadioSelectField(field_name="rating4", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 3,
|
is_required=ratings_required and num_rating_choices > 3,
|
||||||
validator_list=get_validator_list(4),
|
validator_list=get_validator_list(4),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating5", choices=choices,
|
oldforms.RadioSelectField(field_name="rating5", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 4,
|
is_required=ratings_required and num_rating_choices > 4,
|
||||||
validator_list=get_validator_list(5),
|
validator_list=get_validator_list(5),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating6", choices=choices,
|
oldforms.RadioSelectField(field_name="rating6", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 5,
|
is_required=ratings_required and num_rating_choices > 5,
|
||||||
validator_list=get_validator_list(6),
|
validator_list=get_validator_list(6),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating7", choices=choices,
|
oldforms.RadioSelectField(field_name="rating7", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 6,
|
is_required=ratings_required and num_rating_choices > 6,
|
||||||
validator_list=get_validator_list(7),
|
validator_list=get_validator_list(7),
|
||||||
),
|
),
|
||||||
forms.RadioSelectField(field_name="rating8", choices=choices,
|
oldforms.RadioSelectField(field_name="rating8", choices=choices,
|
||||||
is_required=ratings_required and num_rating_choices > 7,
|
is_required=ratings_required and num_rating_choices > 7,
|
||||||
validator_list=get_validator_list(8),
|
validator_list=get_validator_list(8),
|
||||||
),
|
),
|
||||||
|
@ -117,13 +117,13 @@ class PublicCommentManipulator(AuthenticationForm):
|
||||||
mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text())
|
mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text())
|
||||||
return c
|
return c
|
||||||
|
|
||||||
class PublicFreeCommentManipulator(forms.Manipulator):
|
class PublicFreeCommentManipulator(oldforms.Manipulator):
|
||||||
"Manipulator that handles public free (unregistered) comments"
|
"Manipulator that handles public free (unregistered) comments"
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.fields = (
|
self.fields = (
|
||||||
forms.TextField(field_name="person_name", maxlength=50, is_required=True,
|
oldforms.TextField(field_name="person_name", maxlength=50, is_required=True,
|
||||||
validator_list=[self.hasNoProfanities]),
|
validator_list=[self.hasNoProfanities]),
|
||||||
forms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
|
oldforms.LargeTextField(field_name="comment", maxlength=3000, is_required=True,
|
||||||
validator_list=[self.hasNoProfanities]),
|
validator_list=[self.hasNoProfanities]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -221,9 +221,9 @@ def post_comment(request):
|
||||||
from django.contrib.auth import login
|
from django.contrib.auth import login
|
||||||
login(request, manipulator.get_user())
|
login(request, manipulator.get_user())
|
||||||
if errors or request.POST.has_key('preview'):
|
if errors or request.POST.has_key('preview'):
|
||||||
class CommentFormWrapper(forms.FormWrapper):
|
class CommentFormWrapper(oldforms.FormWrapper):
|
||||||
def __init__(self, manipulator, new_data, errors, rating_choices):
|
def __init__(self, manipulator, new_data, errors, rating_choices):
|
||||||
forms.FormWrapper.__init__(self, manipulator, new_data, errors)
|
oldforms.FormWrapper.__init__(self, manipulator, new_data, errors)
|
||||||
self.rating_choices = rating_choices
|
self.rating_choices = rating_choices
|
||||||
def ratings(self):
|
def ratings(self):
|
||||||
field_list = [self['rating%d' % (i+1)] for i in range(len(rating_choices))]
|
field_list = [self['rating%d' % (i+1)] for i in range(len(rating_choices))]
|
||||||
|
@ -302,7 +302,7 @@ def post_free_comment(request):
|
||||||
comment = errors and '' or manipulator.get_comment(new_data)
|
comment = errors and '' or manipulator.get_comment(new_data)
|
||||||
return render_to_response('comments/free_preview.html', {
|
return render_to_response('comments/free_preview.html', {
|
||||||
'comment': comment,
|
'comment': comment,
|
||||||
'comment_form': forms.FormWrapper(manipulator, new_data, errors),
|
'comment_form': oldforms.FormWrapper(manipulator, new_data, errors),
|
||||||
'options': options,
|
'options': options,
|
||||||
'target': target,
|
'target': target,
|
||||||
'hash': security_hash,
|
'hash': security_hash,
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.db.models import signals
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.utils.itercompat import tee
|
from django.utils.itercompat import tee
|
||||||
|
@ -206,10 +206,10 @@ class Field(object):
|
||||||
|
|
||||||
if self.choices:
|
if self.choices:
|
||||||
if self.radio_admin:
|
if self.radio_admin:
|
||||||
field_objs = [forms.RadioSelectField]
|
field_objs = [oldforms.RadioSelectField]
|
||||||
params['ul_class'] = get_ul_class(self.radio_admin)
|
params['ul_class'] = get_ul_class(self.radio_admin)
|
||||||
else:
|
else:
|
||||||
field_objs = [forms.SelectField]
|
field_objs = [oldforms.SelectField]
|
||||||
|
|
||||||
params['choices'] = self.get_choices_default()
|
params['choices'] = self.get_choices_default()
|
||||||
else:
|
else:
|
||||||
|
@ -218,7 +218,7 @@ class Field(object):
|
||||||
|
|
||||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
||||||
"""
|
"""
|
||||||
Returns a list of forms.FormField instances for this field. It
|
Returns a list of oldforms.FormField instances for this field. It
|
||||||
calculates the choices at runtime, not at compile time.
|
calculates the choices at runtime, not at compile time.
|
||||||
|
|
||||||
name_prefix is a prefix to prepend to the "field_name" argument.
|
name_prefix is a prefix to prepend to the "field_name" argument.
|
||||||
|
@ -360,7 +360,7 @@ class AutoField(Field):
|
||||||
return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel, follow)
|
return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel, follow)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.HiddenField]
|
return [oldforms.HiddenField]
|
||||||
|
|
||||||
def get_manipulator_new_data(self, new_data, rel=False):
|
def get_manipulator_new_data(self, new_data, rel=False):
|
||||||
# Never going to be called
|
# Never going to be called
|
||||||
|
@ -387,11 +387,11 @@ class BooleanField(Field):
|
||||||
raise validators.ValidationError, gettext("This value must be either True or False.")
|
raise validators.ValidationError, gettext("This value must be either True or False.")
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.CheckboxField]
|
return [oldforms.CheckboxField]
|
||||||
|
|
||||||
class CharField(Field):
|
class CharField(Field):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.TextField]
|
return [oldforms.TextField]
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
if isinstance(value, basestring):
|
if isinstance(value, basestring):
|
||||||
|
@ -406,7 +406,7 @@ class CharField(Field):
|
||||||
# TODO: Maybe move this into contrib, because it's specialized.
|
# TODO: Maybe move this into contrib, because it's specialized.
|
||||||
class CommaSeparatedIntegerField(CharField):
|
class CommaSeparatedIntegerField(CharField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.CommaSeparatedIntegerField]
|
return [oldforms.CommaSeparatedIntegerField]
|
||||||
|
|
||||||
class DateField(Field):
|
class DateField(Field):
|
||||||
empty_strings_allowed = False
|
empty_strings_allowed = False
|
||||||
|
@ -468,7 +468,7 @@ class DateField(Field):
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.DateField]
|
return [oldforms.DateField]
|
||||||
|
|
||||||
def flatten_data(self, follow, obj = None):
|
def flatten_data(self, follow, obj = None):
|
||||||
val = self._get_val_from_obj(obj)
|
val = self._get_val_from_obj(obj)
|
||||||
|
@ -509,7 +509,7 @@ class DateTimeField(DateField):
|
||||||
return Field.get_db_prep_lookup(self, lookup_type, value)
|
return Field.get_db_prep_lookup(self, lookup_type, value)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.DateField, forms.TimeField]
|
return [oldforms.DateField, oldforms.TimeField]
|
||||||
|
|
||||||
def get_manipulator_field_names(self, name_prefix):
|
def get_manipulator_field_names(self, name_prefix):
|
||||||
return [name_prefix + self.name + '_date', name_prefix + self.name + '_time']
|
return [name_prefix + self.name + '_date', name_prefix + self.name + '_time']
|
||||||
|
@ -541,7 +541,7 @@ class EmailField(CharField):
|
||||||
return "CharField"
|
return "CharField"
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.EmailField]
|
return [oldforms.EmailField]
|
||||||
|
|
||||||
def validate(self, field_data, all_data):
|
def validate(self, field_data, all_data):
|
||||||
validators.isValidEmail(field_data, all_data)
|
validators.isValidEmail(field_data, all_data)
|
||||||
|
@ -605,7 +605,7 @@ class FileField(Field):
|
||||||
os.remove(file_name)
|
os.remove(file_name)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.FileUploadField, forms.HiddenField]
|
return [oldforms.FileUploadField, oldforms.HiddenField]
|
||||||
|
|
||||||
def get_manipulator_field_names(self, name_prefix):
|
def get_manipulator_field_names(self, name_prefix):
|
||||||
return [name_prefix + self.name + '_file', name_prefix + self.name]
|
return [name_prefix + self.name + '_file', name_prefix + self.name]
|
||||||
|
@ -633,7 +633,7 @@ class FilePathField(Field):
|
||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [curry(forms.FilePathField, path=self.path, match=self.match, recursive=self.recursive)]
|
return [curry(oldforms.FilePathField, path=self.path, match=self.match, recursive=self.recursive)]
|
||||||
|
|
||||||
class FloatField(Field):
|
class FloatField(Field):
|
||||||
empty_strings_allowed = False
|
empty_strings_allowed = False
|
||||||
|
@ -642,7 +642,7 @@ class FloatField(Field):
|
||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [curry(forms.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
|
return [curry(oldforms.FloatField, max_digits=self.max_digits, decimal_places=self.decimal_places)]
|
||||||
|
|
||||||
class ImageField(FileField):
|
class ImageField(FileField):
|
||||||
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
|
def __init__(self, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
|
||||||
|
@ -650,7 +650,7 @@ class ImageField(FileField):
|
||||||
FileField.__init__(self, verbose_name, name, **kwargs)
|
FileField.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.ImageUploadField, forms.HiddenField]
|
return [oldforms.ImageUploadField, oldforms.HiddenField]
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
super(ImageField, self).contribute_to_class(cls, name)
|
super(ImageField, self).contribute_to_class(cls, name)
|
||||||
|
@ -676,7 +676,7 @@ class ImageField(FileField):
|
||||||
class IntegerField(Field):
|
class IntegerField(Field):
|
||||||
empty_strings_allowed = False
|
empty_strings_allowed = False
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.IntegerField]
|
return [oldforms.IntegerField]
|
||||||
|
|
||||||
class IPAddressField(Field):
|
class IPAddressField(Field):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -684,7 +684,7 @@ class IPAddressField(Field):
|
||||||
Field.__init__(self, *args, **kwargs)
|
Field.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.IPAddressField]
|
return [oldforms.IPAddressField]
|
||||||
|
|
||||||
def validate(self, field_data, all_data):
|
def validate(self, field_data, all_data):
|
||||||
validators.isValidIPAddress4(field_data, None)
|
validators.isValidIPAddress4(field_data, None)
|
||||||
|
@ -695,22 +695,22 @@ class NullBooleanField(Field):
|
||||||
Field.__init__(self, *args, **kwargs)
|
Field.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.NullBooleanField]
|
return [oldforms.NullBooleanField]
|
||||||
|
|
||||||
class PhoneNumberField(IntegerField):
|
class PhoneNumberField(IntegerField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.PhoneNumberField]
|
return [oldforms.PhoneNumberField]
|
||||||
|
|
||||||
def validate(self, field_data, all_data):
|
def validate(self, field_data, all_data):
|
||||||
validators.isValidPhone(field_data, all_data)
|
validators.isValidPhone(field_data, all_data)
|
||||||
|
|
||||||
class PositiveIntegerField(IntegerField):
|
class PositiveIntegerField(IntegerField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.PositiveIntegerField]
|
return [oldforms.PositiveIntegerField]
|
||||||
|
|
||||||
class PositiveSmallIntegerField(IntegerField):
|
class PositiveSmallIntegerField(IntegerField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.PositiveSmallIntegerField]
|
return [oldforms.PositiveSmallIntegerField]
|
||||||
|
|
||||||
class SlugField(Field):
|
class SlugField(Field):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -722,15 +722,15 @@ class SlugField(Field):
|
||||||
Field.__init__(self, *args, **kwargs)
|
Field.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.TextField]
|
return [oldforms.TextField]
|
||||||
|
|
||||||
class SmallIntegerField(IntegerField):
|
class SmallIntegerField(IntegerField):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.SmallIntegerField]
|
return [oldforms.SmallIntegerField]
|
||||||
|
|
||||||
class TextField(Field):
|
class TextField(Field):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.LargeTextField]
|
return [oldforms.LargeTextField]
|
||||||
|
|
||||||
class TimeField(Field):
|
class TimeField(Field):
|
||||||
empty_strings_allowed = False
|
empty_strings_allowed = False
|
||||||
|
@ -766,7 +766,7 @@ class TimeField(Field):
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.TimeField]
|
return [oldforms.TimeField]
|
||||||
|
|
||||||
def flatten_data(self,follow, obj = None):
|
def flatten_data(self,follow, obj = None):
|
||||||
val = self._get_val_from_obj(obj)
|
val = self._get_val_from_obj(obj)
|
||||||
|
@ -779,11 +779,11 @@ class URLField(Field):
|
||||||
Field.__init__(self, verbose_name, name, **kwargs)
|
Field.__init__(self, verbose_name, name, **kwargs)
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.URLField]
|
return [oldforms.URLField]
|
||||||
|
|
||||||
class USStateField(Field):
|
class USStateField(Field):
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [forms.USStateField]
|
return [oldforms.USStateField]
|
||||||
|
|
||||||
class XMLField(TextField):
|
class XMLField(TextField):
|
||||||
def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
|
def __init__(self, verbose_name=None, name=None, schema_path=None, **kwargs):
|
||||||
|
@ -794,7 +794,7 @@ class XMLField(TextField):
|
||||||
return "TextField"
|
return "TextField"
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
return [curry(forms.XMLLargeTextField, schema_path=self.schema_path)]
|
return [curry(oldforms.XMLLargeTextField, schema_path=self.schema_path)]
|
||||||
|
|
||||||
class OrderingField(IntegerField):
|
class OrderingField(IntegerField):
|
||||||
empty_strings_allowed=False
|
empty_strings_allowed=False
|
||||||
|
@ -807,4 +807,4 @@ class OrderingField(IntegerField):
|
||||||
return "IntegerField"
|
return "IntegerField"
|
||||||
|
|
||||||
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
|
||||||
return [forms.HiddenField(name_prefix + self.name)]
|
return [oldforms.HiddenField(name_prefix + self.name)]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Classes allowing "generic" relations through ContentType and object-id fields.
|
Classes allowing "generic" relations through ContentType and object-id fields.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db import backend
|
from django.db import backend
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
|
@ -98,7 +98,7 @@ class GenericRelation(RelatedField, Field):
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
choices = self.get_choices_default()
|
choices = self.get_choices_default()
|
||||||
return [curry(forms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
|
return [curry(oldforms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
|
||||||
|
|
||||||
def get_choices_default(self):
|
def get_choices_default(self):
|
||||||
return Field.get_choices(self, include_blank=False)
|
return Field.get_choices(self, include_blank=False)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.db.models.related import RelatedObject
|
||||||
from django.utils.translation import gettext_lazy, string_concat, ngettext
|
from django.utils.translation import gettext_lazy, string_concat, ngettext
|
||||||
from django.utils.functional import curry
|
from django.utils.functional import curry
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
|
|
||||||
# For Python 2.3
|
# For Python 2.3
|
||||||
|
@ -493,13 +493,13 @@ class ForeignKey(RelatedField, Field):
|
||||||
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
||||||
else:
|
else:
|
||||||
if self.radio_admin:
|
if self.radio_admin:
|
||||||
field_objs = [forms.RadioSelectField]
|
field_objs = [oldforms.RadioSelectField]
|
||||||
params['ul_class'] = get_ul_class(self.radio_admin)
|
params['ul_class'] = get_ul_class(self.radio_admin)
|
||||||
else:
|
else:
|
||||||
if self.null:
|
if self.null:
|
||||||
field_objs = [forms.NullSelectField]
|
field_objs = [oldforms.NullSelectField]
|
||||||
else:
|
else:
|
||||||
field_objs = [forms.SelectField]
|
field_objs = [oldforms.SelectField]
|
||||||
params['choices'] = self.get_choices_default()
|
params['choices'] = self.get_choices_default()
|
||||||
return field_objs, params
|
return field_objs, params
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ class ForeignKey(RelatedField, Field):
|
||||||
if self.rel.raw_id_admin and not isinstance(rel_field, AutoField):
|
if self.rel.raw_id_admin and not isinstance(rel_field, AutoField):
|
||||||
return rel_field.get_manipulator_field_objs()
|
return rel_field.get_manipulator_field_objs()
|
||||||
else:
|
else:
|
||||||
return [forms.IntegerField]
|
return [oldforms.IntegerField]
|
||||||
|
|
||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
if value == '' or value == None:
|
if value == '' or value == None:
|
||||||
|
@ -581,13 +581,13 @@ class OneToOneField(RelatedField, IntegerField):
|
||||||
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
params['validator_list'].append(curry(manipulator_valid_rel_key, self, manipulator))
|
||||||
else:
|
else:
|
||||||
if self.radio_admin:
|
if self.radio_admin:
|
||||||
field_objs = [forms.RadioSelectField]
|
field_objs = [oldforms.RadioSelectField]
|
||||||
params['ul_class'] = get_ul_class(self.radio_admin)
|
params['ul_class'] = get_ul_class(self.radio_admin)
|
||||||
else:
|
else:
|
||||||
if self.null:
|
if self.null:
|
||||||
field_objs = [forms.NullSelectField]
|
field_objs = [oldforms.NullSelectField]
|
||||||
else:
|
else:
|
||||||
field_objs = [forms.SelectField]
|
field_objs = [oldforms.SelectField]
|
||||||
params['choices'] = self.get_choices_default()
|
params['choices'] = self.get_choices_default()
|
||||||
return field_objs, params
|
return field_objs, params
|
||||||
|
|
||||||
|
@ -622,10 +622,10 @@ class ManyToManyField(RelatedField, Field):
|
||||||
|
|
||||||
def get_manipulator_field_objs(self):
|
def get_manipulator_field_objs(self):
|
||||||
if self.rel.raw_id_admin:
|
if self.rel.raw_id_admin:
|
||||||
return [forms.RawIdAdminField]
|
return [oldforms.RawIdAdminField]
|
||||||
else:
|
else:
|
||||||
choices = self.get_choices_default()
|
choices = self.get_choices_default()
|
||||||
return [curry(forms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
|
return [curry(oldforms.SelectMultipleField, size=min(max(len(choices), 5), 15), choices=choices)]
|
||||||
|
|
||||||
def get_choices_default(self):
|
def get_choices_default(self):
|
||||||
return Field.get_choices(self, include_blank=False)
|
return Field.get_choices(self, include_blank=False)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.db.models.fields import FileField, AutoField
|
from django.db.models.fields import FileField, AutoField
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
|
@ -40,7 +40,7 @@ class ManipulatorDescriptor(object):
|
||||||
self.man._prepare(model)
|
self.man._prepare(model)
|
||||||
return self.man
|
return self.man
|
||||||
|
|
||||||
class AutomaticManipulator(forms.Manipulator):
|
class AutomaticManipulator(oldforms.Manipulator):
|
||||||
def _prepare(cls, model):
|
def _prepare(cls, model):
|
||||||
cls.model = model
|
cls.model = model
|
||||||
cls.manager = model._default_manager
|
cls.manager = model._default_manager
|
||||||
|
@ -76,7 +76,7 @@ class AutomaticManipulator(forms.Manipulator):
|
||||||
|
|
||||||
# Add field for ordering.
|
# Add field for ordering.
|
||||||
if self.change and self.opts.get_ordered_objects():
|
if self.change and self.opts.get_ordered_objects():
|
||||||
self.fields.append(forms.CommaSeparatedIntegerField(field_name="order_"))
|
self.fields.append(oldforms.CommaSeparatedIntegerField(field_name="order_"))
|
||||||
|
|
||||||
def save(self, new_data):
|
def save(self, new_data):
|
||||||
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
# TODO: big cleanup when core fields go -> use recursive manipulators.
|
||||||
|
@ -308,7 +308,7 @@ def manipulator_validator_unique_together(field_name_list, opts, self, field_dat
|
||||||
def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_type, self, field_data, all_data):
|
def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_type, self, field_data, all_data):
|
||||||
from django.db.models.fields.related import ManyToOneRel
|
from django.db.models.fields.related import ManyToOneRel
|
||||||
date_str = all_data.get(date_field.get_manipulator_field_names('')[0], None)
|
date_str = all_data.get(date_field.get_manipulator_field_names('')[0], None)
|
||||||
date_val = forms.DateField.html2python(date_str)
|
date_val = oldforms.DateField.html2python(date_str)
|
||||||
if date_val is None:
|
if date_val is None:
|
||||||
return # Date was invalid. This will be caught by another validator.
|
return # Date was invalid. This will be caught by another validator.
|
||||||
lookup_kwargs = {'%s__year' % date_field.name: date_val.year}
|
lookup_kwargs = {'%s__year' % date_field.name: date_val.year}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
||||||
from django.core.xheaders import populate_xheaders
|
from django.core.xheaders import populate_xheaders
|
||||||
from django.template import loader
|
from django.template import loader
|
||||||
from django import forms
|
from django import oldforms
|
||||||
from django.db.models import FileField
|
from django.db.models import FileField
|
||||||
from django.contrib.auth.views import redirect_to_login
|
from django.contrib.auth.views import redirect_to_login
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
|
@ -56,7 +56,7 @@ def create_object(request, model, template_name=None,
|
||||||
new_data = manipulator.flatten_data()
|
new_data = manipulator.flatten_data()
|
||||||
|
|
||||||
# Create the FormWrapper, template, context, response
|
# Create the FormWrapper, template, context, response
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = oldforms.FormWrapper(manipulator, new_data, errors)
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
|
@ -128,7 +128,7 @@ def update_object(request, model, object_id=None, slug=None,
|
||||||
# This makes sure the form acurate represents the fields of the place.
|
# This makes sure the form acurate represents the fields of the place.
|
||||||
new_data = manipulator.flatten_data()
|
new_data = manipulator.flatten_data()
|
||||||
|
|
||||||
form = forms.FormWrapper(manipulator, new_data, errors)
|
form = oldforms.FormWrapper(manipulator, new_data, errors)
|
||||||
if not template_name:
|
if not template_name:
|
||||||
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
template_name = "%s/%s_form.html" % (model._meta.app_label, model._meta.object_name.lower())
|
||||||
t = template_loader.get_template(template_name)
|
t = template_loader.get_template(template_name)
|
||||||
|
|
|
@ -2,15 +2,27 @@
|
||||||
Forms, fields, and manipulators
|
Forms, fields, and manipulators
|
||||||
===============================
|
===============================
|
||||||
|
|
||||||
|
Forwards-compatibility note
|
||||||
|
===========================
|
||||||
|
|
||||||
|
The legacy forms/manipulators system described in this document is going to be
|
||||||
|
replaced in the next Django release. If you're starting from scratch, we
|
||||||
|
strongly encourage you not to waste your time learning this. Instead, learn and
|
||||||
|
use the django.newforms system, which we have begun to document in the
|
||||||
|
`newforms documentation`_.
|
||||||
|
|
||||||
|
If you have legacy form/manipulator code, read the "Migration plan" section in
|
||||||
|
that document to understand how we're making the switch.
|
||||||
|
|
||||||
|
.. _newforms documentation: http://www.djangoproject.com/documentation/newforms/
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
============
|
||||||
|
|
||||||
Once you've got a chance to play with Django's admin interface, you'll probably
|
Once you've got a chance to play with Django's admin interface, you'll probably
|
||||||
wonder if the fantastic form validation framework it uses is available to user
|
wonder if the fantastic form validation framework it uses is available to user
|
||||||
code. It is, and this document explains how the framework works.
|
code. It is, and this document explains how the framework works.
|
||||||
|
|
||||||
.. admonition:: A note to the lazy
|
|
||||||
|
|
||||||
If all you want to do is present forms for a user to create and/or
|
|
||||||
update a given object, you may be able to use `generic views`_.
|
|
||||||
|
|
||||||
We'll take a top-down approach to examining Django's form validation framework,
|
We'll take a top-down approach to examining Django's form validation framework,
|
||||||
because much of the time you won't need to use the lower-level APIs. Throughout
|
because much of the time you won't need to use the lower-level APIs. Throughout
|
||||||
this document, we'll be working with the following model, a "place" object::
|
this document, we'll be working with the following model, a "place" object::
|
||||||
|
@ -41,17 +53,17 @@ this document, we'll be working with the following model, a "place" object::
|
||||||
Defining the above class is enough to create an admin interface to a ``Place``,
|
Defining the above class is enough to create an admin interface to a ``Place``,
|
||||||
but what if you want to allow public users to submit places?
|
but what if you want to allow public users to submit places?
|
||||||
|
|
||||||
Manipulators
|
Automatic Manipulators
|
||||||
============
|
======================
|
||||||
|
|
||||||
The highest-level interface for object creation and modification is the
|
The highest-level interface for object creation and modification is the
|
||||||
**Manipulator** framework. A manipulator is a utility class tied to a given
|
**automatic Manipulator** framework. An automatic manipulator is a utility
|
||||||
model that "knows" how to create or modify instances of that model and how to
|
class tied to a given model that "knows" how to create or modify instances of
|
||||||
validate data for the object. Manipulators come in two flavors:
|
that model and how to validate data for the object. Automatic Manipulators come
|
||||||
``AddManipulators`` and ``ChangeManipulators``. Functionally they are quite
|
in two flavors: ``AddManipulators`` and ``ChangeManipulators``. Functionally
|
||||||
similar, but the former knows how to create new instances of the model, while
|
they are quite similar, but the former knows how to create new instances of the
|
||||||
the latter modifies existing instances. Both types of classes are automatically
|
model, while the latter modifies existing instances. Both types of classes are
|
||||||
created when you define a new class::
|
automatically created when you define a new class::
|
||||||
|
|
||||||
>>> from mysite.myapp.models import Place
|
>>> from mysite.myapp.models import Place
|
||||||
>>> Place.AddManipulator
|
>>> Place.AddManipulator
|
||||||
|
|
|
@ -902,7 +902,7 @@ If ``template_name`` isn't specified, this view will use the template
|
||||||
|
|
||||||
In addition to ``extra_context``, the template's context will be:
|
In addition to ``extra_context``, the template's context will be:
|
||||||
|
|
||||||
* ``form``: A ``django.forms.FormWrapper`` instance representing the form
|
* ``form``: A ``django.oldforms.FormWrapper`` instance representing the form
|
||||||
for editing the object. This lets you refer to form fields easily in the
|
for editing the object. This lets you refer to form fields easily in the
|
||||||
template system.
|
template system.
|
||||||
|
|
||||||
|
@ -984,7 +984,7 @@ If ``template_name`` isn't specified, this view will use the template
|
||||||
|
|
||||||
In addition to ``extra_context``, the template's context will be:
|
In addition to ``extra_context``, the template's context will be:
|
||||||
|
|
||||||
* ``form``: A ``django.forms.FormWrapper`` instance representing the form
|
* ``form``: A ``django.oldforms.FormWrapper`` instance representing the form
|
||||||
for editing the object. This lets you refer to form fields easily in the
|
for editing the object. This lets you refer to form fields easily in the
|
||||||
template system.
|
template system.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue