Commit f1d6180d authored by Nicolas Joyard's avatar Nicolas Joyard

Add latest votes + home-related settings

parent 598ab2a9
from memopol_settings.models import Setting
from representatives.models import Chamber, Group
......@@ -13,3 +14,13 @@ def search_form_options(request):
d['committees'] = Group.objects.filter(kind='committee')
return d
def intro_text(request):
d = {}
for s in Setting.objects.filter(pk__in=['HOMEPAGE_INTRO_TEXT',
'HOMEPAGE_INSTANCE_TEXT']):
d[s.pk] = s.comment
return d
......@@ -130,6 +130,7 @@ TEMPLATE_LOADERS = (
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.template.context_processors.request',
'memopol.context_processors.search_form_options',
'memopol.context_processors.intro_text'
)
#
......
......@@ -444,6 +444,10 @@ iframe {
margin-left: 1em;
}
.proposal-details, .proposal-details td {
border: 0 !important;
}
/***************************************************************
Icones
***************************************************************/
......
......@@ -12,7 +12,7 @@
</h1>
<p class="lead text-center hidden-xs">{% trans "What is Memopol ?" %}</p>
<p class="text-justify hidden-xs">
{% include "text/short_description.html" %}
{{ HOMEPAGE_INTRO_TEXT }}
</p>
{% if position_form %}
<div class="container-fluid hidden-xs">
......
......@@ -3,6 +3,7 @@
{% load i18n %}
{% load fontawesome %}
{% load staticfiles %}
{% load memopol_tags %}
{% block content %}
<div class="row">
......@@ -13,18 +14,55 @@
<div class="row">
<div class="col-md-12">
<h2>{% trans "What is Memopol ?" %}</h2>
<p>
{% include "text/short_description.html" %}
{{ HOMEPAGE_INTRO_TEXT }}
</p>
<h2>{% trans "What about this instance ?" %}</h2>
<p>
{% include "text/license.html" %}
{{ HOMEPAGE_INSTANCE_TEXT }}
</p>
</div>
</div>
<div class="row">
<div class="col-md-4">
placeholder
<h2>{% trans "Latest votes" %}</h2>
<table class="table table-responsive table-condensed">
<tr>
<th></th>
<th></th>
<th></th>
<th>{{ "for"|position_icon }}</th>
<th>{{ "against"|position_icon }}</th>
<th>{{ "abstain"|position_icon }}</th>
</tr>
{% for proposal in latest_votes %}
<tr class="proposal-title {% if forloop.counter0|divisibleby:2 %}active{% endif %}">
<td colspan="6">
<a href="{% url 'dossier-detail' proposal.dossier.pk %}">
{{ proposal.title }}
</a>
</td>
</tr>
<tr class="proposal-details {% if forloop.counter0|divisibleby:2 %}active{% endif %}">
<td>
{% for chamber in proposal.dossier.chambers %}
{{ chamber | chamber_icon }}
{% endfor %}
</td>
<td>
{% include "blocks/_themetags.html" with themes=proposal|proposal_themes %}
</td>
<td>{{ proposal.status|proposal_status_label:proposal.recommendation }}</td>
<td>{{ proposal.total_for }}</td>
<td>{{ proposal.total_against }}</td>
<td>{{ proposal.total_abstain }}</td>
</tr>
{% endfor %}
</table>
</div>
<div class="col-md-4">
......@@ -89,4 +127,14 @@
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>
<br><br>
{% include "text/license.html" %}
<br><br>
</p>
</div>
</div>
{% endblock %}
{% load i18n %}
{% blocktrans %}
Political Memory is a tool designed by La Quadrature du Net to help
citizens to reach their representatives and
track their voting records on issues related to fundamental
freedoms online.
{% endblocktrans %}
......@@ -118,3 +118,8 @@ def score_badge(score, tooltip=None):
@register.filter
def cast_str(val):
return str(val)
@register.filter
def proposal_themes(proposal):
return set(proposal.themes.all()) | set(proposal.dossier.themes.all())
......@@ -8,7 +8,9 @@ from django.views import generic
from representatives.models import Representative
from representatives_positions.views import PositionFormMixin
from representatives_votes.models import Proposal
from memopol_settings.models import Setting
from memopol_themes.models import Theme
from .representative_mixin import RepresentativeViewMixin
......@@ -45,4 +47,11 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin,
nb_positions=Count('positions', distinct=True)
)
# Last votes
num = int(Setting.objects.get(pk='HOMEPAGE_LATEST_VOTES').value)
c['latest_votes'] = Proposal.objects \
.filter(recommendation__isnull=False) \
.order_by('-datetime')[0:num]
return c
[
{
"model": "memopol_settings.setting",
"pk": "HOMEPAGE_LATEST_VOTES",
"fields": {
"value": "5",
"comment": "Number of 'latest votes' to show on the homepage."
}
},
{
"model": "memopol_settings.setting",
"pk": "HOMEPAGE_INTRO_TEXT",
"fields": {
"value": "** Use comment field for this setting **",
"comment": "Political Memory is a tool to help citizens reach their representatives and track their voting records."
}
},
{
"model": "memopol_settings.setting",
"pk": "HOMEPAGE_INSTANCE_TEXT",
"fields": {
"value": "** Use comment field for this setting **",
"comment": "This instance of Memopol is run by La Quadrature du Net and tracks issues related to fundamental freedoms online."
}
}
]
\ No newline at end of file
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import os
from django.core import serializers
from django.db import migrations, models
fixture_dir = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'../fixtures'))
fixture_filename = 'homepage_settings.json'
def load_fixture(apps, schema_editor):
fixture_file = os.path.join(fixture_dir, fixture_filename)
fixture = open(fixture_file, 'rb')
objects = serializers.deserialize('json', fixture, ignorenonexistent=True)
for obj in objects:
obj.save()
fixture.close()
class Migration(migrations.Migration):
dependencies = [
('memopol_settings', '0001_initial'),
]
operations = [
migrations.RunPython(load_fixture),
]
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