diff --git a/representatives_votes/format.json b/representatives_votes/format.json index 2537fbe12d9c289d1163e901e31b82f399ab4764..34aec27961fa1c8e4ef5a618841d173855c82dba 100644 --- a/representatives_votes/format.json +++ b/representatives_votes/format.json @@ -1,11 +1,12 @@ { - "Dossier": { + "dossier": { "title": "", // Dossier title, eg "2011/0167(NLE) EU/Australia, Canada, Japan, Korea, Mexico, Morocco, New Zealand, Singapore, Switzerland and United States Anti-Counterfeiting Trade Agreement (ACTA)" "reference": "", // Dossier reference, eg "2011/0167(NLE)" "text": "", // Descriptipn - "Proposals": [{ + "proposals": [{ "title": "", // eg A7-0204/2012 - David Martin - Request for referral back to committee - "reference", "", // eg A7-0204/2012 + "reference": "", // eg A7-0204/2012 + "description": "", "kind": "", "date": "", // timestamp "votes": [{ diff --git a/representatives_votes/migrations/0003_auto_20150513_0936.py b/representatives_votes/migrations/0003_auto_20150513_0936.py new file mode 100644 index 0000000000000000000000000000000000000000..d4d603676ad28e39fdaa4fb138e05804d52fd15b --- /dev/null +++ b/representatives_votes/migrations/0003_auto_20150513_0936.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('representatives_votes', '0002_auto_20150511_1209'), + ] + + operations = [ + migrations.AddField( + model_name='proposal', + name='kind', + field=models.CharField(max_length=200, null=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='proposal', + name='reference', + field=models.CharField(max_length=200, null=True), + preserve_default=True, + ), + ] diff --git a/representatives_votes/migrations/0004_auto_20150513_1216.py b/representatives_votes/migrations/0004_auto_20150513_1216.py new file mode 100644 index 0000000000000000000000000000000000000000..ba4e5b3a2c91a4139bd4932cb6c38240e0bffe2f --- /dev/null +++ b/representatives_votes/migrations/0004_auto_20150513_1216.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('representatives_votes', '0003_auto_20150513_0936'), + ] + + operations = [ + migrations.RenameField( + model_name='vote', + old_name='representative_slug', + new_name='representative_name', + ), + ] diff --git a/representatives_votes/models.py b/representatives_votes/models.py index 45db9e98a362e901aa48bdcce879293181dd070c..60d2062de64ae25657309c567480acf0e8391d5f 100644 --- a/representatives_votes/models.py +++ b/representatives_votes/models.py @@ -14,9 +14,9 @@ class Proposal(models.Model): dossier = models.ForeignKey(Dossier) title = models.CharField(max_length=500) description = models.TextField() - reference = models.CharField(max_length=200) + reference = models.CharField(max_length=200, null=True) datetime = models.DateTimeField() - + kind = models.CharField(max_length=200, null=True) total_abstain = models.IntegerField() total_against = models.IntegerField() total_for = models.IntegerField() @@ -31,7 +31,8 @@ class Vote(models.Model): proposal = models.ForeignKey(Proposal) - representative_slug = models.CharField(max_length=200, blank=True, null=True) + # There are two representative fields for flexibility, + representative_name = models.CharField(max_length=200, blank=True, null=True) representative_remote_id = models.CharField(max_length=200, blank=True, null=True) position = models.CharField(max_length=10, choices=VOTECHOICES) diff --git a/representatives_votes/utils.py b/representatives_votes/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..bb8492ca3ba0281fc71e92f61132d2a0cbeec2f9 --- /dev/null +++ b/representatives_votes/utils.py @@ -0,0 +1,35 @@ +from .models import Dossier + +def export_all_dossiers(): + return [export_a_dossier(dossier) for dossier in Dossier.objects.all()] + +def export_a_dossier(dossier): + ret = {'dossier': { + 'title': dossier.title, + 'reference': dossier.reference, + 'text': dossier.text + }} + + ret['proposals'] = [export_a_proposal(proposal) for proposal in dossier.proposal_set.all()] + + return ret + +def export_a_proposal(proposal): + ret = { + 'title': proposal.title, + 'reference': proposal.reference, + 'description': proposal.description, + 'date': proposal.datetime.isoformat(), + 'total_abstain': proposal.total_abstain, + 'total_against': proposal.total_against, + 'total_for': proposal.total_for + } + + ret['votes'] = [export_a_vote(vote) for vote in proposal.vote_set.all()] + return ret + +def export_a_vote(vote): + return { + 'representative': vote.representative_remote_id, + 'postion': vote.position + }