Ticket #338: django-select-prepopulate.patch
File django-select-prepopulate.patch, 2.0 KB (added by , 19 years ago) |
---|
-
django/core/formfields.py
114 114 def __getitem__(self, key): 115 115 for field in self.manipulator.fields: 116 116 if field.field_name == key: 117 if hasattr(field, 'requires_data_list') and hasattr(self.data, 'getlist'): 118 data = self.data.getlist(field.field_name) 119 else: 120 data = self.data.get(field.field_name, None) 121 if data is None: 122 data = '' 123 return FormFieldWrapper(field, data, self.error_dict.get(field.field_name, [])) 117 118 data = field.extract_data(self.data) 119 120 return FormFieldWrapper(field, data, self.error_dict.get(field.field_name, [])) 124 121 raise KeyError 125 122 126 123 def has_errors(self): … … 137 134 return str(self.formfield.render(self.data)) 138 135 139 136 def __repr__(self): 140 return '<FormFieldWrapper for "%s">' % self.formfield.field_name 137 return '<FormFieldWrapper for "%s": %s >' % self.formfield.field_name, repr(self.data) 141 138 142 139 def field_list(self): 143 140 """ … … 209 206 def render(self, data): 210 207 raise NotImplementedError 211 208 209 def get_member_name(self): 210 return self.field_name 211 212 def extract_data(self, data_dict): 213 if hasattr(self, 'requires_data_list') and hasattr(data_dict, 'getlist'): 214 data = data_dict.getlist(self.get_member_name()) 215 else: 216 data = data_dict.get(self.get_member_name(), None) 217 if data is None: 218 data = '' 219 220 return data 221 212 222 #################### 213 223 # GENERIC WIDGETS # 214 224 #################### … … 319 329 output.append(' </select>') 320 330 return '\n'.join(output) 321 331 332 def get_member_name(self): 333 return "%s_id" % self.field_name 334 322 335 def isValidChoice(self, data, form): 323 336 str_data = str(data) 324 337 str_choices = [str(item[0]) for item in self.choices]