Commit 6144b356 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Add dossier scores to representatives votes

parent a69e42c3
<a aria-controls="dossier-15409" aria-expanded="false" data-parent="#accordion-dossier" data-toggle="collapse" href="#dossier-15409" role="button">
Pouvoirs publics : prorogation de l'application de la loi sur l'état d'urgence
</a>
---
<a aria-controls="dossier-15424" aria-expanded="false" data-parent="#accordion-dossier" data-toggle="collapse" href="#dossier-15424" role="button">
Pouvoirs publics : application de la loi relative à l’état d’urgence
</a>
Pouvoirs publics : application de la loi relative à l’état d’urgence
<span class="pull-right">
<span class="badge" data-placement="left" data-toggle="tooltip" title="Score for the representative on this specific dossier">-100</span>
</span>
</a>
---
<a aria-controls="dossier-15409" aria-expanded="false" data-parent="#accordion-dossier" data-toggle="collapse" href="#dossier-15409" role="button">
Pouvoirs publics : prorogation de l'application de la loi sur l'état d'urgence
<span class="pull-right">
<span class="badge" data-placement="left" data-toggle="tooltip" title="Score for the representative on this specific dossier">75</span>
</span>
</a>
---
<a aria-controls="dossier-15407" aria-expanded="false" data-parent="#accordion-dossier" data-toggle="collapse" href="#dossier-15407" role="button">
Pouvoirs publics : prorogation de l'état d'urgence
</a>
\ No newline at end of file
Pouvoirs publics : prorogation de l'état d'urgence
<span class="pull-right">
<span class="badge" data-placement="left" data-toggle="tooltip" title="Score for the representative on this specific dossier">-90</span>
</span>
</a>
\ No newline at end of file
......@@ -6,8 +6,9 @@ class RepresentativeVotesTest(RepresentativeBaseTest):
"""
- One for votes
- One for dossier scores
"""
queries = RepresentativeBaseTest.queries + 1
queries = RepresentativeBaseTest.queries + 2
def test_queries(self):
self.do_query_test()
......
......@@ -23,7 +23,8 @@ class RepresentativeDetailVotes(RepresentativeDetailBase):
'proposal__dossier',
'proposal__recommendation'
).order_by('-proposal__datetime', 'proposal__title')
)
),
'dossierscores'
)
return qs
......@@ -31,7 +32,21 @@ class RepresentativeDetailVotes(RepresentativeDetailBase):
def get_context_data(self, **kwargs):
c = super(RepresentativeDetailVotes, self).get_context_data(**kwargs)
ds = c['object'].dossierscores.all()
dossiers = {}
for vote in c['object'].votes.all():
dossier = vote.proposal.dossier
pk = dossier.pk
if pk not in dossiers:
dossiers[pk] = {
'dossier': dossier,
'votes': [],
'score': [s.score for s in ds if s.dossier_id == pk][0]
}
dossiers[pk]['votes'].append(vote)
c['dossiers'] = dossiers
c['tab'] = 'votes'
c['votes'] = c['object'].votes.all()
return c
......@@ -10,7 +10,7 @@ from representatives.models import Representative
class DossierScore(models.Model):
id = models.CharField(max_length=255, primary_key=True)
representative = models.ForeignKey(Representative,
on_delete=models.DO_NOTHING)
related_name='dossierscores', on_delete=models.DO_NOTHING)
dossier = models.ForeignKey(Dossier, on_delete=models.DO_NOTHING)
score = models.FloatField(default=0)
......
......@@ -371,7 +371,9 @@ iframe {
color: red;
}
.panel.panel-default .badge {
background-color: #487ED6;
}
......
......@@ -8,58 +8,57 @@
<div class="panel-group" id="accordion-dossier" role="tablist" aria-multiselectable="true">
{% regroup votes by proposal.dossier as groups %}
{% for group in groups %}
{% with dossier=group.grouper %}
{% with votes=group.list|dictsortreversed:"proposal.datetime" %}
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="dossier-heading-{{ dossier.pk }}">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion-dossier" href="#dossier-{{ dossier.pk }}" aria-expanded="false" aria-controls="dossier-{{ dossier.pk }}">
{{ dossier.title }}
</a>
</h4>
</div>
<div id="dossier-{{ dossier.pk }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="dossier-heading-{{ dossier.pk }}">
<div class="panel-body">
<table class="table table-striped table-responsive text-center">
<thead>
<tr>
<th class="text-center">{% trans "Proposal" %}</th>
<th class="text-center">{% trans "Recommendation" %}</th>
<th class="text-center">{% trans "Vote" %}</th>
<th class="text-center nowrap">Points&nbsp;<a data-toggle="tooltip" data-placement="top" title="{% trans "Score is negative or positive depending on whether the representative voted as recommended" %}">{% bootstrap_icon "info-sign" %}</a>
</th>
</tr>
</thead>
{% for pk, d in dossiers.items %}
{% with dossier=d.dossier %}
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="dossier-heading-{{ pk }}">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion-dossier" href="#dossier-{{ pk }}" aria-expanded="false" aria-controls="dossier-{{ pk }}">
{{ dossier.title }}
<span class="pull-right">
<span class="badge" data-toggle="tooltip" data-placement="left" title="{% trans "Score for the representative on this specific dossier" %}">{{ d.score }}</span>
</span>
</a>
</h4>
</div>
<div id="dossier-{{ pk }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="dossier-heading-{{ pk }}">
<div class="panel-body">
<tbody>
<table class="table table-striped table-responsive text-center">
{% for vote in votes %}
<thead>
<tr>
<th>{{ vote.proposal.title }}</th>
<td>{{ vote.proposal.recommendation.recommendation|position_icon }}</td>
<td>{{ vote.position|position_icon:vote.proposal.recommendation.recommendation }}</td>
<td>
{{ vote.score }}&nbsp;<a data-toggle="tooltip" data-placement="top" title="{{ vote.proposal.recommendation.title }}">{% bootstrap_icon "info-sign" %}</a>
</td>
<th class="text-center">{% trans "Proposal" %}</th>
<th class="text-center">{% trans "Recommendation" %}</th>
<th class="text-center">{% trans "Vote" %}</th>
<th class="text-center nowrap">Points&nbsp;<a data-toggle="tooltip" data-placement="top" title="{% trans "Score is negative or positive depending on whether the representative voted as recommended" %}">{% bootstrap_icon "info-sign" %}</a>
</th>
</tr>
{% endfor %}
</thead>
<tbody>
{% for vote in d.votes %}
<tr>
<th>{{ vote.proposal.title }}</th>
<td>{{ vote.proposal.recommendation.recommendation|position_icon }}</td>
<td>{{ vote.position|position_icon:vote.proposal.recommendation.recommendation }}</td>
<td>
<span class="badge" data-toggle="tooltip" data-placement="left" title="{{ vote.proposal.recommendation.title }}">{{vote.score }}</span>
</td>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</table>
</div>
</div>
</div>
</div>
{% endwith %}
{% endwith %}
{% endwith %}
{% endfor %}
</div>
......
Supports Markdown
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