Skip to content

Commit

Permalink
#A09. As Admin, I would like to trigger an event to award the winning…
Browse files Browse the repository at this point in the history
… project(s) based on the judges scores. (#134)
  • Loading branch information
stefdworschak authored Jan 20, 2021
1 parent 973dc24 commit aba2991
Show file tree
Hide file tree
Showing 18 changed files with 518 additions and 65 deletions.
80 changes: 79 additions & 1 deletion hackathon/fixtures/hackathons.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,83 @@
"min_score":1,
"max_score":10
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 1,
"fields": {
"created": "2021-01-18T23:22:27.172Z",
"updated": "2021-01-18T23:22:27.172Z",
"created_by": 1,
"display_name": "Best Project",
"description": "The project with the best score overall.",
"hackathon": 4,
"winning_project": null
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 2,
"fields": {
"created": "2021-01-18T23:23:11.556Z",
"updated": "2021-01-18T23:23:11.556Z",
"created_by": 1,
"display_name": "Best Project (1st Runners Up)",
"description": "The project with the second best score overall.",
"hackathon": 4,
"winning_project": null
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 3,
"fields": {
"created": "2021-01-18T23:23:35.718Z",
"updated": "2021-01-18T23:23:35.718Z",
"created_by": 1,
"display_name": "Best Project (2nd Runners Up)",
"description": "The project with the third best score overall.",
"hackathon": 4,
"winning_project": null
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 4,
"fields": {
"created": "2021-01-18T23:25:31.644Z",
"updated": "2021-01-18T23:25:31.644Z",
"created_by": 1,
"display_name": "Most Innovative Project",
"description": "The project using the most innovative technology, approach or architecture.",
"hackathon": 4,
"winning_project": null
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 5,
"fields": {
"created": "2021-01-18T23:26:34.100Z",
"updated": "2021-01-18T23:26:34.100Z",
"created_by": 1,
"display_name": "Best Commercial Application",
"description": "The project which shows be the best commercial application and is the closest to be market ready.",
"hackathon": 4,
"winning_project": null
}
},
{
"model": "hackathon.hackawardcategory",
"pk": 6,
"fields": {
"created": "2021-01-18T23:27:06.554Z",
"updated": "2021-01-18T23:27:06.554Z",
"created_by": 1,
"display_name": "Most Creative Project",
"description": "The project with the most creative idea.",
"hackathon": 4,
"winning_project": null
}
}
]
]
34 changes: 32 additions & 2 deletions hackathon/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django import forms
from django.forms import BaseModelFormSet

from accounts.models import Organisation
from .models import Hackathon, HackProject
from .models import Hackathon, HackProject, HackAwardCategory,\
HackProjectScoreCategory
from .lists import STATUS_TYPES_CHOICES, JUDGING_STATUS_CHOICES

class HackathonForm(forms.ModelForm):
Expand All @@ -24,7 +26,7 @@ class HackathonForm(forms.ModelForm):
max_length=3000,
widget=forms.Textarea(
attrs={
'rows': 3,
'rows': 4,
'placeholder': 'Tell us more about this event...'
}
)
Expand Down Expand Up @@ -78,11 +80,18 @@ class HackathonForm(forms.ModelForm):
label="Organisation",
queryset=Organisation.objects.order_by('display_name'),
)
score_categories = forms.ModelMultipleChoiceField(
queryset=HackProjectScoreCategory.objects.all(),
widget=forms.SelectMultiple(attrs={
'size': '5'
})
)

class Meta:
model = Hackathon
fields = ['display_name', 'description', 'theme', 'start_date',
'end_date', 'status', 'judging_status', 'organisation',
'score_categories',
]

def __init__(self, *args, **kwargs):
Expand All @@ -104,3 +113,24 @@ class Meta:
'start_date': forms.HiddenInput(),
'end_date': forms.HiddenInput()
}


class HackAwardCategoryForm(forms.ModelForm):

display_name = forms.CharField(
label='Award Category Name',
widget=forms.TextInput(
attrs={
'readonly': True
}
),
required=True
)

class Meta:
model = HackAwardCategory
fields = ('id', 'display_name', 'winning_project')

def __init__(self, *args, **kwargs):
super(HackAwardCategoryForm, self).__init__(*args, **kwargs)
self.fields['display_name'].widget.attrs['readonly'] = True
6 changes: 5 additions & 1 deletion hackathon/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
('not_yet_started', "Hasn't started"),
('open', "Open"),
('closed', "Closed"),
)
)

AWARD_CATEGORIES = ['Best Project', 'Best Project (1st Runners Up)',
'Best Project (2nd Runners Up)', 'Most Innovative Project',
'Best Commercial Application', 'Most Creative Project']
19 changes: 19 additions & 0 deletions hackathon/migrations/0026_hackprojectscorecategory_hackathon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.3 on 2021-01-18 23:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('hackathon', '0025_auto_20210111_2242'),
]

operations = [
migrations.AddField(
model_name='hackprojectscorecategory',
name='hackathon',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='hackprojectscorecategories', to='hackathon.hackathon'),
),
]
19 changes: 19 additions & 0 deletions hackathon/migrations/0027_auto_20210119_0045.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.1.3 on 2021-01-19 00:45

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('hackathon', '0026_hackprojectscorecategory_hackathon'),
]

operations = [
migrations.AlterField(
model_name='hackawardcategory',
name='winning_project',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hackathon.hackproject'),
),
]
22 changes: 22 additions & 0 deletions hackathon/migrations/0028_auto_20210119_2352.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.1.3 on 2021-01-19 23:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('hackathon', '0027_auto_20210119_0045'),
]

operations = [
migrations.RemoveField(
model_name='hackprojectscorecategory',
name='hackathon',
),
migrations.AddField(
model_name='hackathon',
name='score_categories',
field=models.ManyToManyField(blank=True, related_name='hackathon_score_categories', to='hackathon.HackProjectScoreCategory'),
),
]
14 changes: 14 additions & 0 deletions hackathon/migrations/0032_merge_20210120_1141.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.1.3 on 2021-01-20 11:41

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('hackathon', '0028_auto_20210119_2352'),
('hackathon', '0031_merge_20210118_1524'),
]

operations = [
]
14 changes: 10 additions & 4 deletions hackathon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Hackathon(models.Model):
participants = models.ManyToManyField(User,
blank=True,
related_name='hackathon_participants')
# Hackathons can have multiple score categories and score categories
# Can belong to multiple hackahtons: Many to Many
score_categories = models.ManyToManyField(
'HackProjectScoreCategory',
blank=True,
related_name='hackathon_score_categories')
# One organiser could organise more than one Hackathon: One To Many
organiser = models.ForeignKey(User,
null=True,
Expand Down Expand Up @@ -90,10 +96,10 @@ class HackAwardCategory(models.Model):
on_delete=models.CASCADE,
related_name="awards")
# One category can have one winner: One to One
winning_project = models.OneToOneField("HackProject",
null=True,
blank=True,
on_delete=models.SET_NULL)
winning_project = models.ForeignKey("HackProject",
null=True,
blank=True,
on_delete=models.SET_NULL)

def __str__(self):
return self.display_name
Expand Down
3 changes: 3 additions & 0 deletions hackathon/templates/hackathon/create-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ <h1>Create Hackathon</h1>
<div class="col-12 col-md-6 mb-3">
{{ form.end_date|as_crispy_field }}
</div>
<div class="col-12 mb-3">
{{ form.score_categories|as_crispy_field }}
</div>
<div class="col-12 mb-5">
<input type="submit" class="btn-ci mr-2">
<a href="{% url 'hackathon:hackathon-list' %}" type="button" class="btn-ci button">Cancel</a>
Expand Down
Loading

0 comments on commit aba2991

Please sign in to comment.