How to use the rdmo.core.serializers.TranslationSerializerMixin function in rdmo

To help you get started, we’ve selected a few rdmo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rdmorganiser / rdmo / rdmo / questions / serializers / v1.py View on Github external
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(), )
github rdmorganiser / rdmo / rdmo / views / serializers / v1.py View on Github external
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'
        )
github rdmorganiser / rdmo / rdmo / questions / serializers / __init__.py View on Github external
'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',
        )
github rdmorganiser / rdmo / rdmo / questions / serializers / __init__.py View on Github external
'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',
github rdmorganiser / rdmo / rdmo / questions / serializers / export.py View on Github external
)
        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',
github rdmorganiser / rdmo / rdmo / questions / serializers / v1.py View on Github external
'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',
github rdmorganiser / rdmo / rdmo / questions / serializers / v1.py View on Github external
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',
        )
github rdmorganiser / rdmo / rdmo / questions / serializers / v1.py View on Github external
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',
        )
github rdmorganiser / rdmo / rdmo / questions / serializers / export.py View on Github external
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',
github rdmorganiser / rdmo / rdmo / options / serializers / export.py View on Github external
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 = (