On Saturday 31 October 2009 07:40:05 David wrote:
> I would like to have reusable ratings (typical layout with 5 stars). I
> have found this http://www.thebroth.com/blog/119/css-rating-stars that
> explains how to display this using css. For actually collecting the
> rating I was thinking of using an image map or maybe simple radio
> buttons. I would like to use this on various different models.
> 
> How would you do this? Shall I create a widget or can I do this with a
> template? Actually I was pretty surprised not to find anything on this
> on the web. Is it that simple, or uncommon?
> 

Well you can create a widget, I like a seperate rating model myself.  That 
collects the value and then adds that to a total and creates a score or 
average.  The model stores the total votes and the total score, which I divide 
and get my average, (I do the math in the view).  Adding it to other models 
with a foreign key relation.  Enforcing that users vote only once is rarely 
enforced outside of the current session or cookie lifetime.   If you want it 
persistance, I'm notfgv6gw33TT   sure off the top of my head what is best for 
this, but would require only registered users vote.

Now, you just display the rating form, I would do it as a template inclusion 
tag and put the tag in my templates.  This tag has the basic submit form, the 
form it's self is two fields, with a select box (I went simple this way) and a 
hidden field labeled next that points back to this page, that I can redirect 
to. When the user submits, in my views to handle the forms action, I just 
increment the votes and total score and redirect back to the page the vote was 
taken on.  This is using the traditional submit button, posting the form to a 
url, returning a full view.

If you do something with javascript that illuminates the number of stars for 
the rating and click on the stars to submit, here you might want to post it as 
json object using xhr request, update the view and return a json object with 
the updated rating values, if it's a 200, update the page with the new values 
after voting (returned with the 200).  If it's a 500, deal with the error, 
letting the user know, there was a problem voting and reset the stars.

This is what I do, or would do in your position, if anyone has a better idea, 
please speak up.

Hope this helps.

Mike

-- 
Didn't I buy a 1951 Packard from you last March in Cairo?

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to