Commit 0731c495 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Add working position form

parent f6d6bd9a
from django.views import generic
from django.db import models
from django.core.urlresolvers import reverse
from memopol.views.representative_mixin import RepresentativeViewMixin
from representatives.models import Mandate
from .models import Position
from .forms import PositionForm
class PositionCreate(generic.CreateView):
model = Position
form_class = PositionForm
class PositionFormMixin(generic.View):
"""
Mixin for class views that handle a position form (should be all full-page
views, ie. all template views that use a templates that extends base.html).
We don't use a FormView here to allow usage of this mixin in views that
have their own form.
"""
position_form = None
position_created = False
def get_success_url(self):
return reverse('representative-detail',
args=(self.object.representative.slug,))
def post(self, request, *args, **kwargs):
if 'position-representative' in request.POST:
self.position_form = PositionForm(request.POST, prefix='position')
if self.position_form.is_valid():
self.position_form.save()
self.position_form = None
self.position_created = True
return self.get(request, args, kwargs)
class PositionDetail(RepresentativeViewMixin, generic.DetailView):
queryset = Position.objects.filter(published=True).select_related(
'representative__score')
def get_context_data(self, **kwargs):
c = super(PositionFormMixin, self).get_context_data(**kwargs)
def get_queryset(self):
qs = super(PositionDetail, self).get_queryset()
qs = qs.prefetch_related(models.Prefetch(
'representative__mandates',
Mandate.objects.select_related('constituency__country', 'group')
))
return qs
c['position_form'] = \
self.position_form or PositionForm(prefix='position')
c['position_created'] = self.position_created
def get_object(self):
obj = super(PositionDetail, self).get_object()
self.add_representative_country_and_main_mandate(obj.representative)
return obj
return c
......@@ -253,18 +253,6 @@ a:hover .custom-thumbnail-details {
}
/***************************************************************
List / Résultat de la recherche
***************************************************************/
thead th {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAMAAACelLz8AAAAJ1BMVEVmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmaP/QSjAAAADHRSTlMAAgMJC0uWpKa6wMxMdjkoAAAANUlEQVR4AeXJyQEAERAAsNl7Hf3X6xt0QL6JpZWq30pdvdadme+0PMdzvHm8YThHcT1H7K0BtOMDniZhWOgAAAAASUVORK5CYII=);
-webkit-background-size: 13px 13px;
background-size: 13px;
background-repeat: no-repeat;
background-position: right center;
}
/***************************************************************
MEPs
***************************************************************/
......
......@@ -3,25 +3,27 @@
{% load staticfiles %}
<div id="intro">
<h1 class="text-center">
<img id="logo" src="{% static 'images/logo.png' %}">
<br>
{% trans "Political memory" %}
</h1>
<p class="lead text-center hidden-xs">{% trans "What is Memopol ?" %}</p>
<p class="text-justify hidden-xs">{% trans "Political Memory is a tool designed by La Quadrature du Net to help citizens reach their representative and track their voting records on issues related to fundamental freedoms online." %}</p>
<div class="container-fluid hidden-xs">
<div class="row">
<div class="col-sm-6">
<a class="btn btn-primary hidden-print" data-toggle="modal" data-target="#addposition" aria-expanded="false" aria-controls="addposition">
{% bootstrap_icon "bullhorn" %}
Add a public position
</a>
<h1 class="text-center">
<img id="logo" src="{% static 'images/logo.png' %}">
<br>
{% trans "Political memory" %}
</h1>
<p class="lead text-center hidden-xs">{% trans "What is Memopol ?" %}</p>
<p class="text-justify hidden-xs">{% trans "Political Memory is a tool designed by La Quadrature du Net to help citizens reach their representative and track their voting records on issues related to fundamental freedoms online." %}</p>
<div class="container-fluid hidden-xs">
<div class="row">
<div class="col-sm-6">
{% if position_form %}
<a class="btn btn-primary hidden-print" data-toggle="modal" data-target="#add-position-form" aria-expanded="false" aria-controls="add-position-form">
{% bootstrap_icon "bullhorn" %}
Add a public position
</a>
{% endif %}
</div>
<div class="col-sm-6 text-right">
<a class="btn btn-default">{% trans "More on our blog" %}</a>
</div>
</div>
</div>
<div class="col-sm-6 text-right">
<a class="btn btn-default">{% trans "More on our blog" %}</a>
</div>
</div>
</div>
</div>
\ No newline at end of file
<div class="modal fade" id="addposition" tabindex="-1" role="dialog" aria-labelledby="btn-position">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Add a MEP's public position</h4>
{% load i18n %}
{% load bootstrap3 %}
<div class="modal fade" id="add-position-form" tabindex="-1" role="dialog" aria-labelledby="btn-position">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form method="post" action="">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{% trans 'Close' %}"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{% trans "Add a representative public position" %}</h4>
</div>
<div class="modal-body">
{% csrf_token %}
<div class="row">
<div class="col-sm-12">
<div class="well well-sm text-justify">{% include "text/position_info.html" %}</div>
</div>
<div class="modal-body">
<p class="text-justify">Cronut pop-up gluten-free, cliche Carles chillwave salvia roof party Blue Bottle. Craft beer post-ironic photo booth whatever literally DIY lomo, shabby chic fashion axe. Cardigan meh master cleanse, McSweeney's hashtag Etsy Pinterest forage viral XOXO freegan narwhal. Pour-over Brooklyn asymmetrical flannel pork belly four loko. Crucifix tote bag you probably haven't heard of them, organic synth stumptown occupy. Seitan plaid Williamsburg selvage single-origin coffee, tattooed PBR occupy art party whatever Banksy. Tumblr kale chips food truck tofu kitsch, chambray Etsy pork belly.</p>
<form class="form-horizontal">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-2 control-label" for="MEPname">MEP</label>
<div class="col-sm-10">
<select class="form-control" id="MEPname">
<option></option>
<option>Jan Philipp ALBRECHT</option>
<option>Martina ANDERSON</option>
<option>Sergio Gaetano COFFERATI</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="date">Date</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="date" placeholder="Today">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="points">Points</label>
<div class="col-sm-10">
<input type="number" class="form-control" id="points" placeholder="0">
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-2 control-label" for="theme">Theme</label>
<div class="col-sm-10">
<select class="form-control" id="theme">
<option>Any</option>
<option>Personal data protection: processing of data for the purposes of prevention, investigation, detection or prosecution of criminal offences or execution of criminal penalties, and free movement of data </option>
<option>ACTA </option>
<option>Personal data protection: processing and free movement of data </option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="dossier">Dossier</label>
<div class="col-sm-10">
<select class="form-control" id="dossier">
<option>Any</option>
<option>Personal data protection: processing of data for the purposes of prevention, investigation, detection or prosecution of criminal offences or execution of criminal penalties, and free movement of data </option>
<option>ACTA </option>
<option>Personal data protection: processing and free movement of data </option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="tags">Tags</label>
<div class="col-sm-10">
<input type="url" class="form-control" id="source" placeholder="ACTA, Net neutrality, ...">
</div>
</div>
</div>
<div class="col-sm-12">
<hr/>
<div class="form-group">
<label class="col-sm-1 control-label" for="text">Transcript</label>
<div class="col-sm-11">
<textarea class="form-control" id="text" rows="5"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label" for="source">Source link</label>
<div class="col-sm-11">
<input type="url" class="form-control" id="source" placeholder="https://">
</div>
</div>
</div>
</form>
</div>
<div class="row">
<div class="col-sm-6">
{% bootstrap_field position_form.representative layout='horizontal' %}
{% bootstrap_field position_form.datetime layout='horizontal' %}
{% bootstrap_field position_form.link layout='horizontal' %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Add this public position</button>
<div class="col-sm-6">
{% bootstrap_field position_form.themes layout='horizontal' %}
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
{% bootstrap_field position_form.text %}
</div>
</div>
</div>
</div>
<div class="modal-footer">
{% bootstrap_form_errors position_form %}
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
<button type="submit" class="btn btn-primary">{% trans "Submit public position" %}</button>
</div>
</form>
</div>
</div>
</div>
{% if position_form.errors %}
<script>
$(function() {
$("#add-position-form").modal("show");
});
</script>
{% endif %}
{% if position_created %}
<div class="modal fade" id="add-position-success" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{% trans 'Close' %}"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">{% trans "Add a representative public position" %}</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<div class="row">
<div class="col-sm-12">
<div role="alert" class="alert alert-success text-justify">{% trans "Thanks! The position was submitted and will be reviewed shortly." %}</div>
</div>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>
<script>
$(function() {
$("#add-position-success").modal("show");
});
</script>
{% endif %}
\ No newline at end of file
......@@ -26,6 +26,9 @@
<script type="text/javascript" src="{% static 'libs/jquery/dist/jquery.js' %}"></script>
<script type="text/javascript" src="{% static 'js/bootstrap.js' %}"></script>
{% endcompress %}
{{ position_form.media }}
{% block head %}{% endblock %}
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
......@@ -36,15 +39,16 @@
</head>
<body>
{% get_current_language as LANGUAGE_CODE %}
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 custom-nav">
{% block sidebar %}
{% include '_base_intro.html' %}
<hr class="hidden-xs"/>
{% get_current_language as LANGUAGE_CODE %}
{% cache 3600 LANGUAGE_CODE %} {# 1 hour #}
{% include '_base_search.html' %}
{% include '_base_search.html' %}
{% endcache %}
<hr class="hidden-xs"/>
<a href="{% url "representative-list" %}" class="btn btn-primary btn-block">
......@@ -57,11 +61,13 @@
{% endblock %}
</div>
{% include '_position_form_modal.html' %}
{% cache 3600 LANGUAGE_CODE %}
{% include '_position_form_modal.html' %}
{% endcache %}
<div class="col-sm-9 col-sm-offset-3 {% block container-class %}{% endblock %}">
{% block content %}
<div class="text-danger">This template is empty !</div>
<div class="text-danger">{% trans "This template is empty !" %}</div>
{% endblock %}
</div>
</div>
......
{% load i18n %}
<p>
{% blocktrans %}
Use this form to submit a public position taken by a representative and
related to one of the themes followed on this instance of Political Memory.
Public positions may include blog or social network posts, interviews,
parliament interventions...
{% endblocktrans %}
</p>
<p>
{% blocktrans %}
Be sure to include a relevant excerpt from the public position as well as
a valid link that refers to it. Note that positions will be reviewed by
the staff before publication.
{% endblocktrans %}
</p>
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