Django

Code

Show
Ignore:
Timestamp:
03/22/08 14:20:19 (10 months ago)
Author:
jkocherhans
Message:

newforms-admin: Merged from trunk up to [7350].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7232 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7350
  • django/branches/newforms-admin/django/newforms/extras/widgets.py

    r6777 r7351  
    44 
    55import datetime 
     6import re 
    67 
    78from django.newforms.widgets import Widget, Select 
     
    1011 
    1112__all__ = ('SelectDateWidget',) 
     13 
     14RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$') 
    1215 
    1316class SelectDateWidget(Widget): 
     
    3336    def render(self, name, value, attrs=None): 
    3437        try: 
    35             value = datetime.date(*map(int, value.split('-'))) 
    3638            year_val, month_val, day_val = value.year, value.month, value.day 
    37         except (AttributeError, TypeError, ValueError)
     39        except AttributeError
    3840            year_val = month_val = day_val = None 
     41            if isinstance(value, basestring): 
     42                match = RE_DATE.match(value) 
     43                if match: 
     44                    year_val, month_val, day_val = [int(v) for v in match.groups()] 
    3945 
    4046        output = [] 
    4147 
     48        if 'id' in self.attrs: 
     49            id_ = self.attrs['id'] 
     50        else: 
     51            id_ = 'id_%s' % name 
     52 
    4253        month_choices = MONTHS.items() 
    4354        month_choices.sort() 
    44         select_html = Select(choices=month_choices).render(self.month_field % name, month_val) 
     55        local_attrs = self.build_attrs(id=self.month_field % id_) 
     56        select_html = Select(choices=month_choices).render(self.month_field % name, month_val, local_attrs) 
    4557        output.append(select_html) 
    4658 
    4759        day_choices = [(i, i) for i in range(1, 32)] 
    48         select_html = Select(choices=day_choices).render(self.day_field % name, day_val) 
     60        local_attrs['id'] = self.day_field % id_ 
     61        select_html = Select(choices=day_choices).render(self.day_field % name, day_val, local_attrs) 
    4962        output.append(select_html) 
    5063 
    5164        year_choices = [(i, i) for i in self.years] 
    52         select_html = Select(choices=year_choices).render(self.year_field % name, year_val) 
     65        local_attrs['id'] = self.year_field % id_ 
     66        select_html = Select(choices=year_choices).render(self.year_field % name, year_val, local_attrs) 
    5367        output.append(select_html) 
    5468 
    5569        return mark_safe(u'\n'.join(output)) 
     70 
     71    def id_for_label(self, id_): 
     72        return '%s_month' % id_ 
     73    id_for_label = classmethod(id_for_label) 
    5674 
    5775    def value_from_datadict(self, data, files, name):