Commit 27d3dfe5 authored by Arnaud Fabre's avatar Arnaud Fabre

Design improvements

Adds-flag icons
Adds fluid containers
Adds a memopolVote proxy model
parent 4ecd390c
......@@ -2,7 +2,8 @@
"name": "Memopol",
"version": "3.0.0",
"dependencies": {
"bootstrap": "~3.3.5"
"bootstrap": "~3.3.5",
"flag-icon-css": "~0.7.1"
},
"devDependencies": {
"fontawesome": "~4.3.0"
......
......@@ -22,7 +22,7 @@
</head>
<body {% block bodyattrs %}{% endblock %}>
{% include "core/blocks/header.html" %}
<div class="container main-container">
<div class="container-fluid main-container">
{% block content %}
{% endblock %}
</div>
......
- load i18n
#footer.container
#footer.container-fluid
- blocktrans
Memopol is free software
<a href="https://gitorious.org/memopol2-0">released</a>
......
......@@ -3,7 +3,7 @@
- load cache
- load staticfiles
#header.container
#header.container-fluid
%a{href: "/", id: 'logo'}
%img{src: '{% static "images/logo.png" %}'}
%h1
......@@ -12,6 +12,5 @@
%p.organization
=config.ORGANIZATION_NAME
#nav.container
#nav.container-fluid
-include "core/blocks/navigation.html"
......@@ -24,10 +24,10 @@ from django.db import models
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.functional import cached_property
# from django.utils.functional import cached_property
from representatives.models import Representative, Mandate, Country
from representatives_votes.models import Vote
from votes.models import MemopolVote
from core.utils import create_child_instance_from_parent
......@@ -39,21 +39,7 @@ class MemopolRepresentative(Representative):
def update_score(self):
score = 0
for vote in self.votes.all():
proposal = vote.proposal
try:
if proposal.recommendation:
recommendation = proposal.recommendation
if ( vote.position != recommendation.recommendation
and (
vote.position == 'abstain' or
recommendation.recommendation == 'abstain' )):
score -= (recommendation.weight / 2)
elif vote.position != recommendation.recommendation:
score -= recommendation.weight
else:
score += recommendation.weight
except Exception:
pass
score += vote.absolute_score
self.score = score
self.save()
......@@ -102,10 +88,10 @@ class MemopolRepresentative(Representative):
)
def votes_with_proposal(self):
return self.votes.select_related(
return MemopolVote.objects.select_related(
'proposal',
'proposal__recommendation'
)
).filter(representative=self)
@receiver(post_save, sender=Representative)
......
- load by_group_url
- load representatives_extras
.representative
%h1.name
={representative.full_name}
={representative.full_name}
.row
.col-md-4
......@@ -15,12 +15,11 @@
%tr.score
%th Score
%td
%span.label.label-success
%a{:href => '#votes'}
= representative.score
= representative.score|score_label
%tr
%th Country
%td= representative.country.name
%td
= representative.country|country_flag
%tr
%th Party
%td
......
......@@ -3,29 +3,38 @@
- extends 'base.html'
- load humanize
- load by_group_url
- load representatives_extras
- load bootstrap3
- block head
{{ position_form.media }}
- block content
- include 'legislature/blocks/representative_header.html' with representative=representative
%h2#votes Votes
.row
.col-md-6
- include 'legislature/blocks/representative_block.html' with representative=representative
.col-md-6
%h2#votes Votes
%table.table.table-condensed.votes
%tr
%th Title
%th Position
%th Recommendation
%th Score
%table.table.table-condensed.votes
%tr
%th Title
%th.icon-cell
Memopol recommendation
%th.icon-cell
Representative vote
%th.icon-cell
Score
- for vote in representative.votes_with_proposal.all
%tr
%td= vote.proposal.recommendation.title
%td= vote.position
%td= vote.proposal.recommendation.recommendation
%td= vote.proposal.recommendation.weight
- for vote in representative.votes_with_proposal.all
%tr
%td= vote.proposal.recommendation.title
%td.icon-cell
= vote.proposal.recommendation.recommendation|position_icon
%td.icon-cell
= vote.position|position_icon
%td.icon-cell
= vote.absolute_score|score_label
%h2 Mandates
......
- extends 'base.html'
- load by_group_url
- load representatives_extras
- block content
......@@ -27,16 +27,16 @@
%td
%a{'href': "{% url 'legislature:representative-detail' name=representative.slug %}"}
={representative.full_name}
= representative.full_name
%td
%a{'href': "{% url 'legislature:representative-index' group_kind='country' group=representative.country.code %}"}
={representative.country.name}
= representative.country|country_flag
%td
%a{'href': "{{ representative.main_mandate|by_group_url }}"}
={representative.main_mandate.group.abbreviation}
= representative.main_mandate.group.abbreviation
%td
={representative.score}
= representative.score|score_label
- include "core/blocks/pagination.html"
from django import template
from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
from representatives.models import Mandate, Group
register = template.Library()
@register.filter
def position_icon(position):
if position == 'for':
return mark_safe(
'<i \
aria-label="for" \
class="fa fa-thumbs-up vote_positive" \
title="for" \
></i>')
elif position == 'against':
return mark_safe(
'<i \
aria-label="against" \
class="fa fa-thumbs-down vote_negative" \
title="against" \
></i>')
else:
return mark_safe(
'<i \
aria-label="abstain" \
class="fa fa-circle-o vote_abstain" \
title="abstain" \
></i>')
@register.filter
def score_label(score):
if score > 0:
return mark_safe('<span class="label label-success">{}</span>'.format(score))
elif score < 0:
return mark_safe('<span class="label label-danger">{}</span>'.format(score))
else:
return mark_safe('<span class="label label-default">{}</span>'.format(score))
@register.filter
def country_flag(country):
return mark_safe('{} <span class="flag-icon flag-icon-{}"></span>'.format(
country.name,
country.code.lower()
))
@register.filter
def by_group_url(group):
if isinstance(group, Mandate):
group = group.group
if not isinstance(group, Group):
return ''
kwargs = {'group_kind': group.kind}
if group.abbreviation:
kwargs['group'] = group.abbreviation
else:
kwargs['group'] = group.name
# kwargs['group_id'] = group.id
return reverse(
'legislature:representative-index',
kwargs=kwargs
)
......@@ -10,7 +10,7 @@ body {
background: #E5E5E5;
}
.container {
.container, .container-fluid {
background: white;
}
......
......@@ -23,3 +23,15 @@
width: 50%;
margin: auto;
}
.vote_negative {
color: red;
}
.vote_positive {
color: green;
}
.vote_abstain {
color: #333;
}
\ No newline at end of file
@import '../libs/bootstrap/less/bootstrap';
@import '../libs/fontawesome/less/font-awesome';
// Flag icons
@import '../libs/flag-icon-css/less/variabless';
@flag-icon-css-path: '../libs/flag-icon-css/flags';
@import '../libs/flag-icon-css/less/flag-icon-base';
@import '../libs/flag-icon-css/less/flag-icon-list';
......@@ -7,6 +7,10 @@ table.detail-view {
text-align: right;
}
th:after{
content: ' :';
content: ' :';
}
}
.icon-cell {
text-align: center;
}
\ No newline at end of file
......@@ -79,7 +79,10 @@ table.detail-view th {
text-align: right;
}
table.detail-view th:after {
content: ' :';
content: ' :';
}
.icon-cell {
text-align: center;
}
.representative h1 {
text-align: center;
......@@ -100,6 +103,15 @@ table.detail-view th:after {
width: 50%;
margin: auto;
}
.vote_negative {
color: red;
}
.vote_positive {
color: green;
}
.vote_abstain {
color: #333;
}
.quote {
width: 70%;
margin: auto;
......@@ -123,7 +135,8 @@ table.detail-view th:after {
body {
background: #E5E5E5;
}
.container {
.container,
.container-fluid {
background: white;
}
.main-container {
......
This diff is collapsed.
......@@ -23,9 +23,9 @@ from django.utils.functional import cached_property
from django.db.models.signals import post_save
from django.dispatch import receiver
from representatives.models import Representative
# from representatives.models import Representative
from representatives_votes.models import Vote, Proposal, Dossier
from legislature.models import MemopolRepresentative
# from legislature.models import MemopolRepresentative
from core.utils import create_child_instance_from_parent
......@@ -72,3 +72,23 @@ class MemopolDossier(Dossier):
@receiver(post_save, sender=Dossier)
def create_memopolrepresentative_from_representative(instance, **kwargs):
create_child_instance_from_parent(MemopolDossier, instance)
class MemopolVote(Vote):
class Meta:
proxy = True
@cached_property
def absolute_score(self):
if self.proposal.recommendation:
recommendation = self.proposal.recommendation
weight = recommendation.weight
if (self.position == 'abstain' or
recommendation.recommendation == 'abstain'):
weight = weight / 2
if self.position == recommendation.recommendation:
return weight
else:
return -weight
else:
return 0
......@@ -9,7 +9,7 @@
- for dossier in object_list
%tr
%td
%a{'href': "{% url 'votes:dossier_detail' pk=dossier.id %}"}
%a{'href': "{% url 'votes:dossier-detail' pk=dossier.id %}"}
{{ dossier.name }}
%td= dossier.reference
%td= dossier.proposals.count
......
Markdown is supported
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