Ticket #5917: newforms.extra.widgets.py.2.diff
File newforms.extra.widgets.py.2.diff, 2.0 KB (added by , 17 years ago) |
---|
-
widgets.py
old new 30 30 self.years = range(this_year, this_year+10) 31 31 32 32 def render(self, name, value, attrs=None): 33 34 has_id = attrs and 'id' in attrs 35 final_attrs = self.build_attrs(attrs, name=name) 36 37 def select_id(name_field): 38 if has_id: return dict(final_attrs, id=name_field % attrs['id']) 39 else: return None 40 33 41 try: 34 value = datetime.date(*map(int, value.split('-'))) 42 if type(value) == type(u''): 43 value = datetime.date(*map(int, value.split('-'))) 35 44 year_val, month_val, day_val = value.year, value.month, value.day 36 45 except (AttributeError, TypeError, ValueError): 37 46 year_val = month_val = day_val = None 38 47 39 48 output = [] 40 49 50 print self.month_field % u'ntsf' 51 41 52 month_choices = MONTHS.items() 42 53 month_choices.sort() 43 select_html = Select(choices=month_choices).render(self.month_field % name, month_val) 54 select_html = Select(select_id(self.month_field), 55 choices=month_choices).render(self.month_field % name, month_val) 44 56 output.append(select_html) 45 57 46 58 day_choices = [(i, i) for i in range(1, 32)] 47 select_html = Select(choices=day_choices).render(self.day_field % name, day_val) 59 select_html = Select(select_id(self.month_field), 60 choices=day_choices).render(self.day_field % name, day_val) 48 61 output.append(select_html) 49 62 50 63 year_choices = [(i, i) for i in self.years] 51 select_html = Select(choices=year_choices).render(self.year_field % name, year_val) 64 select_html = Select(select_id(self.year_field), 65 choices=year_choices).render(self.year_field % name, year_val) 52 66 output.append(select_html) 53 67 54 68 return u'\n'.join(output)