Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def award(self, **state):
     user = state["user"]
     points = user.get_profile().ayah_points
     if points > 10:
         return BadgeAwarded(level=1)
     elif points > 50:
         return BadgeAwarded(level=2)
     elif points > 100:
         return BadgeAwarded(level=3)
     elif points > 500:
         return BadgeAwarded(level=4)
Exemplo n.º 4
0
 def award(self, **state):
     user = state["user"]
     vote_count = Vote.objects.filter(author=user).count()
     if vote_count >= 120:
         return BadgeAwarded(level=4)
     elif vote_count >= 80:
         return BadgeAwarded(level=3)
     elif vote_count >= 40:
         return BadgeAwarded(level=2)
     elif vote_count >= 3:
         return BadgeAwarded(level=1)
Exemplo n.º 5
0
 def award(self, **state):
     user = state["user"]
     points = user.profile.points
     if points > 20:
         return BadgeAwarded(level=4)
     elif points > 15:
         return BadgeAwarded(level=3)
     elif points > 5:
         return BadgeAwarded(level=2)
     elif points > 0:
         return BadgeAwarded(level=1)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def award(self, **state):
     user = state["user"]
     print(user.username)
     points = user.username
     if points:
         return BadgeAwarded(level=3)
     if points > 10000:
         return BadgeAwarded(level=3)
     elif points > 7500:
         return BadgeAwarded(level=2)
     elif points > 0:
         return BadgeAwarded(level=1)
Exemplo n.º 8
0
 def award(self, **state):
     user = state["user"]
     points = user.get_profile().login_points
     if points > 3:
         return BadgeAwarded(level=1)
     elif points > 7:
         return BadgeAwarded(level=2)
     elif points > 30:
         return BadgeAwarded(level=3)
     elif points > 180:
         return BadgeAwarded(level=4)
     elif points > 365:
         return BadgeAwarded(level=5)
Exemplo n.º 9
0
 def award(self, **state):
     run = state["run"]
     time = run.time
     remainder = time % 1  # 7.148 -> 0.148
     remainder_map = {
         Decimal("0.999"): BadgeAwarded(level=1),
         Decimal("0.777"): BadgeAwarded(level=2),
         Decimal("0.666"): BadgeAwarded(level=3),
         Decimal("0.000"): BadgeAwarded(level=4),
     }
     remainder_award = remainder_map.get(remainder)
     if remainder_award:
         return remainder_award
     if time == Decimal("3.142"):
         return BadgeAwarded(level=5)
Exemplo n.º 10
0
 def award(self, user, **state):
     """ Should this badge be awarded? This is part of the pinax-badges API
     and is called by `possibly_award`.
     """
     if self.can_award(user, **state):
         self.grant(user)
         return BadgeAwarded()
Exemplo n.º 11
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)
Exemplo n.º 12
0
    def award(self, **state):
        award_level = 0

        user = state["user"]
        votes_list = [
            Vote.objects.filter(comment__conversation=c, author=user).count()
            for c in Conversation.objects.all()
        ]

        # If the user has any number of votes in at least two conversations, give him the level 1
        if sum(i > 0 for i in votes_list) >= 2:
            award_level = 1

        # major_participations stores the number of conversations in wich the user voted 30 or more times
        major_participations = sum([i >= 30 for i in votes_list])
        award_level = award_level + major_participations

        # Ensure that you'll never award a level that is not set yet
        available_levels = len(KnowItAllBadge.levels)
        if award_level > available_levels:
            return BadgeAwarded(level=available_levels)

        return BadgeAwarded(level=award_level)
Exemplo n.º 13
0
 def award(self, **state):
     return BadgeAwarded(level=1)
Exemplo n.º 14
0
 def award(self, **state):
     # user = User.objects.get(username=state["user"])
     # if user.production_set.all().count() > 1:
     return BadgeAwarded(level=1)
Exemplo n.º 15
0
 def award(self, **state):
     user = state["user"]
     if user.profile.position == 1:
         return BadgeAwarded(level=1)
Exemplo n.º 16
0
 def award(self, **state):
     user = state["user"]
     if user.profile_filled:
         return BadgeAwarded(level=1)
Exemplo n.º 17
0
 def award(self, **state):
     user = state["user"]
     if user.is_staff or user.is_superuser:
         return BadgeAwarded(level=1)