mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
new-admin: Negligible formatting changes to django/core/formfields.py and fixed small bug in CheckboxSelectMultipleField.render()
git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@1417 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b413132dd5
commit
3b0f82ab8b
@ -98,7 +98,7 @@ class FormWrapper:
|
||||
This allows dictionary-style lookups of formfields. It also handles feeding
|
||||
prepopulated data and validation error messages to the formfield objects.
|
||||
"""
|
||||
def __init__(self, manipulator, data, error_dict, edit_inline = True):
|
||||
def __init__(self, manipulator, data, error_dict, edit_inline=True):
|
||||
self.manipulator, self.data = manipulator, data
|
||||
self.error_dict = error_dict
|
||||
self._inline_collections = None
|
||||
@ -109,7 +109,6 @@ class FormWrapper:
|
||||
|
||||
def __getitem__(self, key):
|
||||
for field in self.manipulator.fields:
|
||||
|
||||
if field.field_name == key:
|
||||
data = field.extract_data(self.data)
|
||||
return FormFieldWrapper(field, data, self.error_dict.get(field.field_name, []))
|
||||
@ -118,7 +117,7 @@ class FormWrapper:
|
||||
for inline_collection in self._inline_collections:
|
||||
if inline_collection.name == key:
|
||||
return inline_collection
|
||||
raise KeyError("Could not find Formfield or InlineObjectCollection named:%s" % key )
|
||||
raise KeyError, "Could not find Formfield or InlineObjectCollection named %r" % key
|
||||
|
||||
def fill_inline_collections(self):
|
||||
if not self._inline_collections:
|
||||
@ -152,7 +151,6 @@ class FormFieldWrapper:
|
||||
"Renders the field"
|
||||
return str(self.formfield.render(self.data))
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return '<FormFieldWrapper for "%s">' % self.formfield.field_name
|
||||
|
||||
@ -194,7 +192,7 @@ class FormFieldCollection(FormFieldWrapper):
|
||||
"Returns list of all errors in this collection's formfields"
|
||||
errors = []
|
||||
for field in self.formfield_dict.values():
|
||||
if(hasattr(field, 'errors') ):
|
||||
if hasattr(field, 'errors'):
|
||||
errors.extend(field.errors())
|
||||
return errors
|
||||
|
||||
@ -202,7 +200,7 @@ class FormFieldCollection(FormFieldWrapper):
|
||||
return bool(len(self.errors()))
|
||||
|
||||
def html_combined_error_list(self):
|
||||
return ''.join( [ field.html_error_list() for field in self.formfield_dict.values() if hasattr(field, 'errors')])
|
||||
return ''.join([field.html_error_list() for field in self.formfield_dict.values() if hasattr(field, 'errors')])
|
||||
|
||||
class InlineObjectCollection:
|
||||
"An object that acts like a list of form field collections."
|
||||
@ -243,7 +241,7 @@ class InlineObjectCollection:
|
||||
orig = hasattr(self.parent_manipulator, 'original_object') and self.parent_manipulator.original_object or None
|
||||
orig_list = self.rel_obj.get_list(orig)
|
||||
for i, instance in enumerate(orig_list):
|
||||
collection = {'original': instance }
|
||||
collection = {'original': instance}
|
||||
for f in self.rel_obj.editable_fields():
|
||||
for field_name in f.get_manipulator_field_names(''):
|
||||
full_field_name = '%s.%d.%s' % (var_name, i, field_name)
|
||||
@ -306,8 +304,7 @@ class FormField:
|
||||
if new_data.has_key(self.field_name):
|
||||
d = new_data.getlist(self.field_name)
|
||||
try:
|
||||
converted_data = [self.__class__.html2python(data)
|
||||
for data in d]
|
||||
converted_data = [self.__class__.html2python(data) for data in d]
|
||||
except ValueError:
|
||||
converted_data = d
|
||||
new_data.setlist(name, converted_data)
|
||||
@ -360,7 +357,7 @@ class TextField(FormField):
|
||||
html2python = staticmethod(html2python)
|
||||
|
||||
class PasswordField(TextField):
|
||||
input_type="password"
|
||||
input_type = "password"
|
||||
|
||||
class LargeTextField(TextField):
|
||||
def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=[], maxlength=None):
|
||||
@ -410,7 +407,6 @@ class CheckboxField(FormField):
|
||||
return False
|
||||
html2python = staticmethod(html2python)
|
||||
|
||||
|
||||
class SelectField(FormField):
|
||||
def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[], member_name=None):
|
||||
self.field_name = field_name
|
||||
@ -586,8 +582,8 @@ class CheckboxSelectMultipleField(SelectMultipleField):
|
||||
checked_html = ' checked="checked"'
|
||||
field_name = '%s%s' % (self.field_name, value)
|
||||
output.append('<li><input type="checkbox" id="%s" class="v%s" name="%s"%s /> <label for="%s">%s</label></li>' % \
|
||||
(get_id() + value , self.__class__.__name__, field_name, checked_html,
|
||||
get_id() + value, choice))
|
||||
(self.get_id() + value , self.__class__.__name__, field_name, checked_html,
|
||||
self.get_id() + value, choice))
|
||||
output.append('</ul>')
|
||||
return '\n'.join(output)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user