Ejemplo n.º 1
0
class ViewIndexSerializer(serializers.ModelSerializer):

    sites = SiteSerializer(many=True, read_only=True)
    warning = serializers.SerializerMethodField()

    class Meta:
        model = View
        fields = ('id', 'uri', 'key', 'sites', 'title', 'help', 'warning')

    def get_warning(self, obj):
        return get_language_warning(obj, 'title')
Ejemplo n.º 2
0
Archivo: v1.py Proyecto: s4magier/rdmo
class TaskIndexSerializer(serializers.ModelSerializer):

    sites = SiteSerializer(many=True, read_only=True)
    warning = serializers.SerializerMethodField()
    xml_url = serializers.SerializerMethodField()

    class Meta:
        model = Task
        fields = ('id', 'uri', 'uri_prefix', 'key', 'available', 'sites',
                  'title', 'text', 'warning', 'xml_url')

    def get_warning(self, obj):
        return get_language_warning(obj, 'title') or get_language_warning(
            obj, 'text')

    def get_xml_url(self, obj):
        return reverse('v1-tasks:task-detail-export', args=[obj.pk])
Ejemplo n.º 3
0
class ViewIndexSerializer(MarkdownSerializerMixin,
                          serializers.ModelSerializer):

    markdown_fields = ('help', )

    sites = SiteSerializer(many=True, read_only=True)
    warning = serializers.SerializerMethodField()
    xml_url = serializers.SerializerMethodField()

    class Meta:
        model = View
        fields = ('id', 'uri', 'uri_prefix', 'key', 'locked', 'available',
                  'sites', 'title', 'help', 'warning', 'xml_url')

    def get_warning(self, obj):
        return get_language_warning(obj, 'title')

    def get_xml_url(self, obj):
        return reverse('v1-views:view-detail-export', args=[obj.pk])
Ejemplo n.º 4
0
class CatalogNestedSerializer(TranslationSerializerMixin, serializers.ModelSerializer):

    sections = SectionNestedSerializer(many=True, read_only=True)
    sites = SiteSerializer(many=True, read_only=True)
    warning = serializers.SerializerMethodField()
    xml_url = serializers.SerializerMethodField()
    export_urls = serializers.SerializerMethodField()
    projects_count = serializers.IntegerField(read_only=True)

    class Meta:
        model = Catalog
        fields = (
            'id',
            'uri',
            'uri_prefix',
            'key',
            'locked',
            'order',
            'sites',
            'title',
            'help',
            'sections',
            'warning',
            'xml_url',
            'export_urls',
            'projects_count'
        )
        trans_fields = (
            'title',
        )

    def get_warning(self, obj):
        return get_language_warning(obj, 'title')

    def get_xml_url(self, obj):
        return reverse('v1-questions:catalog-detail-export', args=[obj.pk])

    def get_export_urls(self, obj):
        urls = {}
        for key, text in settings.EXPORT_FORMATS:
            urls[key] = reverse('questions_catalog_export', args=[obj.pk, key])
        return urls
Ejemplo n.º 5
0
class CatalogNestedSerializer(TranslationSerializerMixin,
                              serializers.ModelSerializer):

    sections = SectionNestedSerializer(many=True, read_only=True)
    sites = SiteSerializer(many=True, read_only=True)

    urls = serializers.SerializerMethodField()

    class Meta:
        model = Catalog
        fields = ('id', 'key', 'sites', 'title', 'sections', 'urls')
        trans_fields = ('title', )

    def get_urls(self, obj):
        urls = {
            'xml': reverse('questions_catalog_export', args=[obj.pk, 'xml'])
        }
        for key, text in settings.EXPORT_FORMATS:
            urls[key] = reverse('questions_catalog_export', args=[obj.pk, key])
        return urls