Hello again.
I looked at the rating widget in T2 and T3 (they seem essentially
identical), but I am not familiar enough with web2py to transplant
them. It looks like there is more than just the widget involved, it
looks there there is some jquery to it?
In any case I wanted to share the solution I have come up with for
now, which is working reasonably for me. I have modified the radio
widget to do what I need:
class RatingWidget(OptionsWidget):
@staticmethod
def widget(field, value, **attributes):
"""
generates a TABLE tag, including INPUT radios (only 1 option
allowed)
see also: :meth:`FormWidget.widget`
"""
attr = OptionsWidget._attributes(field, {}, **attributes)
if isinstance(field.requires, IS_NULL_OR)\
and hasattr(field.requires.other, 'options'):
opts = [TD(INPUT(_type='radio', _name=field.name,
_value='', value=value), '')]
options = field.requires.other.options()
elif hasattr(field.requires, 'options'):
opts = []
options = field.requires.options()
else:
raise SyntaxError, 'widget cannot determine options of %s'
% field
opts += [TD(INPUT(_type='radio', _name=field.name,
_value=k, value=value), '') for (k, v) in
options]
return TABLE(TR(*(['low']+opts+['high'])), **attr)
This works for now, but could obviously still be improved. My first
thoughts are to get rid of the IS_NULL_OR logic, and replace it with
code that verifies the options are somehow ordinal in nature. It would
also be good to generate a relevant mouseover for each option. I will
post again if I extend this further.
For now I have another question. Right now this class is living in my
application's modules/widgets.py, and I am importing via
applications.appname.modules.widgets. Is this the right/sensible thing
to do?
Thank you to everyone that posted with advice.
Cheers
Marco
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---