Skip to content

Commit bc6244d

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

File tree

10 files changed

+63
-95
lines changed

10 files changed

+63
-95
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: 10 additions & 19 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
),
@@ -35,6 +42,7 @@ class Migration(migrations.Migration):
3542
models.CharField(
3643
help_text="Award name/title (e.g., 'Event Person of the Year')",
3744
max_length=200,
45+
unique=True,
3846
verbose_name="Name",
3947
),
4048
),
@@ -50,9 +58,7 @@ class Migration(migrations.Migration):
5058
(
5159
"year",
5260
models.IntegerField(
53-
blank=True,
54-
help_text="Year the award was given (null for category definitions)",
55-
null=True,
61+
help_text="Year the award was given",
5662
verbose_name="Year",
5763
),
5864
),
@@ -85,16 +91,6 @@ class Migration(migrations.Migration):
8591
verbose_name="Winner Image",
8692
),
8793
),
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-
),
9894
(
9995
"user",
10096
models.ForeignKey(
@@ -117,11 +113,6 @@ class Migration(migrations.Migration):
117113
models.Index(fields=["-year"], name="owasp_award_year_desc"),
118114
models.Index(fields=["name"], name="owasp_award_name"),
119115
],
120-
"constraints": [
121-
models.UniqueConstraint(
122-
fields=("name", "year", "category"), name="unique_award_name_year_category"
123-
)
124-
],
125116
},
126117
),
127118
]

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

backend/apps/owasp/models/award.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ class Meta:
3030
]
3131
verbose_name = "Award"
3232
verbose_name_plural = "Awards"
33-
constraints = [
34-
models.UniqueConstraint(
35-
fields=["name", "year", "category"], name="unique_award_name_year_category"
36-
)
37-
]
3833

3934
# Core fields based on YAML structure
4035
category = models.CharField(
@@ -46,6 +41,7 @@ class Meta:
4641
name = models.CharField(
4742
verbose_name="Name",
4843
max_length=200,
44+
unique=True,
4945
help_text="Award name/title (e.g., 'Event Person of the Year')",
5046
)
5147
description = models.TextField(

backend/tests/apps/owasp/models/award_test.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)