Commit 704fbd93 authored by Arnaud Fabre's avatar Arnaud Fabre

Cleans core app and adds 3rd parties libs

- Cleans core app by removing useless files
- Organizes utils in a utils directory
- Creates a digg-like pagination class
http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-
django
- Adds constance to installed app to manage settings in django admin
console
- Adds debug_toolbar and django_extensions in dev mode
parent dcc0cd3d
*.sqlite3
celerybeat-*
core/static/libs/*
deploy
# libs
static/libs
......
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
......@@ -6,17 +6,20 @@
<!-- Set the viewport width to device width for mobile -->
<meta name="viewport" content="width=device-width" />
{% block head %}{% endblock %}
<title>{% block title %}Home{% endblock %} - The Political Memory of {{ organization_name }}</title>
<link rel="stylesheet" href="{{ STATIC_URL }}css/reset.css" type="text/css" />
<link rel="stylesheet" href="{{ STATIC_URL }}css/base.css" type="text/css" />
<title>
{% block title %}Home{% endblock %}
- The Political Memory of {{ config.ORGANIZATION_NAME }}</title>
{% load compress %}
{% load staticfiles %}
{% compress css %}
<link rel="stylesheet" href="{% static 'stylesheets/base.min.css' %}" type="text/css" />
{% endcompress %}
</head>
<body {% block bodyattrs %}{% endblock %}>
{% include "core/blocks/header.html" %}
<div class="row main">
<div class="large-12 main columns">
{% block content %}
{% endblock %}
</div>
<div class="container main-container">
{% block content %}
{% endblock %}
</div>
{% include "core/blocks/footer.html" %}
</body>
......
- load i18n
#footer.row
%ul
%li
- blocktrans
Memopol is free software
<a href="https://gitorious.org/memopol2-0">released</a>
under the terms of the
<a href="http://www.gnu.org/licenses/agpl.html">GNU aGPLV3+</a>
%li
-# %a{href: "{% url about %}"}
-# - trans "About"
%li
%a{href: "https://projets.lqdn.fr/projects/mempol"}
- trans "Bug tracking system"
%li
%a{href: "https://projets.lqdn.fr/projects/mempol/issues/new"}
- trans "Report a bug"
%ul
%li
-# %a{href: "{% url api_doc %}"}
-# API
%li
-# %a{href: "{% url contact_form %}"}
-# Contact
-# - if user.is_staff
-# %li
-# %a{href: "{% url admin:index %}"}
-# - trans "Administration"
-# %li
-# %a{href: "{% url admin:comments_comment_changelist %}"}
-# - trans "Comments moderation"
-# %li
-# %a{href: "{% url admin:logout %}"}
-# - trans "Logout"
-# -if user.is_anonymous
-# %li
-# %a{href: "{% url admin:index %}"}
-# - trans "Login"
%ul
%li
{% trans "Provided by" %} <a href="http://www.laquadrature.net/">La Quadrature du Net</a>
#footer.container
- blocktrans
Memopol is free software
<a href="https://gitorious.org/memopol2-0">released</a>
under the terms of the
<a href="http://www.gnu.org/licenses/agpl.html">GNU aGPLV3+</a>
%a{href: "https://projets.lqdn.fr/projects/mempol"}
- trans "Bug tracking system"
%a{href: "https://projets.lqdn.fr/projects/mempol/issues/new"}
- trans "Report a bug"
%br
{% trans "Provided by" %} <a href="http://www.laquadrature.net/">La Quadrature du Net</a>
/ -load memopol_tags cache
- load i18n
- load cache
- load staticfiles
.row.large-12.head
#header
%a{href: "/"}
%img{src: "https://memopol.lqdn.fr/static/img/logo.png"}/
%h1
%a#header_banner{href: "/"}
-trans "Political Memory"
%p
=organization_name
#header.container
%a{href: "/", id: 'logo'}
%img{src: '{% static "images/logo.png" %}'}
%h1
%a#header_banner{href: "/"}
-trans "Political Memory"
%p.organization
=config.ORGANIZATION_NAME
-include "core/blocks/navigation.html"
#nav.container
-include "core/blocks/navigation.html"
%ul.nav-bar
%ul.nav
%li
%a{href: "{% url 'legislature:representative_index' %}"}
Representatives
%li
%em By :
%li
%a{href: "{% url 'legislature:group_index' kind='country' %}"}
Countries
......@@ -17,7 +15,7 @@
%a{href: "{% url 'legislature:group_index' kind='committee' %}"}
Committees
%ul.nav-bar
%ul.nav
%li
%a{href: "{% url 'votes:dossier_index' %}"}
Votes
-# Pagination block display pagination for the `object_list`
`object_list` could be generated with core.view_utils.render_paginate_list
.pagination
%span.step-links
- if object_list.has_previous
%a{'href': '?={queries.urlencode}&page=={object_list.previous_page_number}'} previous
%span.current
Page ={object_list.number} of ={object_list.paginator.num_pages}
- if object_list.has_next
%a{'href': '?={queries.urlencode}&page=={object_list.next_page_number}'} next
.pagination-block
%nav
%ul.pagination.pagination-sm
- if object_list.has_previous
%li
%a{'href': '?={queries.urlencode}&page=={object_list.previous_page_number}',
'aria-label': 'Previous'}
<i aria-hidden="true" class="fa fa-chevron-left"></i>
- for page_num in object_list.page_range
- if not page_num
%li.disabled
%a{'href': ''}
- elif page_num == object_list.number
%li.active
%a{'href': ''}
{{ page_num }}
- else
%li
%a{'href': '?={queries.urlencode}&page=={page_num}'}
{{ page_num }}
- if object_list.has_next
%li
%a{'href': '?={queries.urlencode}&page=={object_list.next_page_number}',
'aria-label': 'Next'}
<i aria-hidden="true" class="fa fa-chevron-right"></i>
%div.count
Number of results : {{ paginator.count }}
%br
Number of displayed results :
{{ paginator.per_page }}
(
- for limit in pagination_limits
%a{'href': '?limit={{ limit }}'}
{{ limit }}
- if not forloop.last
\/
)
.panel.callout
%h3
What is memopol?
%p
Political Memory is a tool designed by La Quadrature du Net to help
European citizens to reach members of European Parliament (MEPs) and
track their voting records on issues related to fundamental
freedoms online. <em><a href="">More...</a></em>
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from create_child_instance_from_parent import create_child_instance_from_parent
from render_paginate_list import render_paginate_list
......@@ -19,32 +19,18 @@
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from __future__ import absolute_import
from django.core.exceptions import ObjectDoesNotExist
def create_child_instance_from_parent(child_cls, parent_instance):
"""
Create a child model instance from a parent instance
"""
parent_cls = parent_instance.__class__
field = child_cls._meta.get_ancestor_link(parent_cls).column
# We could specify a parent_identifier which is a unique field in
# the parent class that link child to parent
if hasattr(child_cls, 'parent_identifier'):
try:
child_instance = child_cls.objects.get(
**{child_cls.child_parent_identifier:
getattr(parent_instance, child_cls.parent_identifier)}
)
setattr(child_instance, field, parent_instance.pk)
except ObjectDoesNotExist:
child_instance = child_cls(**{
field: parent_instance.pk,
child_cls.child_parent_identifier:
getattr(parent_instance, child_cls.parent_identifier)
})
else:
child_instance = child_cls(**{
field: parent_instance.pk
})
child_instance = child_cls(**{
field: parent_instance.pk
})
child_instance.__dict__.update(parent_instance.__dict__)
child_instance.save()
return child_instance
This diff is collapsed.
......@@ -20,16 +20,20 @@
from __future__ import absolute_import
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from .digg_paginator import DiggPaginator
from django.shortcuts import render
def render_paginate_list(request, object_list, template_name, num_by_page=30):
def render_paginate_list(request, object_list, template_name):
"""
Render a paginated list of representatives
"""
paginator = Paginator(object_list, num_by_page)
page = request.GET.get('page')
pagination_limits = (10, 20, 50, 100)
num_by_page = request.GET.get('limit', 30)
paginator = DiggPaginator(object_list, num_by_page, body=5)
# paginator = Paginator(object_list, num_by_page)
page = request.GET.get('page', 1)
try:
objects = paginator.page(page)
except PageNotAnInteger:
......@@ -43,8 +47,9 @@ def render_paginate_list(request, object_list, template_name, num_by_page=30):
del queries_without_page['page']
context['queries'] = queries_without_page
context['object_list'] = objects
context['object_count'] = paginator.count
context['paginator'] = paginator
context['pagination_limits'] = pagination_limits
return render(
request,
template_name,
......
from django.shortcuts import render
# coding: utf-8
# This file is part of memopol.
#
# memopol is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or any later version.
#
# memopol is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Affero Public
# License along with django-representatives.
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from django.views.generic.base import TemplateView
class HomeView(TemplateView):
class HomeView(TemplateView):
template_name = "core/home.html"
def get_context_data(self, **kwargs):
return {
'organization_name': 'La Quadrature du Net'
}
......@@ -26,7 +26,7 @@ from django.shortcuts import render, get_object_or_404
from django.http import Http404
from ..models import MemopolRepresentative
from core.views_utils import render_paginate_list
from core.utils import render_paginate_list
def index(request, group_kind=None, group=None):
# Fetch active representatives
......
......@@ -16,6 +16,7 @@ import django
# Normally you should not import ANYTHING from Django directly
# into your settings, but ImproperlyConfigured is an exception.
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
......@@ -51,7 +52,7 @@ ALLOWED_HOSTS = []
COMPOTISTA_SERVER = get_param('compotista_server')
TOUTATIS_SERVER = get_param('toutatis_server')
REDIS_DB = get_param('redis_db')
ORGANIZATION_NAME = get_param('organization')
# Application definition
INSTALLED_APPS = (
......@@ -62,10 +63,10 @@ INSTALLED_APPS = (
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# ---
# 3rd party app
'compressor',
# 'chronograph',
'adminplus',
'constance',
# ---
'core',
'representatives',
......@@ -74,9 +75,11 @@ INSTALLED_APPS = (
'votes',
)
if DEBUG:
INSTALLED_APPS += tuple(get_param('dev_modules'))
INSTALLED_APPS += (
'debug_toolbar',
'django_extensions'
)
MIDDLEWARE_CLASSES = (
......@@ -146,6 +149,10 @@ TEMPLATE_LOADERS = (
'hamlpy.template.loaders.HamlPyAppDirectoriesLoader',
)
TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS + (
'constance.context_processors.config',
)
"""
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
......@@ -218,3 +225,16 @@ LOGGING = {
}
},
}
CONSTANCE_BACKEND = 'constance.backends.redisd.RedisBackend'
CONSTANCE_REDIS_CONNECTION = {
'host': 'localhost',
'port': 6379,
'db': 0,
}
CONSTANCE_CONFIG = {
'USE_COUNTRY': (True, 'Use country for representative'),
'MAIN_GROUP_KIND': ('group', 'Main group kind'),
'ORGANIZATION_NAME': ('La Quadrature du Net', 'Organization name')
}
......@@ -28,7 +28,7 @@ from representatives_votes.models import Vote, Proposal, Dossier
from legislature.models import MemopolRepresentative
from core.utils import create_child_instance_from_parent
class Recommendation(models.Model):
SCORE_TABLE = {
('abstain', 'abstain'): 1,
......
......@@ -22,9 +22,10 @@ from __future__ import absolute_import
from django.shortcuts import render, get_object_or_404
from core.views_utils import render_paginate_list
from core.utils import render_paginate_list
from .models import MemopolDossier
def dossier_index(request):
dossier_list = MemopolDossier.objects.all()
......@@ -34,9 +35,10 @@ def dossier_index(request):
'votes/dossier_index.html'
)
def dossier_detail(request, pk):
dossier = get_object_or_404(MemopolDossier, pk=pk)
return render(
request,
'votes/dossier_detail.html',
......
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