Skip to content
This repository has been archived by the owner on Apr 14, 2019. It is now read-only.

Commit

Permalink
Fix referendum supporting/opposing
Browse files Browse the repository at this point in the history
Use ballot_item_selection from referendum to find supporting/opposing
contributions.
  • Loading branch information
adborden committed Aug 21, 2016
1 parent d2a7a7d commit 9019801
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion disclosure/tests/test_api_supporting_opposing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from finance.models import Beneficiary


@with_form460A_data(test_agency='CSD', test_year='2015')
@with_form460A_data(test_agency='COS', test_year='2015')
class OpposingTests(APITestCase):

def do_the_thing_for_candidates(self, support):
Expand All @@ -18,6 +18,7 @@ def do_the_thing_for_candidates(self, support):
url = reverse('candidate_%s' % ('supporting' if support else 'opposing'),
kwargs={'candidate_id': candidate.id})
resp = self.client.get(url)
self.assertEquals(resp.status_code, 200)
self.assertTrue(len(resp.data) > 0)

# TODO: replace dummy tests with live data tests.
Expand All @@ -41,7 +42,9 @@ def do_the_thing_for_referendums(self, support):
url = reverse('referendum_%s' % ('supporting' if support else 'opposing'),
kwargs={'referendum_id': referendum.id})
resp = self.client.get(url)
self.assertEquals(resp.status_code, 200)
self.assertTrue(len(resp.data) > 0)
print(resp.data)

# TODO: replace dummy tests with live data tests.
row = resp.data[0]
Expand Down
16 changes: 11 additions & 5 deletions disclosure/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rest_framework.response import Response

from .serializers import BeneficiaryMoneyReceivedSerializer
from ballot.models import Ballot, BallotItemSelection
from ballot.models import Ballot, BallotItemSelection, ReferendumSelection
from finance.models import Beneficiary, IndependentMoney
from finance.views import summarize_money
from locality.models import Locality
Expand Down Expand Up @@ -131,18 +131,24 @@ def supporting(self, request, referendum_id):
"""
List of committees supporting a referendum, and level of benefits given.
"""
# ballot_item_selection_id = # query from referendumresponse model
ballot_item_selection = get_object_or_404(
ReferendumSelection,
in_favor=True,
ballot_item__id=referendum_id)
return super(ReferendumViewSet, self).supporting(
request, ballot_item_selection_id=referendum_id)
request, ballot_item_selection_id=ballot_item_selection.id)

@list_route(['GET'])
def opposing(self, request, referendum_id):
"""
List of committees opposing a referendum, and level of benefits given.
"""
# ballot_item_selection_id = # query from referendumresponse model
ballot_item_selection = get_object_or_404(
ReferendumSelection,
in_favor=False,
ballot_item__id=referendum_id)
return super(ReferendumViewSet, self).opposing(
request, ballot_item_selection_id=referendum_id)
request, ballot_item_selection_id=ballot_item_selection.id)


class CandidateViewSet(BallotItemSelectionViewSet):
Expand Down

0 comments on commit 9019801

Please sign in to comment.