Source code for beat.web.toolchains.serializers

#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.web module of the BEAT platform.              #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################

from rest_framework import serializers

import beat.core.toolchain

from ..attestations.serializers import AttestationSerializer
from ..common.serializers import ContributionCreationSerializer
from ..common.serializers import ContributionModSerializer
from ..common.serializers import ContributionSerializer
from ..experiments.serializers import ExperimentSerializer
from .models import Toolchain

# ----------------------------------------------------------


[docs]class ToolchainCreationSerializer(ContributionCreationSerializer):
[docs] class Meta(ContributionCreationSerializer.Meta): model = Toolchain beat_core_class = beat.core.toolchain.Toolchain
# ----------------------------------------------------------
[docs]class ToolchainModSerializer(ContributionModSerializer):
[docs] class Meta(ContributionModSerializer.Meta): model = Toolchain beat_core_class = beat.core.toolchain.Toolchain
# ----------------------------------------------------------
[docs]class ToolchainSerializer(ContributionSerializer): valid = serializers.BooleanField(source="is_valid") attestations = AttestationSerializer(many=True) referencing_experiments = serializers.SerializerMethodField() new_experiment_url = serializers.SerializerMethodField()
[docs] class Meta(ContributionSerializer.Meta): model = Toolchain
[docs] def get_referencing_experiments(self, obj): user = self.context.get("user") experiments = obj.experiments.for_user(user, True).order_by("-creation_date") serializer = ExperimentSerializer(experiments, many=True) referencing_experiments = serializer.data # Put the pending experiments first ordered_result = filter( lambda x: x["creation_date"] is None, referencing_experiments ) ordered_result += filter( lambda x: x["creation_date"] is not None, referencing_experiments ) return ordered_result
[docs] def get_new_experiment_url(self, obj): return obj.get_new_experiment_url()
# ----------------------------------------------------------
[docs]class FullToolchainSerializer(ToolchainSerializer):
[docs] class Meta(ToolchainSerializer.Meta): default_fields = ( ToolchainSerializer.Meta.default_fields + ToolchainSerializer.Meta.extra_fields )