Commit c0a1fc55 authored by Nicolas Cn's avatar Nicolas Cn
Browse files

dossier/votes: add basic table of representatives and votes

parent bd3329a0
......@@ -229,6 +229,11 @@ select:focus, select.form-control:focus {
/***************************************************************
Nav
***************************************************************/
.custom-nav {
background-color: white;
}
@media (min-width: 768px) {
.custom-nav .custom-plus {
margin: -1.5em 0 1.5em 0;
......@@ -244,6 +249,7 @@ select:focus, select.form-control:focus {
.custom-nav {
height: 100%;
position: fixed;
z-index: 100;
overflow-y: auto;
}
}
......@@ -586,3 +592,24 @@ iframe {
.text-danger {
color: #ab181d !important;
}
/***************************************************************
Dossier/Votes
***************************************************************/
.dossier-votes__table {
overflow-x: auto;
}
.dossier-votes__col-representatives {
min-width: 15rem;
white-space: nowrap;
}
.dossier-votes__col-proposal {
min-width: 25rem;
}
.dossier-votes__cell-vote {
text-align: center;
}
......@@ -4,5 +4,61 @@
{% load fontawesome %}
{% load memopol_tags %}
{% comment %}
Expected variables
- 'proposals': proposal list
- 'representatives': representative list
{% endcomment %}
{% block dossier_content %}
{% if not proposals %}
<p class="no-links empty text-center">
{% trans "No proposals has been recorded yet." %}
</p>
{% else %}
<div class="dossier-votes__table">
<table class="table table-responsive table-striped">
<thead>
<tr>
<td class="dossier-votes__col-representatives">{% trans "Representative" %}</td>
{% for proposal in proposals %}
<td class="dossier-votes__col-proposal">{{ proposal.title }}</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for rep,rep_votes in votes_by_rep %}
<tr>
<td class="representative">{{ rep.full_name }}</td>
{% for proposal in proposals %}
{% with rep_votes|getitem:proposal as vote %}
{% with proposal.recommendation.recommendation as reco %}
<td class="dossier-votes__cell-vote">
{% if vote %}
{{ vote.position|proposal_vote_icon:reco }}
{% else %}
{{ 'abstain'|proposal_vote_icon }}
{% endif %}
</td>
{% endwith %}
{% endwith %}
{% endfor %}
<tr/>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
{% endblock %}
......@@ -94,6 +94,21 @@ def proposal_status_label(status, recommendation=None):
pattern = '<span class="label label-%s">%s</span>'
return mark_safe(pattern % (color, status))
@register.filter
def proposal_vote_icon(vote, recommendation=None):
color = 'muted'
if recommendation:
color = 'success' if (vote == recommendation) else 'danger'
status = {
'for': 'thumbs-up',
'abstain': 'circle-o',
'against': 'thumbs-down'
}[vote]
pattern = '<span class="fa fa-%s text-%s"></span>'
return mark_safe(pattern % (status, color))
@register.filter
def score_badge(score, tooltip=None):
......@@ -123,3 +138,7 @@ def cast_str(val):
@register.filter
def proposal_themes(proposal):
return set(proposal.themes.all()) | set(proposal.dossier.themes.all())
@register.filter
def getitem (item, index):
return item.get(index,'')
# coding: utf-8
import collections
from .dossier_detail_base import DossierDetailBase
from representatives_votes.models import Vote
from representatives.models import Representative
class DossierDetailVotes(DossierDetailBase):
template_name = 'representatives_votes/dossier_detail_votes.html'
def get_context_data(self, **kwargs):
c = super(DossierDetailVotes, self).get_context_data(**kwargs)
# Get all Votes related to this Dossier
votes = Vote.objects.filter(proposal__dossier=c['object'])
# Regroup Votes by Representatives
votes_by_rep = collections.defaultdict(dict)
for vote in votes:
votes_by_rep[vote.representative][vote.proposal] = vote
c['tab'] = 'votes'
c['proposals'] = c['object'].proposals.all().order_by('-datetime', 'title')
c['votes_by_rep'] = votes_by_rep.items()
return c
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