def award(self, **state):
     user = state["user"]
     ratings = total_ratings_by_user(user)
     if ratings >= 2:
         return BadgeAwarded(2)
     elif ratings >= 1:
         return BadgeAwarded(1)
 def award(self, **state):
     user = state['user']
     profile = user.get_profile()
     if profile.twitter_access_token and profile.facebook_access_token:
         return BadgeAwarded(level=2)
     if profile.twitter_access_token or profile.facebook_access_token:
         return BadgeAwarded(level=1)
 def award(self, **state):
     user = state['user']
     num_of_comments = Comment.objects.filter(user=user).count()
     if num_of_comments >= 15:
         return BadgeAwarded(level=3)
     elif num_of_comments >= 5:
         return BadgeAwarded(level=2)
     return BadgeAwarded(level=1)
 def award(self, **state):
     user = state['user']
     num_of_surveys = ContributorSurvey.objects.filter(entered_by=user).count()
     if num_of_surveys >= 30:
         return BadgeAwarded(level=3)
     elif num_of_surveys >= 15:
         return BadgeAwarded(level=2)
     elif num_of_surveys >= 5:
         return BadgeAwarded(level=1)
Esempio n. 5
0
 def award(self, **state):
     user = state["user"]
     points = user.stats.points
     if points > 10000:
         return BadgeAwarded(3)
     elif points > 7500:
         return BadgeAwarded(2)
     elif points > 5000:
         return BadgeAwarded(1)
 def award(self, **state):
     user = state["user"]
     likes = total_likes_by_user(user)
     if likes >= 500:
         return BadgeAwarded(3)
     elif likes >= 200:
         return BadgeAwarded(2)
     elif likes >= 100:
         return BadgeAwarded(1)
 def award(self, **state):
     user = state['user']
     num_dogged_actions = UserActionProgress.objects.filter(user=user, is_completed=True,
             date_committed__isnull=False).count()
     if num_dogged_actions >= 5:
         return BadgeAwarded(level=3)
     elif num_dogged_actions >= 3:
         return BadgeAwarded(level=2)
     elif num_dogged_actions:
         return BadgeAwarded(level=1)
Esempio n. 8
0
	def award(self, **state):
		user = state['user']
		runs = user.profile.completions
		if runs > 5000:
			return BadgeAwarded(level=4)
		if runs > 1000:
			return BadgeAwarded(level=3)
		if runs > 100:
			return BadgeAwarded(level=2)
		return BadgeAwarded(level=1)
 def award(self, **state):
     user = state["user"]
     likes = total_likes_by_user(user)
     if likes >= 7:
         return BadgeAwarded(5)  # skip a level to make it more interesting
     if likes >= 5:
         return BadgeAwarded(3)
     elif likes >= 2:
         return BadgeAwarded(2)
     elif likes >= 1:
         return BadgeAwarded(1)
    def award(self, **state):
        user = state["user"]
        questions = Question.objects.filter(author=user).count()

        if questions >= 1000:
            return BadgeAwarded(4)
        elif questions >= 500:
            return BadgeAwarded(3)
        elif questions >= 400:
            return BadgeAwarded(2)
        elif questions >= 300:
            return BadgeAwarded(1)
Esempio n. 11
0
	def award(self, **state):
		user = state['user']
		runtime = user.profile.runtime
		# a day
		if runtime > 86400:
			return BadgeAwarded(level=3)
		# 10 hours
		if runtime > 36000:
			return BadgeAwarded(level=2)
		# 1 hour
		if runtime > 3600:
			return BadgeAwarded(level=1)
Esempio n. 12
0
    def award(self, **state):
        user=state["user"]

        # Returns the highest level achieved by this user for each badge slug, as a dictionary {slug : max_level} 
        achieved = {x['slug'] : x['max_level'] for x in BadgeAward.objects.filter(user=user).values('slug').annotate(max_level=Max('level'))}

        for i, r in enumerate(self.requirements):
            if not all([slug in achieved and achieved[slug] >= r[slug] for slug in r]):
                if i > 0:
                    return BadgeAwarded(i)
                else:
                    return
        return BadgeAwarded(len(self.requirements))
Esempio n. 13
0
	def award(self, **state):
		run = state['run']
		time = run.time
		after_dec_point = time % 1 # 7.148 -> 0.148
		if after_dec_point == Decimal('0.999'):
			return BadgeAwarded(level=1)
		if after_dec_point == Decimal('0.777'):
			return BadgeAwarded(level=2)
		if after_dec_point == Decimal('0.666'):
			return BadgeAwarded(level=3)
		if after_dec_point == Decimal('0.000'):
			return BadgeAwarded(level=4)
		if time == Decimal('3.142'):
			return BadgeAwarded(level=5)
Esempio n. 14
0
 def award(self, **state):
     user = state["user"]
     assert (len(all_donations_by_user(user)) == 0) == (
         total_donation_amount(user) == 0
     ), "Total donation amount is zero if and only if there are no donations"
     if total_donation_amount(user) > 0:
         return BadgeAwarded(1)
 def award(self, **state):
     if not self.action:
         raise NotImplementedError('%s can not be used as a badge' % self.__class__)
     user = state['user']
     if UserActionProgress.objects.filter(user=user, action=self.action,
             is_completed=True).exists():
         return BadgeAwarded()
Esempio n. 16
0
	def award(self, **state):
		user = state['user']
		maps = Map.objects.values_list('name', flat=True)
		maps_finished = Run.objects.filter(user=user).values_list('map__name',
			flat=True).distinct()
		# check if maps equals to maps_finished
		if set(maps_finished).issuperset(maps):
			return BadgeAwarded(level=1)
Esempio n. 17
0
	def award(self, **state):
		user = state['user']
		if user.is_staff or user.is_superuser:
			return BadgeAwarded(level=1)
Esempio n. 18
0
 def award(self, **state):
     user = get_object_or_404(User, username=state["user"].username)
     if user.get_profile().votePoints == 1:
         return BadgeAwarded()
Esempio n. 19
0
	def award(self, **state):
		user = state['user']
		if user.profile.position == 1:
			return BadgeAwarded(level=1)
Esempio n. 20
0
 def award(self, **state):
     user = get_object_or_404(User, username=state["user"].username)
     recipes = user.recipes_submitted.all()
     if len(recipes) == 1:
         return BadgeAwarded()
 def award(self, **state):
     user = state['user']
     num_of_actions = Action.objects.all().count()
     num_of_completed = UserActionProgress.objects.filter(user=user, is_completed=True)
     if num_of_actions == num_of_completed:
         return BadgeAwarded()
Esempio n. 22
0
 def award(self, **state):
     user = get_object_or_404(User, username=state["user"].username)
     if state["award"] == "ing3":
         return BadgeAwarded()
 def award(self, **state):
     return BadgeAwarded()