From ce5bf7f65ed9dccbb70234226fad3ed383734ce9 Mon Sep 17 00:00:00 2001 From: jpic <jamespic@gmail.com> Date: Wed, 27 Jan 2016 01:44:44 +0100 Subject: [PATCH] PEP8 --- representatives_votes/api.py | 39 ++++++++++++++++++++++------ representatives_votes/serializers.py | 22 +++++++--------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/representatives_votes/api.py b/representatives_votes/api.py index cc7b8f4..193c65c 100644 --- a/representatives_votes/api.py +++ b/representatives_votes/api.py @@ -26,7 +26,11 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet): queryset = Dossier.objects.all() serializer_class = DossierSerializer - filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter) + filter_backends = ( + filters.DjangoFilterBackend, + filters.SearchFilter, + filters.OrderingFilter + ) filter_fields = { 'fingerprint': ['exact'], @@ -34,9 +38,15 @@ class DossierViewSet(viewsets.ReadOnlyModelViewSet): 'reference': ['exact', 'icontains'], } - search_fields = ('title', 'fingerprint', 'reference', 'text', 'proposals__title') - ordering_fields = ('id', 'reference') + search_fields = ( + 'title', + 'fingerprint', + 'reference', + 'text', + 'proposals__title' + ) + ordering_fields = ('id', 'reference') def list(self, request): return super(DossierViewSet, self).list(request) @@ -54,7 +64,11 @@ class ProposalViewSet(viewsets.ReadOnlyModelViewSet): queryset = Proposal.objects.all() serializer_class = ProposalSerializer - filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter) + filter_backends = ( + filters.DjangoFilterBackend, + filters.SearchFilter, + filters.OrderingFilter + ) filter_fields = { 'fingerprint': ['exact'], @@ -66,9 +80,14 @@ class ProposalViewSet(viewsets.ReadOnlyModelViewSet): 'kind': ['exact'], } - search_fields = ('title', 'fingerprint', 'reference', - 'dossier__fingerprint', 'dossier__title', - 'dossier__reference') + search_fields = ( + 'title', + 'fingerprint', 'reference', + 'dossier__fingerprint', + 'dossier__title', + 'dossier__reference' + ) + ordering_fields = ('id', 'reference') def list(self, request): @@ -87,7 +106,11 @@ class VoteViewSet(viewsets.ReadOnlyModelViewSet): queryset = Vote.objects.all() serializer_class = VoteSerializer - filter_backends = (filters.DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter) + filter_backends = ( + filters.DjangoFilterBackend, + filters.SearchFilter, + filters.OrderingFilter + ) filter_fields = { 'proposal__fingerprint': ['exact'], diff --git a/representatives_votes/serializers.py b/representatives_votes/serializers.py index d2b1a3c..e5db2ef 100644 --- a/representatives_votes/serializers.py +++ b/representatives_votes/serializers.py @@ -34,7 +34,7 @@ class VoteSerializer(serializers.ModelSerializer): source='representative.fingerprint', allow_null=True ) - + class Meta: model = models.Vote fields = ( @@ -74,7 +74,7 @@ class ProposalSerializer(serializers.ModelSerializer): source='dossier.reference', read_only=True ) - + class Meta: model = models.Proposal fields = ( @@ -95,13 +95,14 @@ class ProposalSerializer(serializers.ModelSerializer): ) def to_internal_value(self, data): - validated_data = super(ProposalSerializer, self).to_internal_value(data) + validated_data = super(ProposalSerializer, self).to_internal_value( + data) validated_data['dossier'] = models.Dossier.objects.get( fingerprint=validated_data['dossier']['fingerprint'] ) validated_data['votes'] = data['votes'] return validated_data - + def _create_votes(self, votes_data, proposal): for vote in votes_data: serializer = VoteSerializer(data=vote) @@ -109,7 +110,7 @@ class ProposalSerializer(serializers.ModelSerializer): serializer.save() else: raise Exception(serializer.errors) - + def create(self, validated_data): votes_data = validated_data.pop('votes') proposal = models.Proposal.objects.create( @@ -129,7 +130,7 @@ class ProposalSerializer(serializers.ModelSerializer): class ProposalDetailSerializer(ProposalSerializer): """ Proposal serializer that includes votes """ votes = VoteSerializer(many=True) - + class Meta(ProposalSerializer.Meta): fields = ProposalSerializer.Meta.fields + ( 'votes', @@ -152,13 +153,10 @@ class DossierSerializer(serializers.ModelSerializer): class DossierDetailSerializer(DossierSerializer): - """ - Dossier serializer that includes proposals - and votes """ - proposals = ProposalDetailSerializer( - many = True, - ) + Dossier serializer that includes proposals and votes. + """ + proposals = ProposalDetailSerializer(many=True) class Meta(DossierSerializer.Meta): fields = DossierSerializer.Meta.fields + ( -- GitLab