Skip to content

Commit

Permalink
feat(Matches): Invalidate score 0-0
Browse files Browse the repository at this point in the history
  • Loading branch information
TeoTN committed Dec 28, 2017
1 parent b2565c8 commit da4920f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class MatchSerializer(serializers.ModelSerializer):
blue_def = serializers.SlugRelatedField(slug_field='username', queryset=Member.objects.all())
points = serializers.IntegerField(required=False)

class Meta:
model = Match
fields = (
'id', 'red_att', 'red_def', 'blue_att', 'blue_def', 'date',
'red_score', 'blue_score', 'points'
)

def __init__(self, *args, **kwargs):
# Ensure that we use only members within team context, if present
ctx = kwargs.get('context', None)
Expand All @@ -90,9 +97,9 @@ def __init__(self, *args, **kwargs):
field.queryset = field.queryset.filter(team_id=team_id)
super(MatchSerializer, self).__init__(*args, **kwargs)

class Meta:
model = Match
fields = (
'id', 'red_att', 'red_def', 'blue_att', 'blue_def', 'date',
'red_score', 'blue_score', 'points'
)
def validate(self, data):
rs = data.get('red_score', None)
bs = data.get('blue_score', None)
if rs == 0 and bs == 0:
raise serializers.ValidationError('Cannot add match with score 0-0. Was it a typo?')
return data

0 comments on commit da4920f

Please sign in to comment.