Skip to content

Commit

Permalink
fix: Rename worksheet label to Challenge (#1427)
Browse files Browse the repository at this point in the history
* fix: Rename worksheet label to Challenge

* Merge branch 'development' into rename_form_label

* Rename game class field to class

* Merge branch 'rename_form_label' of https://github.com/ocadotechnology/aimmo into rename_form_label

* Merge branch 'development' into rename_form_label

* Merge branch 'development' into rename_form_label

* Merge branch 'development' into rename_form_label

* Define worksheet widget to be consistent with game class

* Fix typo
  • Loading branch information
faucomte97 committed Dec 10, 2020
1 parent 575d743 commit 9529bf0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions aimmo/forms.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from common.models import Class
from django.core.exceptions import ValidationError
from django.db.models.query import QuerySet
from django.forms import ModelChoiceField, ModelForm, Select

from aimmo.models import Game
from common.models import Class
from aimmo.models import Game, Worksheet


class AddGameForm(ModelForm):
def __init__(self, classes: QuerySet, *args, **kwargs):
super(AddGameForm, self).__init__(*args, **kwargs)
self.fields["game_class"].queryset = classes
self.fields["worksheet"].queryset = Worksheet.objects.all()

game_class = ModelChoiceField(queryset=None, widget=Select, required=True)
game_class = ModelChoiceField(
queryset=None, widget=Select, label="Class", required=True
)
worksheet = ModelChoiceField(
queryset=None, widget=Select, label="Challenge", required=True
)

class Meta:
model = Game
Expand Down Expand Up @@ -46,8 +52,12 @@ def full_clean(self) -> None:

def clean(self):
game_class: Class = self.cleaned_data.get("game_class")
worksheet: Worksheet = self.cleaned_data.get("worksheet")

if game_class and not Class.objects.filter(pk=game_class.id).exists():
raise ValidationError("Sorry, an invalid class was entered")

if worksheet and not Worksheet.objects.filter(pk=worksheet.id).exists():
raise ValidationError("Sorry, an invalid challenge was entered")

return self.cleaned_data

0 comments on commit 9529bf0

Please sign in to comment.