1) Download the jQuery star rating widget from here
2) Extract the files to web2py/applications/your_app/static/stars folder
3) Include the necessary files in your app's web2py_ajax.html file:
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js" type="text/javascript"></script>
<script src="{{=URL(r=request,c='static/stars',f='ui.stars.js')}}" type="text/javascript"></script>
<link href="{{=URL(r=request,c='static/stars',f='ui.stars.css')}}" rel="stylesheet" type="text/css" media="screen" charset="utf-8" />
4) Add this to the end of the web2py_ajax_init function:
jQuery("#stars-wrapper").stars({inputType: "select"});
5) Create your widget function in db.py and apply it to your rating field:
def rating_widget(f,v):
from gluon.sqlhtml import OptionsWidget
return DIV(SPAN(_id="stars-cap"), DIV(OptionsWidget.widget(f,v),_id="stars-wrapper"))
db.define_table('test',Field('rating','integer'))
db.test.rating.requires = IS_IN_SET(range(0,6))
db.test.rating.widget = rating_widget
6) Try displaying a SQLFORM(db.test). It should appear as a star rating widget.
Note: A similar method can be used to make a represents function for when the rating should be read only. Also, the widget can be ajaxified by looking into the available callback in the stars plugin.
Comments (3)
0
mandriluy 13 years ago
0
select 15 years ago
0
select 15 years ago