Skip to content
Snippets Groups Projects
Commit ab9067b6 authored by Bodor Máté's avatar Bodor Máté
Browse files

Validate document

parent e35230ae
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ class Document(models.Model):
],
blank=True,
)
solution = models.ForeignKey(Solution, related_name='files', on_delete=models.DO_NOTHING, blank=True, null=True)
solution = models.ForeignKey(Solution, related_name='files', on_delete=models.CASCADE)
def __str__(self):
return self.name
from rest_framework import serializers
from common.serializers import CurrentUserProfileDefault
from . import models
from common.middleware import CurrentUserMiddleware
_max_count = 5
class DocumentSerializer(serializers.ModelSerializer):
uploaded_by = serializers.HiddenField(default=CurrentUserProfileDefault())
......@@ -20,4 +21,7 @@ class DocumentSerializer(serializers.ModelSerializer):
profile = CurrentUserMiddleware.get_current_user_profile()
if data['solution'] not in profile.solution.all():
raise serializers.ValidationError('You dont have permission!')
count = models.Document.objects.filter(uploaded_by=profile, solution=data['solution']).count()
if count >= _max_count:
raise serializers.ValidationError('You cant upload more than ' + str(_max_count) + ' document to one solution!')
return data
......@@ -28,6 +28,7 @@ class SolutionSerializer(serializers.ModelSerializer):
model = models.Solution
read_only_fields = ('created_by', 'created_at', 'updated_at', 'ready', 'files')
fields = (
'id',
'task',
'created_at',
'updated_at',
......
......@@ -18,12 +18,18 @@ class StaffEventSerializer(serializers.ModelSerializer):
def get_visitor_number(self, obj):
return obj.visitors.all().count()
def validate(self, data):
for i in data['absent']:
if i in data['visitors']:
raise serializers.ValidationError('You cant add a student to absent and visitor in the same time.')
return data
class StudentEventSerializer(serializers.ModelSerializer):
class Meta:
model = models.Event
fields = ('name', 'date', 'description', )
read_only_fields = ('name', 'date', 'description', )
fields = ('id', 'name', 'date', 'description', )
read_only_fields = ('id', 'name', 'date', 'description', )
class NoteSerializer(serializers.ModelSerializer):
......
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