Skip to content

Commit aebe403

Browse files
committed
Waspy Award Winner badge integration
1 parent 1a33ed4 commit aebe403

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

backend/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ shell-db:
109109
sync-data: \
110110
update-data \
111111
enrich-data \
112+
owasp-update-badges \
112113
index-data
113114

114115
test-backend:

backend/apps/owasp/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ owasp-update-events:
6767
owasp-update-sponsors:
6868
@echo "Getting OWASP sponsors data"
6969
@CMD="python manage.py owasp_update_sponsors" $(MAKE) exec-backend-command
70+
71+
owasp-update-badges:
72+
@echo "Updating OWASP user badges"
73+
@CMD="python manage.py owasp_update_badges" $(MAKE) exec-backend-command
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Update user badges based on OWASP awards."""
2+
3+
from django.core.management.base import BaseCommand
4+
5+
from apps.github.models.user import User
6+
from apps.nest.models.badge import Badge
7+
from apps.owasp.models.award import Award
8+
9+
10+
class Command(BaseCommand):
11+
"""Update user badges based on OWASP awards."""
12+
13+
help = "Update user badges based on OWASP awards"
14+
15+
def handle(self, *args, **options):
16+
"""Handle the command execution."""
17+
# Get or create WASPY badge
18+
waspy_badge, created = Badge.objects.get_or_create(
19+
name="WASPY Award Winner",
20+
defaults={
21+
"description": "Recipient of WASPY award from OWASP",
22+
"css_class": "badge-waspy",
23+
"weight": 10,
24+
},
25+
)
26+
27+
if created:
28+
self.stdout.write(f"Created badge: {waspy_badge.name}")
29+
30+
# Get users with WASPY awards using the model method
31+
waspy_winners = Award.get_waspy_award_winners()
32+
33+
# Add badge to WASPY winners
34+
for user in waspy_winners:
35+
user.badges.add(waspy_badge)
36+
37+
# Remove badge from users no longer on the WASPY winners list
38+
users_with_badge = User.objects.filter(badges=waspy_badge)
39+
waspy_winner_ids = set(waspy_winners.values_list("id", flat=True))
40+
41+
for user in users_with_badge:
42+
if user.id not in waspy_winner_ids:
43+
user.badges.remove(waspy_badge)
44+
45+
self.stdout.write(f"Updated badges for {waspy_winners.count()} WASPY winners")

backend/apps/owasp/models/award.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ def get_waspy_award_winners(cls):
105105
"""
106106
from apps.github.models.user import User
107107

108-
return User.objects.filter(awards__category=cls.Category.WASPY).distinct()
108+
return User.objects.filter(
109+
awards__category=cls.Category.WASPY, awards__is_reviewed=True
110+
).distinct()
109111

110112
@classmethod
111113
def get_user_waspy_awards(cls, user):

0 commit comments

Comments
 (0)