def stars(identifier, value): if isinstance(value, float): return {"class":get_rating_stars_class(value), "identifier": identifier} else: ratings = value count = ratings.count() value = 0.0 if count: value = ratings.aggregate(rating=Avg("value"))["rating"] return {"class":get_rating_stars_class(value), "rating_value": "%0.1f" % value, "rating_count": count, "identifier": identifier}
def rate(request): if not request.is_ajax(): raise Http404() form = RatingForm(request.REQUEST, user=request.user) if form.is_valid(): form.save() return dict(status="success", stars_class=get_rating_stars_class(form.instance.rating), message=u"Your rating was saved.") else: return dict(status="error", message=u"There was a problem with saving your rate.")