Added agenda validation in all methods
This commit is contained in:
parent
bcf73897c8
commit
62a66a80fb
|
|
@ -231,12 +231,6 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
if not attrs[key].get(locale):
|
||||
attrs[key][locale] = getattr(instance, key).get(locale)
|
||||
|
||||
if 'agenda' in attrs:
|
||||
agenda = models.Agenda.objects.get(attrs['agenda'])
|
||||
|
||||
if agenda.event_name is None or agenda.content is None:
|
||||
raise serializers.ValidationError({'agenda': _('Agenda is empty')})
|
||||
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
|
|
@ -254,6 +248,10 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
user = request.user
|
||||
validated_data['created_by'] = user
|
||||
|
||||
agenda = validated_data.get('agenda')
|
||||
if agenda is not None and (agenda.event_name is None or agenda.content is None):
|
||||
raise serializers.ValidationError({'agenda': _('Agenda is empty')})
|
||||
|
||||
return super().create(validated_data)
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
|
|
@ -265,6 +263,11 @@ class NewsBackOfficeBaseSerializer(NewsBaseSerializer):
|
|||
slugs__values__contains=list(slugs.values())
|
||||
).exists() or len(slugs_list) != len(slugs_set):
|
||||
raise serializers.ValidationError({'slugs': _('Slug should be unique')})
|
||||
|
||||
agenda = validated_data.get('agenda')
|
||||
if agenda is not None and (agenda.event_name is None or agenda.content is None):
|
||||
raise serializers.ValidationError({'agenda': _('Agenda is empty')})
|
||||
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user