def testPopularActivities(self): """Check which activity is the most popular.""" activity_member = ActionMember(user=self.user, action=self.activity) activity_member.approval_status = "approved" activity_member.save() activities = smartgrid.get_popular_actions("activity", "approved") self.assertEqual(activities[0].title, self.activity.title)
def testPopularCommitments(self): """Tests that we can retrieve the most popular commitments.""" commitment_member = ActionMember(user=self.user, action=self.commitment) commitment_member.award_date = datetime.datetime.today() commitment_member.approval_status = "approved" commitment_member.save() commitments = smartgrid.get_popular_actions("commitment", "approved") self.assertEqual(commitments[0].title, self.commitment.title) self.assertEqual(commitments[0].completions, 1, "Most popular commitment should have one completion.")
def supply(request, page_name): """Supply view_objects content, which are the popular actions from the smart grid game.""" _ = request num_results = 5 if page_name != "status" else None #contruct a dictionary containing the most popular tasks. #The keys are the type of the task and the values are a list of tasks.""" popular_tasks = { "Activity": smartgrid.get_popular_actions("activity", "approved", num_results), "Commitment": smartgrid.get_popular_actions("commitment", "approved", num_results), "Event": smartgrid.get_popular_actions("event", "pending", num_results), "Excursion": smartgrid.get_popular_actions("excursion", "pending", num_results), } count = len(popular_tasks) return { "popular_tasks": popular_tasks, "no_carousel": page_name == "status", "range": count, }