Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.conf import settings
from rest_framework import serializers
from rest_framework.reverse import reverse
from rdmo.core.serializers import TranslationSerializerMixin
from rdmo.core.utils import get_language_warning
from rdmo.domain.models import Attribute
from ..models import Catalog, Question, QuestionSet, Section
from ..validators import (CatalogUniqueKeyValidator,
QuestionSetUniquePathValidator,
QuestionUniquePathValidator,
SectionUniquePathValidator)
class CatalogSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
key = serializers.CharField(required=True)
class Meta:
model = Catalog
fields = (
'id',
'uri_prefix',
'key',
'comment',
'order',
)
trans_fields = (
'title',
)
validators = (CatalogUniqueKeyValidator(), )
from rest_framework import serializers
from rdmo.core.serializers import TranslationSerializerMixin
from rdmo.core.utils import get_language_warning
from ..models import View
class ViewSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
class Meta:
model = View
fields = (
'id',
'uri',
'uri_prefix',
'key',
'comment',
'template'
)
trans_fields = (
'title',
'help'
)
'title',
)
validators = (CatalogUniqueKeyValidator(), )
class SectionIndexSerializer(serializers.ModelSerializer):
class Meta:
model = Section
fields = (
'id',
'path',
)
class SectionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
key = serializers.CharField(required=True)
class Meta:
model = Section
fields = (
'id',
'uri_prefix',
'key',
'comment',
'catalog',
'order',
)
trans_fields = (
'title',
)
'attribute',
'section',
'is_collection',
'order',
'conditions',
)
trans_fields = (
'title',
'help',
'verbose_name',
'verbose_name_plural',
)
validators = (QuestionSetUniquePathValidator(), )
class QuestionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
key = serializers.CharField(required=True)
class Meta:
model = Question
fields = (
'id',
'uri_prefix',
'key',
'comment',
'attribute',
'questionset',
'is_collection',
'order',
'maximum',
'minimum',
)
trans_fields = (
'help',
'text',
'verbose_name',
'verbose_name_plural',
)
def get_optionsets(self, obj):
return [optionset.uri for optionset in obj.optionsets.all()]
def get_conditions(self, obj):
return [condition.uri for condition in obj.conditions.all()]
class QuestionSetSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
attribute = serializers.CharField(source='attribute.uri', default=None, read_only=True)
section = serializers.CharField(source='section.uri', default=None, read_only=True)
questions = QuestionSerializer(many=True, read_only=True)
conditions = serializers.SerializerMethodField()
class Meta:
model = QuestionSet
fields = (
'uri',
'uri_prefix',
'key',
'path',
'comment',
'attribute',
'section',
'attribute',
'section',
'is_collection',
'order',
'conditions',
)
trans_fields = (
'title',
'help',
'verbose_name',
'verbose_name_plural',
)
validators = (QuestionSetUniquePathValidator(), )
class QuestionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
key = serializers.CharField(required=True)
class Meta:
model = Question
fields = (
'id',
'uri_prefix',
'key',
'comment',
'attribute',
'questionset',
'is_collection',
'order',
'maximum',
'minimum',
class Meta:
model = Catalog
fields = (
'id',
'uri_prefix',
'key',
'comment',
'order',
)
trans_fields = (
'title',
)
validators = (CatalogUniqueKeyValidator(), )
class SectionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
key = serializers.CharField(required=True)
class Meta:
model = Section
fields = (
'id',
'uri_prefix',
'key',
'comment',
'catalog',
'order',
)
trans_fields = (
'title',
)
class Meta:
model = Section
fields = (
'id',
'path',
'title',
'questionsets',
'warning'
)
def get_warning(self, obj):
return get_language_warning(obj, 'title')
class CatalogNestedSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
sections = SectionNestedSerializer(many=True, read_only=True)
urls = serializers.SerializerMethodField()
class Meta:
model = Catalog
fields = (
'id',
'key',
'sections',
'urls'
)
trans_fields = (
'title',
)
from rest_framework import serializers
from rdmo.core.serializers import TranslationSerializerMixin
from ..models import Catalog, Section, QuestionSet, Question
class QuestionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
attribute = serializers.CharField(source='attribute.uri', default=None, read_only=True)
questionset = serializers.CharField(source='questionset.uri', default=None, read_only=True)
optionsets = serializers.SerializerMethodField()
conditions = serializers.SerializerMethodField()
class Meta:
model = Question
fields = (
'uri',
'uri_prefix',
'key',
'path',
'comment',
'attribute',
'questionset',
from rest_framework import serializers
from rdmo.core.serializers import TranslationSerializerMixin
from ..models import OptionSet, Option
class OptionSerializer(TranslationSerializerMixin, serializers.ModelSerializer):
optionset = serializers.CharField(source='optionset.uri', default=None, read_only=True)
class Meta:
model = Option
fields = (
'uri',
'uri_prefix',
'key',
'path',
'comment',
'order',
'additional_input',
'optionset'
)
trans_fields = (