3 from floof
.lib
.dbhelpers
import find_or_create
, update_or_create
6 art
= ManyToOne('Art', ondelete
='cascade', required
=True)
7 rater
= ManyToOne('User', ondelete
='cascade', required
=True)
8 score
= Field(Integer
, required
=True)
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
,)