Skip to content

Commit 867a047

Browse files
committed
clean up Award implementation and fix migration conflicts
1 parent 471492f commit 867a047

File tree

8 files changed

+61
-20
lines changed

8 files changed

+61
-20
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/nest/admin/badge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class BadgeAdmin(admin.ModelAdmin):
1212
list_display = ("name", "description", "weight", "css_class")
1313
list_filter = ("weight",)
1414
search_fields = ("name", "description")
15-
ordering = ("weight", "name")
15+
ordering = ("weight", "name")

backend/apps/nest/models/badge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ class Meta:
3838

3939
def __str__(self) -> str:
4040
"""Return the badge string representation."""
41-
return self.name
41+
return self.name

backend/apps/owasp/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ owasp-update-events:
6464
owasp-update-sponsors:
6565
@echo "Getting OWASP sponsors data"
6666
@CMD="python manage.py owasp_update_sponsors" $(MAKE) exec-backend-command
67+
68+
owasp-update-badges:
69+
@echo "Updating OWASP user badges"
70+
@CMD="python manage.py owasp_update_badges" $(MAKE) exec-backend-command

backend/apps/owasp/admin/award.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ class AwardAdmin(admin.ModelAdmin):
1313
"name",
1414
"category",
1515
"year",
16-
"award_type",
1716
"winner_name",
1817
"user",
1918
"nest_created_at",
2019
"nest_updated_at",
2120
)
2221
list_filter = (
23-
"award_type",
2422
"category",
2523
"year",
2624
)
@@ -38,7 +36,7 @@ class AwardAdmin(admin.ModelAdmin):
3836
fieldsets = (
3937
(
4038
"Basic Information",
41-
{"fields": ("name", "category", "award_type", "year", "description")},
39+
{"fields": ("name", "category", "year", "description")},
4240
),
4341
(
4442
"Winner Information",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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
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 without WASPY awards
38+
users_with_badge = User.objects.filter(badges=waspy_badge)
39+
for user in users_with_badge:
40+
if not Award.get_user_waspy_awards(user).exists():
41+
user.badges.remove(waspy_badge)
42+
43+
self.stdout.write(f"Updated badges for {waspy_winners.count()} WASPY winners")

backend/apps/owasp/migrations/0045_award.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ class Migration(migrations.Migration):
2525
(
2626
"category",
2727
models.CharField(
28-
help_text="Award category (e.g., 'WASPY', 'Lifetime Achievement')",
28+
choices=[
29+
("WASPY", "WASPY"),
30+
(
31+
"Distinguished Lifetime Memberships",
32+
"Distinguished Lifetime Memberships",
33+
),
34+
],
35+
help_text="Award category (e.g., 'WASPY', 'Distinguished Lifetime Memberships')",
2936
max_length=100,
3037
verbose_name="Category",
3138
),
@@ -50,9 +57,7 @@ class Migration(migrations.Migration):
5057
(
5158
"year",
5259
models.IntegerField(
53-
blank=True,
54-
help_text="Year the award was given (null for category definitions)",
55-
null=True,
60+
help_text="Year the award was given",
5661
verbose_name="Year",
5762
),
5863
),
@@ -85,16 +90,6 @@ class Migration(migrations.Migration):
8590
verbose_name="Winner Image",
8691
),
8792
),
88-
(
89-
"award_type",
90-
models.CharField(
91-
choices=[("category", "Category"), ("award", "Award")],
92-
default="award",
93-
help_text="Type of entry: category definition or individual award",
94-
max_length=20,
95-
verbose_name="Award Type",
96-
),
97-
),
9893
(
9994
"user",
10095
models.ForeignKey(

backend/apps/owasp/migrations/0046_merge_0045_badge_0045_project_audience.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Migration(migrations.Migration):
77
dependencies = [
8-
("owasp", "0045_badge"),
8+
("owasp", "0045_award"),
99
("owasp", "0045_project_audience"),
1010
]
1111

0 commit comments

Comments
 (0)