def get_ratings(self): ratings_dict = { 'clarity': self.clarity.to_dict(), 'easiness': self.easiness.to_dict(), 'passion': self.passion.to_dict(), } ratings_dict['overall'] = _rating.get_overall_rating( ratings_dict.values()).to_dict() return util.dict_to_list(ratings_dict)
def get_ratings_for_course(self, course_id): rating_dict = {} for name in ['clarity', 'easiness', 'passion']: agg_rating = self.get_course_rating_from_redis(course_id, name) if agg_rating: rating_dict[name] = agg_rating.to_dict() rating_dict['overall'] = _rating.get_overall_rating( rating_dict.values()).to_dict() return util.dict_to_list(rating_dict)
def to_dict(self): """Returns information about a course to be sent down an API. Args: course: The course object. """ return { "id": self.id, "code": self.code, "name": self.name, "description": self.description, # TODO(mack): create user models for friends #'friends': [1647810326, 518430508, 541400376], "ratings": util.dict_to_list(self.get_ratings()), "overall": self.overall.to_dict(), "professor_ids": self.professor_ids, "prereqs": self.prereqs, }
def to_dict(self): """Returns information about a course to be sent down an API. Args: course: The course object. """ return { 'id': self.id, 'code': self.code, 'name': self.name, 'description': self.description, # TODO(mack): create user models for friends #'friends': [1647810326, 518430508, 541400376], 'ratings': util.dict_to_list(self.get_ratings()), 'overall': self.overall.to_dict(), 'professor_ids': self.professor_ids, 'prereqs': self.prereqs, }
def test_dict_to_list(self): self.assertEquals( [{'name': 'a', 'aprop': 1}, {'name': 'b', 'bprop': 2}], util.dict_to_list({'a': {'aprop': 1}, 'b': {'bprop': 2}}) )