Commit ce5bf7f6 authored by Jamesie Pic's avatar Jamesie Pic

PEP8

parent eebec1ea
......@@ -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'],
......
......@@ -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 + (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment