From b50b95b4e9cc1eb95be8d08db97fd97a67b79c98 Mon Sep 17 00:00:00 2001 From: Samuel Gaist <samuel.gaist@idiap.ch> Date: Tue, 7 Apr 2020 15:23:09 +0200 Subject: [PATCH] [algorithms][serializers] Pre-commit cleanup --- beat/web/algorithms/serializers.py | 57 +++++++++++++++++++----------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/beat/web/algorithms/serializers.py b/beat/web/algorithms/serializers.py index fa486b256..c04a9c280 100755 --- a/beat/web/algorithms/serializers.py +++ b/beat/web/algorithms/serializers.py @@ -42,7 +42,7 @@ import simplejson as json import beat.core.algorithm -#---------------------------------------------------------- +# ---------------------------------------------------------- class AlgorithmCreationSerializer(CodeCreationSerializer): @@ -51,7 +51,7 @@ class AlgorithmCreationSerializer(CodeCreationSerializer): beat_core_class = beat.core.algorithm -#---------------------------------------------------------- +# ---------------------------------------------------------- class AlgorithmSerializer(CodeSerializer): @@ -62,13 +62,16 @@ class AlgorithmSerializer(CodeSerializer): outputs = serializers.SerializerMethodField() referencing_experiments = serializers.SerializerMethodField() referenced_libraries = LibraryReferenceSerializer(many=True) - referenced_dataformats = ReferencedDataFormatSerializer(many=True, source='all_referenced_dataformats') - needed_dataformats = ReferencedDataFormatSerializer(many=True, source='all_needed_dataformats') + referenced_dataformats = ReferencedDataFormatSerializer( + many=True, source="all_referenced_dataformats" + ) + needed_dataformats = ReferencedDataFormatSerializer( + many=True, source="all_needed_dataformats" + ) class Meta(CodeSerializer.Meta): model = Algorithm - def get_result_dataformat(self, obj): return json.loads(obj.result_dataformat) if obj.result_dataformat else None @@ -76,33 +79,45 @@ class AlgorithmSerializer(CodeSerializer): return json.loads(obj.parameters) if obj.parameters else None def get_inputs(self, obj): - return map(lambda x: { - 'name': x.name, - 'dataformat': x.dataformat.fullname(), - 'channel': x.channel - }, obj.endpoints.filter(input=True).order_by('name')) + return map( + lambda x: { + "name": x.name, + "dataformat": x.dataformat.fullname(), + "channel": x.channel, + }, + obj.endpoints.filter(input=True).order_by("name"), + ) def get_outputs(self, obj): - return map(lambda x: { - 'name': x.name, - 'dataformat': x.dataformat.fullname(), - 'channel': x.channel, - }, obj.endpoints.filter(input=False).order_by('name')) + return map( + lambda x: { + "name": x.name, + "dataformat": x.dataformat.fullname(), + "channel": x.channel, + }, + obj.endpoints.filter(input=False).order_by("name"), + ) def get_referencing_experiments(self, obj): - user = self.context.get('user') - experiments = Experiment.objects.for_user(user, True).filter(blocks=obj.blocks.all()).distinct() + user = self.context.get("user") + experiments = ( + Experiment.objects.for_user(user, True) + .filter(blocks=obj.blocks.all()) + .distinct() + ) serializer = ExperimentSerializer(experiments, many=True) referencing_experiments = serializer.data # Put the pending experiments first - return sorted(referencing_experiments, key=itemgetter('creation_date')) + return sorted(referencing_experiments, key=itemgetter("creation_date")) -#---------------------------------------------------------- +# ---------------------------------------------------------- class FullAlgorithmSerializer(AlgorithmSerializer): - class Meta(AlgorithmSerializer.Meta): - default_fields = AlgorithmSerializer.Meta.default_fields + AlgorithmSerializer.Meta.extra_fields + default_fields = ( + AlgorithmSerializer.Meta.default_fields + + AlgorithmSerializer.Meta.extra_fields + ) -- GitLab