def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of approved revisions in the appropriate locales # for the current year. qs = Revision.objects.filter(creator=user, is_approved=True, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) if badge_template['slug'] == WIKI_BADGES['kb-badge']['slug']: # kb-badge qs = qs.filter(document__locale=settings.WIKI_DEFAULT_LANGUAGE) else: # l10n-badge qs = qs.exclude(document__locale=settings.WIKI_DEFAULT_LANGUAGE) # If the count is 10 or higher, award the badge. if qs.count() >= 10: badge.award_to(user) return True
def maybe_award_badge(badge_template: Dict, year: int, user_id: int): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) try: user = User.objects.get(id=user_id) except User.DoesNotExist as err: capture_exception(err) return # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. from kitsune.questions.models import Answer qs = Answer.objects.filter( creator=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1) ) # If the count is at or above the limit, award the badge. if qs.count() >= settings.BADGE_LIMIT_SUPPORT_FORUM: badge.award_to(user) return True
def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of approved revisions in the appropriate locales # for the current year. qs = Revision.objects.filter( creator=user, is_approved=True, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) if badge_template['slug'] == WIKI_BADGES['kb-badge']['slug']: # kb-badge qs = qs.filter(document__locale=settings.WIKI_DEFAULT_LANGUAGE) else: # l10n-badge qs = qs.exclude(document__locale=settings.WIKI_DEFAULT_LANGUAGE) # If the count is 10 or higher, award the badge. if qs.count() >= 10: badge.award_to(user) return True
def maybe_award_badge(badge_template: Dict, year: int, user_id: int): """Award the specific badge to the user if they've earned it.""" try: user = User.objects.get(id=user_id) except User.DoesNotExist: return badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of approved revisions in the appropriate locales # for the current year. qs = Revision.objects.filter( creator=user, is_approved=True, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1), ) if badge_template["slug"] == WIKI_BADGES["kb-badge"]["slug"]: # kb-badge qs = qs.filter(document__locale=settings.WIKI_DEFAULT_LANGUAGE) else: # l10n-badge qs = qs.exclude(document__locale=settings.WIKI_DEFAULT_LANGUAGE) # If the count is 10 or higher, award the badge. if qs.count() >= settings.BADGE_LIMIT_L10N_KB: badge.award_to(user) return True
def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. qs = Reply.objects.filter(user=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) # If the count is 50 or higher, award the badge. if qs.count() >= 50: badge.award_to(user) return True
def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. qs = Reply.objects.filter(user=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) # If the count is 50 or higher, award the badge. if qs.count() >= settings.BADGE_LIMIT_ARMY_OF_AWESOME: badge.award_to(user) return True
def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. from kitsune.questions.models import Answer qs = Answer.objects.filter(creator=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) # If the count is 30 or higher, award the badge. if qs.count() >= 30: badge.award_to(user) return True
def maybe_award_badge(badge_template, year, user): """Award the specific badge to the user if they've earned it.""" badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. from kitsune.questions.models import Answer qs = Answer.objects.filter( creator=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) # If the count is 30 or higher, award the badge. if qs.count() >= 30: badge.award_to(user) return True
def maybe_award_badge(badge_template: Dict, year: int, user_id: int): """Award the specific badge to the user if they've earned it.""" try: user = User.objects.get(id=user_id) except User.DoesNotExist as err: capture_exception(err) return badge = get_or_create_badge(badge_template, year) # If the user already has the badge, there is nothing else to do. if badge.is_awarded_to(user): return # Count the number of replies tweeted in the current year. qs = Reply.objects.filter(user=user, created__gte=date(year, 1, 1), created__lt=date(year + 1, 1, 1)) # If the count is 50 or higher, award the badge. if qs.count() >= settings.BADGE_LIMIT_ARMY_OF_AWESOME: badge.award_to(user) return True