6b5850aa588ec213df8feba5ce923cc978b430d2
3 from floof
.lib
.dbhelpers
import find_or_create
, update_or_create
6 art
= ManyToOne('Art', ondelete
='cascade')
7 rater
= ManyToOne('User', ondelete
='cascade')
10 options
= {-1:"sucks", 0:"undecided", 1:"good", 2:"great"}
13 Rating
.reverse_options
= dict (zip(Rating
.options
.values(), Rating
.options
.keys()))
16 class RatingMixin(object):
17 def rate(self
, score
, user
):
18 return update_or_create(Rating
, {"rater":user
, "art":self
}, {"score":score
})
20 def user_score(self
, user
):
21 rating
= Rating
.get_by(rater
=user
, art
=self
)
26 Art
.__bases__
+= (RatingMixin
,)