Skip to content
Snippets Groups Projects
Commit 94a9d63c authored by Barnabás Czémán's avatar Barnabás Czémán
Browse files

Fix deadline validate

parent 62a7d05c
No related branches found
No related tags found
No related merge requests found
# Generated by Django 2.0.1 on 2018-02-03 19:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0012_auto_20180125_1957'),
]
operations = [
migrations.AlterField(
model_name='profile',
name='join_date',
field=models.DateTimeField(auto_now=True),
),
]
# Generated by Django 2.0.1 on 2018-02-03 19:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0013_auto_20180203_2007'),
]
operations = [
migrations.AlterField(
model_name='deadline',
name='deadline',
field=models.DateTimeField(null=True),
),
]
# Generated by Django 2.0.1 on 2018-02-03 19:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('account', '0014_auto_20180203_2010'),
]
operations = [
migrations.AddField(
model_name='profile',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AlterField(
model_name='profile',
name='join_date',
field=models.DateTimeField(auto_now_add=True),
),
]
......@@ -19,7 +19,8 @@ class GroupChoice(models.Model):
class Profile(models.Model):
join_date = models.DateField(auto_now=True)
join_date = models.DateTimeField(auto_now_add=True, editable=False)
updated_at = models.DateTimeField(auto_now=True, editable=False)
user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE)
motivation = models.TextField(null=True)
nick = models.CharField(max_length=15, blank=True, null=True)
......@@ -32,4 +33,4 @@ class Profile(models.Model):
class Deadline(SingletonModel):
deadline = models.DateField(null=True)
deadline = models.DateTimeField(null=True)
......@@ -10,12 +10,19 @@ class ChoiceSerializer(serializers.ModelSerializer):
class ProfileSerializer(serializers.ModelSerializer):
groups = serializers.SlugRelatedField(many=True, slug_field="choice", queryset=models.GroupChoice.objects.all())
updated_at = serializers.DateTimeField(read_only=True)
signed = serializers.BooleanField()
class Meta:
model = models.Profile
fields = ('id', 'join_date', 'user', 'nick', 'motivation', 'signed', 'groups')
fields = ('id', 'join_date', 'updated_at', 'user', 'nick', 'motivation', 'signed', 'groups')
def validate(self, data):
if data['join_date'] > models.Deadline.get_solo().deadline:
raise serializers.ValidationError("join_date more than deadline")
deadline = models.Deadline.get_solo().deadline
if deadline is None:
return data
if data['signed'] is True and data['updated_at'] > deadline:
raise serializers.ValidationError("You cannot join after the deadline")
return data
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment