Skip to content

Commit aba2991

Browse files
#A09. As Admin, I would like to trigger an event to award the winning project(s) based on the judges scores. (#134)
1 parent 973dc24 commit aba2991

18 files changed

Lines changed: 518 additions & 65 deletions

hackathon/fixtures/hackathons.json

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,83 @@
275275
"min_score":1,
276276
"max_score":10
277277
}
278+
},
279+
{
280+
"model": "hackathon.hackawardcategory",
281+
"pk": 1,
282+
"fields": {
283+
"created": "2021-01-18T23:22:27.172Z",
284+
"updated": "2021-01-18T23:22:27.172Z",
285+
"created_by": 1,
286+
"display_name": "Best Project",
287+
"description": "The project with the best score overall.",
288+
"hackathon": 4,
289+
"winning_project": null
290+
}
291+
},
292+
{
293+
"model": "hackathon.hackawardcategory",
294+
"pk": 2,
295+
"fields": {
296+
"created": "2021-01-18T23:23:11.556Z",
297+
"updated": "2021-01-18T23:23:11.556Z",
298+
"created_by": 1,
299+
"display_name": "Best Project (1st Runners Up)",
300+
"description": "The project with the second best score overall.",
301+
"hackathon": 4,
302+
"winning_project": null
303+
}
304+
},
305+
{
306+
"model": "hackathon.hackawardcategory",
307+
"pk": 3,
308+
"fields": {
309+
"created": "2021-01-18T23:23:35.718Z",
310+
"updated": "2021-01-18T23:23:35.718Z",
311+
"created_by": 1,
312+
"display_name": "Best Project (2nd Runners Up)",
313+
"description": "The project with the third best score overall.",
314+
"hackathon": 4,
315+
"winning_project": null
316+
}
317+
},
318+
{
319+
"model": "hackathon.hackawardcategory",
320+
"pk": 4,
321+
"fields": {
322+
"created": "2021-01-18T23:25:31.644Z",
323+
"updated": "2021-01-18T23:25:31.644Z",
324+
"created_by": 1,
325+
"display_name": "Most Innovative Project",
326+
"description": "The project using the most innovative technology, approach or architecture.",
327+
"hackathon": 4,
328+
"winning_project": null
329+
}
330+
},
331+
{
332+
"model": "hackathon.hackawardcategory",
333+
"pk": 5,
334+
"fields": {
335+
"created": "2021-01-18T23:26:34.100Z",
336+
"updated": "2021-01-18T23:26:34.100Z",
337+
"created_by": 1,
338+
"display_name": "Best Commercial Application",
339+
"description": "The project which shows be the best commercial application and is the closest to be market ready.",
340+
"hackathon": 4,
341+
"winning_project": null
342+
}
343+
},
344+
{
345+
"model": "hackathon.hackawardcategory",
346+
"pk": 6,
347+
"fields": {
348+
"created": "2021-01-18T23:27:06.554Z",
349+
"updated": "2021-01-18T23:27:06.554Z",
350+
"created_by": 1,
351+
"display_name": "Most Creative Project",
352+
"description": "The project with the most creative idea.",
353+
"hackathon": 4,
354+
"winning_project": null
355+
}
278356
}
279-
]
357+
]

hackathon/forms.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from django import forms
2+
from django.forms import BaseModelFormSet
23

34
from accounts.models import Organisation
4-
from .models import Hackathon, HackProject
5+
from .models import Hackathon, HackProject, HackAwardCategory,\
6+
HackProjectScoreCategory
57
from .lists import STATUS_TYPES_CHOICES, JUDGING_STATUS_CHOICES
68

79
class HackathonForm(forms.ModelForm):
@@ -24,7 +26,7 @@ class HackathonForm(forms.ModelForm):
2426
max_length=3000,
2527
widget=forms.Textarea(
2628
attrs={
27-
'rows': 3,
29+
'rows': 4,
2830
'placeholder': 'Tell us more about this event...'
2931
}
3032
)
@@ -78,11 +80,18 @@ class HackathonForm(forms.ModelForm):
7880
label="Organisation",
7981
queryset=Organisation.objects.order_by('display_name'),
8082
)
83+
score_categories = forms.ModelMultipleChoiceField(
84+
queryset=HackProjectScoreCategory.objects.all(),
85+
widget=forms.SelectMultiple(attrs={
86+
'size': '5'
87+
})
88+
)
8189

8290
class Meta:
8391
model = Hackathon
8492
fields = ['display_name', 'description', 'theme', 'start_date',
8593
'end_date', 'status', 'judging_status', 'organisation',
94+
'score_categories',
8695
]
8796

8897
def __init__(self, *args, **kwargs):
@@ -104,3 +113,24 @@ class Meta:
104113
'start_date': forms.HiddenInput(),
105114
'end_date': forms.HiddenInput()
106115
}
116+
117+
118+
class HackAwardCategoryForm(forms.ModelForm):
119+
120+
display_name = forms.CharField(
121+
label='Award Category Name',
122+
widget=forms.TextInput(
123+
attrs={
124+
'readonly': True
125+
}
126+
),
127+
required=True
128+
)
129+
130+
class Meta:
131+
model = HackAwardCategory
132+
fields = ('id', 'display_name', 'winning_project')
133+
134+
def __init__(self, *args, **kwargs):
135+
super(HackAwardCategoryForm, self).__init__(*args, **kwargs)
136+
self.fields['display_name'].widget.attrs['readonly'] = True

hackathon/lists.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
('not_yet_started', "Hasn't started"),
1717
('open', "Open"),
1818
('closed', "Closed"),
19-
)
19+
)
20+
21+
AWARD_CATEGORIES = ['Best Project', 'Best Project (1st Runners Up)',
22+
'Best Project (2nd Runners Up)', 'Most Innovative Project',
23+
'Best Commercial Application', 'Most Creative Project']
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.1.3 on 2021-01-18 23:12
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('hackathon', '0025_auto_20210111_2242'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='hackprojectscorecategory',
16+
name='hackathon',
17+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hackprojectscorecategories', to='hackathon.hackathon'),
18+
),
19+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.1.3 on 2021-01-19 00:45
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('hackathon', '0026_hackprojectscorecategory_hackathon'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='hackawardcategory',
16+
name='winning_project',
17+
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hackathon.hackproject'),
18+
),
19+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 3.1.3 on 2021-01-19 23:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('hackathon', '0027_auto_20210119_0045'),
10+
]
11+
12+
operations = [
13+
migrations.RemoveField(
14+
model_name='hackprojectscorecategory',
15+
name='hackathon',
16+
),
17+
migrations.AddField(
18+
model_name='hackathon',
19+
name='score_categories',
20+
field=models.ManyToManyField(blank=True, related_name='hackathon_score_categories', to='hackathon.HackProjectScoreCategory'),
21+
),
22+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Django 3.1.3 on 2021-01-20 11:41
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('hackathon', '0028_auto_20210119_2352'),
10+
('hackathon', '0031_merge_20210118_1524'),
11+
]
12+
13+
operations = [
14+
]

hackathon/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ class Hackathon(models.Model):
4444
participants = models.ManyToManyField(User,
4545
blank=True,
4646
related_name='hackathon_participants')
47+
# Hackathons can have multiple score categories and score categories
48+
# Can belong to multiple hackahtons: Many to Many
49+
score_categories = models.ManyToManyField(
50+
'HackProjectScoreCategory',
51+
blank=True,
52+
related_name='hackathon_score_categories')
4753
# One organiser could organise more than one Hackathon: One To Many
4854
organiser = models.ForeignKey(User,
4955
null=True,
@@ -90,10 +96,10 @@ class HackAwardCategory(models.Model):
9096
on_delete=models.CASCADE,
9197
related_name="awards")
9298
# One category can have one winner: One to One
93-
winning_project = models.OneToOneField("HackProject",
94-
null=True,
95-
blank=True,
96-
on_delete=models.SET_NULL)
99+
winning_project = models.ForeignKey("HackProject",
100+
null=True,
101+
blank=True,
102+
on_delete=models.SET_NULL)
97103

98104
def __str__(self):
99105
return self.display_name

hackathon/templates/hackathon/create-event.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ <h1>Create Hackathon</h1>
4949
<div class="col-12 col-md-6 mb-3">
5050
{{ form.end_date|as_crispy_field }}
5151
</div>
52+
<div class="col-12 mb-3">
53+
{{ form.score_categories|as_crispy_field }}
54+
</div>
5255
<div class="col-12 mb-5">
5356
<input type="submit" class="btn-ci mr-2">
5457
<a href="{% url 'hackathon:hackathon-list' %}" type="button" class="btn-ci button">Cancel</a>

0 commit comments

Comments
 (0)