Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] import data from an API using an admin view #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions representatives_votes/contrib/parltrack/import_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ def parse_proposal_data(self, proposal_data, dossier_pk):
changed = True

if changed:
logger.debug('Saving proposal %s' %
proposal_data.get('epref', proposal_data['title']))
proposal.save()

responses = vote_pre_import.send(sender=self, vote_data=proposal_data)

for receiver, response in responses:
if response is False:
logger.debug(
'Skipping dossier %s', proposal_data.get(
'epref', proposal_data['title']))
'Skipping votes for dossier %s because of %s',
proposal_data.get( 'epref', proposal_data['title']),
receiver)
return

positions = ['For', 'Abstain', 'Against']
Expand Down
4 changes: 1 addition & 3 deletions representatives_votes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ProposalDetailSerializer(ProposalSerializer):

class Meta:
model = models.Proposal
fields = ProposalSerializer.Meta.fields + ('votes',)


class DossierSerializer(serializers.HyperlinkedModelSerializer):
Expand All @@ -64,8 +63,7 @@ class DossierDetailSerializer(DossierSerializer):
"""
Dossier serializer that includes proposals and votes.
"""

proposals = ProposalSerializer(many=True)
proposals = ProposalDetailSerializer(many=True)

class Meta:
model = models.Dossier
Expand Down
11 changes: 11 additions & 0 deletions representatives_votes/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django import test


class RetrieverSpec(test.TestCase):
# Should:
# - sync any dossier where title='', dossiers are inserted by a custom
# admin feature
# - sync any proposal without vote, proposals should be added on
# dossier-sync, so any dossier in our db should have votes for every
# proposal at some point.

3 changes: 3 additions & 0 deletions representatives_votes/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ def test_proposals(self):
def test_vote(self):
self.functional_test(1, '/api/votes/1/')

def test_proposals(self):
self.functional_test(1, '/api/proposals/')

def test_votes(self):
self.functional_test(1, '/api/votes/')