Beispiel #1
0
    def rate(route_id, score):
        assert isinstance(route_id, ObjectId)
        route = RouteHelper.get(route_id)
        assert route
        assert isinstance(score, int)

        rate_info = RateInfo.objects(Q(route=route_id) & Q(user=current_user.id)).first()
        if rate_info:
            rate_info.score = score
            rate_info.save()
        else:
            rate_info = RateInfo()
            rate_info.route = route_id
            rate_info.user = current_user.id
            rate_info.score = score
            rate_info.save()

        RouteHelper._recalculate_avg(route_id)