1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +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:
Adrian Holovaty 2005-11-25 02:02:53 +00:00
parent b413132dd5
commit 3b0f82ab8b

View File

@ -98,7 +98,7 @@ class FormWrapper:
This allows dictionary-style lookups of formfields. It also handles feeding This allows dictionary-style lookups of formfields. It also handles feeding
prepopulated data and validation error messages to the formfield objects. 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.manipulator, self.data = manipulator, data
self.error_dict = error_dict self.error_dict = error_dict
self._inline_collections = None self._inline_collections = None
@ -109,7 +109,6 @@ class FormWrapper:
def __getitem__(self, key): def __getitem__(self, key):
for field in self.manipulator.fields: for field in self.manipulator.fields:
if field.field_name == key: if field.field_name == key:
data = field.extract_data(self.data) data = field.extract_data(self.data)
return FormFieldWrapper(field, data, self.error_dict.get(field.field_name, [])) return FormFieldWrapper(field, data, self.error_dict.get(field.field_name, []))
@ -118,7 +117,7 @@ class FormWrapper:
for inline_collection in self._inline_collections: for inline_collection in self._inline_collections:
if inline_collection.name == key: if inline_collection.name == key:
return inline_collection 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): def fill_inline_collections(self):
if not self._inline_collections: if not self._inline_collections:
@ -152,7 +151,6 @@ class FormFieldWrapper:
"Renders the field" "Renders the field"
return str(self.formfield.render(self.data)) return str(self.formfield.render(self.data))
def __repr__(self): def __repr__(self):
return '<FormFieldWrapper for "%s">' % self.formfield.field_name 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" "Returns list of all errors in this collection's formfields"
errors = [] errors = []
for field in self.formfield_dict.values(): for field in self.formfield_dict.values():
if(hasattr(field, 'errors') ): if hasattr(field, 'errors'):
errors.extend(field.errors()) errors.extend(field.errors())
return errors return errors
@ -202,11 +200,11 @@ class FormFieldCollection(FormFieldWrapper):
return bool(len(self.errors())) return bool(len(self.errors()))
def html_combined_error_list(self): 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: class InlineObjectCollection:
"An object that acts like a list of form field collections." "An object that acts like a list of form field collections."
def __init__(self, parent_manipulator, rel_obj, data, errors): def __init__(self, parent_manipulator, rel_obj, data, errors):
self.parent_manipulator = parent_manipulator self.parent_manipulator = parent_manipulator
self.rel_obj = rel_obj self.rel_obj = rel_obj
self.data = data self.data = data
@ -243,7 +241,7 @@ class InlineObjectCollection:
orig = hasattr(self.parent_manipulator, 'original_object') and self.parent_manipulator.original_object or None orig = hasattr(self.parent_manipulator, 'original_object') and self.parent_manipulator.original_object or None
orig_list = self.rel_obj.get_list(orig) orig_list = self.rel_obj.get_list(orig)
for i, instance in enumerate(orig_list): for i, instance in enumerate(orig_list):
collection = {'original': instance } collection = {'original': instance}
for f in self.rel_obj.editable_fields(): for f in self.rel_obj.editable_fields():
for field_name in f.get_manipulator_field_names(''): for field_name in f.get_manipulator_field_names(''):
full_field_name = '%s.%d.%s' % (var_name, i, field_name) 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): if new_data.has_key(self.field_name):
d = new_data.getlist(self.field_name) d = new_data.getlist(self.field_name)
try: try:
converted_data = [self.__class__.html2python(data) converted_data = [self.__class__.html2python(data) for data in d]
for data in d]
except ValueError: except ValueError:
converted_data = d converted_data = d
new_data.setlist(name, converted_data) new_data.setlist(name, converted_data)
@ -360,7 +357,7 @@ class TextField(FormField):
html2python = staticmethod(html2python) html2python = staticmethod(html2python)
class PasswordField(TextField): class PasswordField(TextField):
input_type="password" input_type = "password"
class LargeTextField(TextField): class LargeTextField(TextField):
def __init__(self, field_name, rows=10, cols=40, is_required=False, validator_list=[], maxlength=None): 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 return False
html2python = staticmethod(html2python) html2python = staticmethod(html2python)
class SelectField(FormField): class SelectField(FormField):
def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[], member_name=None): def __init__(self, field_name, choices=[], size=1, is_required=False, validator_list=[], member_name=None):
self.field_name = field_name self.field_name = field_name
@ -586,8 +582,8 @@ class CheckboxSelectMultipleField(SelectMultipleField):
checked_html = ' checked="checked"' checked_html = ' checked="checked"'
field_name = '%s%s' % (self.field_name, value) 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>' % \ 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, (self.get_id() + value , self.__class__.__name__, field_name, checked_html,
get_id() + value, choice)) self.get_id() + value, choice))
output.append('</ul>') output.append('</ul>')
return '\n'.join(output) return '\n'.join(output)