web/formwidgets.py
changeset 2523 1d245fbbeb90
parent 2522 562f5dcf2345
child 2549 3d8c62e5e2d4
equal deleted inserted replaced
2522:562f5dcf2345 2523:1d245fbbeb90
   250     input will be generated for each possible value.
   250     input will be generated for each possible value.
   251     """
   251     """
   252     type = 'radio'
   252     type = 'radio'
   253 
   253 
   254 
   254 
       
   255 # compound widgets #############################################################
       
   256 
       
   257 class IntervalWidget(FieldWidget):
       
   258     """custom widget to display an interval composed by 2 fields. This widget
       
   259     is expected to be used with a CompoundField containing the two actual
       
   260     fields.
       
   261 
       
   262     Exemple usage::
       
   263 
       
   264 from uicfg import autoform_field, autoform_section
       
   265 autoform_field.tag_attribute(('Concert', 'minprice'),
       
   266                               CompoundField(fields=(IntField(name='minprice'),
       
   267                                                     IntField(name='maxprice')),
       
   268                                             label=_('price'),
       
   269                                             widget=IntervalWidget()
       
   270                                             ))
       
   271 # we've to hide the other field manually for now
       
   272 autoform_section.tag_attribute(('Concert', 'maxprice'), 'generated')
       
   273     """
       
   274     def render(self, form, field, renderer):
       
   275         actual_fields = field.fields
       
   276         assert len(actual_fields) == 2
       
   277         return u'<div>%s %s %s %s</div>' % (
       
   278             form.req._('from_interval_start'),
       
   279             actual_fields[0].render(form, renderer),
       
   280             form.req._('to_interval_end'),
       
   281             actual_fields[1].render(form, renderer),
       
   282             )
       
   283 
       
   284 
       
   285 class HorizontalLayoutWidget(FieldWidget):
       
   286     """custom widget to display a set of fields grouped together horizontally
       
   287     in a form. See `IntervalWidget` for example usage.
       
   288     """
       
   289     def render(self, form, field, renderer):
       
   290         if self.attrs.get('display_label', True):
       
   291             subst = self.attrs.get('label_input_substitution', '%(label)s %(input)s')
       
   292             fields = [subst % {'label': renderer.render_label(form, f),
       
   293                               'input': f.render(form, renderer)}
       
   294                       for f in field.fields]
       
   295         else:
       
   296             fields = [f.render(form, renderer) for f in field.fields]
       
   297         return u'<div>%s</div>' % ' '.join(fields)
       
   298 
       
   299 
   255 # javascript widgets ###########################################################
   300 # javascript widgets ###########################################################
   256 
   301 
   257 class DateTimePicker(TextInput):
   302 class DateTimePicker(TextInput):
   258     """<input type='text' + javascript date/time picker for date or datetime
   303     """<input type='text' + javascript date/time picker for date or datetime
   259     fields
   304     fields