Ticket #3025: newforms_autoid.patch
File newforms_autoid.patch, 1.3 KB (added by , 18 years ago) |
---|
-
django/newforms/forms.py
22 22 class Form(object): 23 23 "A collection of Fields, plus their associated data." 24 24 __metaclass__ = DeclarativeFieldsMetaclass 25 26 auto_id = None 25 27 26 28 def __init__(self, data=None): # TODO: prefix stuff 27 29 self.data = data or {} … … 156 158 errors = property(_errors) 157 159 158 160 def as_widget(self, widget, attrs=None): 161 attrs = attrs or {} 162 if attrs and not attrs.has_key('id') and self.auto_id: 163 attrs['id'] = self.auto_id 159 164 return widget.render(self._name, self._form.data.get(self._name, None), attrs=attrs) 160 165 161 166 def as_text(self, attrs=None): … … 167 172 def as_textarea(self, attrs=None): 168 173 "Returns a string of HTML for representing this as a <textarea>." 169 174 return self.as_widget(Textarea(), attrs) 175 176 def _auto_id(self): 177 auto_id = self._form.auto_id 178 if auto_id and self._name: 179 if '%s' in auto_id: 180 auto_id = auto_id * self._name 181 else: 182 return self._name 183 return '' 184 auto_id = property(_auto_id) 185 No newline at end of file