Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Political Memory
memopol
Commits
a9d88685
Commit
a9d88685
authored
Sep 05, 2016
by
Nicolas Joyard
Browse files
Add title, kind, score to positions
parent
c0930e34
Changes
14
Hide whitespace changes
Inline
Side-by-side
memopol/tests/response_fixtures/PositionFormTest.test_position_form.content
View file @
a9d88685
...
...
@@ -112,9 +112,17 @@ format: 'yyyy-mm-dd'}).find('input').addClass("form-control");
</script>
</div></div>
<div class="form-group"><label class="col-md-3 control-label" for="id_position-link">Link</label><div class="col-md-9"><input class="form-control" id="id_position-link" maxlength="500" name="position-link" placeholder="Link" required="required" title="" type="url"/></div></div>
<div class="form-group"><label class="col-md-3 control-label" for="id_position-title">Title</label><div class="col-md-9"><input class="form-control" id="id_position-title" maxlength="500" name="position-title" placeholder="Title" required="required" title="" type="text"/></div></div>
</div>
<div class="col-sm-6">
<div class="form-group"><label class="col-md-3 control-label" for="id_position-kind">Kind</label><div class="col-md-9"><select class="form-control" id="id_position-kind" name="position-kind" required="required" title="">
<option selected="selected" value="other">Other</option>
<option value="blog">Blog post</option>
<option value="social">Social network</option>
<option value="press">Press interview</option>
<option value="parliament">Parliament debate</option>
</select></div></div>
<div class="form-group"><label class="col-md-3 control-label" for="id_position-themes_0">Themes</label><div class="col-md-9"><div id="id_position-themes"><div class="checkbox"><label for="id_position-themes_0"><input class="" id="id_position-themes_0" name="position-themes" title="" type="checkbox" value="1"/> Etat d'urgence</label></div>
<div class="checkbox"><label for="id_position-themes_1"><input class="" id="id_position-themes_1" name="position-themes" title="" type="checkbox" value="2"/> ACTA</label></div></div></div></div>
</div>
...
...
@@ -122,6 +130,7 @@ format: 'yyyy-mm-dd'}).find('input').addClass("form-control");
<div class="row">
<div class="col-sm-12">
<div class="col-sm-12">
<div class="form-group"><label class="control-label" for="id_position-text">Text</label><textarea class="form-control" cols="40" id="id_position-text" name="position-text" placeholder="Text" required="required" rows="10" title=""></textarea></div>
</div>
...
...
memopol/tests/response_fixtures/RepresentativePositionsTest.test_position_buttons.content
View file @
a9d88685
...
...
@@ -3,6 +3,8 @@
<div class="text-center">Oct. 3, 2009</div>
<span class="badge badge-primary">0</span>
</button>
---
<button aria-controls="position-modal-567" aria-expanded="false" class="btn btn-default position-button" data-target="#position-modal-567" data-toggle="modal" id="position-button-567" type="button">
...
...
@@ -10,4 +12,6 @@
<div class="text-center">June 17, 2008</div>
<span class="badge badge-primary">0</span>
</button>
\ No newline at end of file
memopol/tests/response_fixtures/RepresentativePositionsTest.test_position_details.content
View file @
a9d88685
...
...
@@ -2,6 +2,7 @@
<div class="modal-content">
<div class="modal-header">
<button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">
...
...
@@ -12,6 +13,30 @@
</div>
<div class="modal-body">
<div class="row">
<dl class="dl-horizontal col-sm-6 text-left">
<dt>Date</dt>
<dd>
Oct. 3, 2009
</dd>
<dt>Kind</dt>
<dd>
other
</dd>
</dl>
<dl class="dl-horizontal col-sm-6 text-left">
<dt>Themes</dt>
<dd>
</dd>
<dt>Score</dt>
<dd>
<span class="badge badge-primary">0</span>
</dd>
</dl>
</div>
<div class="row">
<div class="col-sm-12 text-justify">
<blockquote>
...
...
@@ -42,6 +67,7 @@ Olivier Dussopt n'a pas fait de réponse aux commentaires sur son blog.</p>
<div class="modal-content">
<div class="modal-header">
<button aria-label="Close" class="close" data-dismiss="modal" type="button"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">
...
...
@@ -52,6 +78,30 @@ Olivier Dussopt n'a pas fait de réponse aux commentaires sur son blog.</p>
</div>
<div class="modal-body">
<div class="row">
<dl class="dl-horizontal col-sm-6 text-left">
<dt>Date</dt>
<dd>
June 17, 2008
</dd>
<dt>Kind</dt>
<dd>
other
</dd>
</dl>
<dl class="dl-horizontal col-sm-6 text-left">
<dt>Themes</dt>
<dd>
</dd>
<dt>Score</dt>
<dd>
<span class="badge badge-primary">0</span>
</dd>
</dl>
</div>
<div class="row">
<div class="col-sm-12 text-justify">
<blockquote>
...
...
memopol/tests/test_position_form.py
View file @
a9d88685
...
...
@@ -13,6 +13,9 @@ class PositionFormTest(BaseTest):
'position-representative'
:
1
,
'position-datetime'
:
'2016-09-01'
,
'position-link'
:
'http://example.com/test'
,
'position-kind'
:
'other'
,
'position-score'
:
'0'
,
'position-title'
:
'position test title'
,
'position-text'
:
'position test text'
,
'position-themes'
:
'1'
}
...
...
memopol_themes/admin.py
View file @
a9d88685
...
...
@@ -77,8 +77,8 @@ class ThemedProposalAdminForm(ThemedAdminForm):
class
ThemedPositionAdminForm
(
ThemedAdminForm
):
class
Meta
:
model
=
Position
fields
=
(
'representative'
,
'datetime'
,
'
text'
,
'link'
,
'published
'
,
'themes'
)
fields
=
(
'representative'
,
'datetime'
,
'
kind'
,
'title'
,
'score
'
,
'text'
,
'link'
,
'published'
,
'themes'
)
class
ThemedDossierAdmin
(
DossierAdmin
):
...
...
representatives_positions/admin.py
View file @
a9d88685
...
...
@@ -20,11 +20,14 @@ unpublish_positions.short_description = 'Unpublish selected positions'
class
PositionAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'representative'
,
'kind'
,
'short_title'
,
'short_text'
,
'score'
,
'datetime'
,
'link'
,
'published'
)
list_display_links
=
(
'short_text'
,
)
list_display_links
=
(
'short_title'
,
'short_text'
)
list_editable
=
(
'published'
,)
list_filter
=
(
'published'
,)
actions
=
(
publish_positions
,
unpublish_positions
)
...
...
representatives_positions/forms.py
View file @
a9d88685
...
...
@@ -15,7 +15,8 @@ class PositionForm(forms.ModelForm):
class
Meta
:
model
=
Position
fields
=
[
'representative'
,
'link'
,
'datetime'
,
'themes'
,
'text'
]
fields
=
[
'representative'
,
'link'
,
'datetime'
,
'themes'
,
'title'
,
'kind'
,
'text'
]
widgets
=
{
'datetime'
:
DateWidget
(
...
...
representatives_positions/migrations/0004_add_kind_score_title.py
0 → 100644
View file @
a9d88685
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'representatives_positions'
,
'0003_remove_position_tags'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'position'
,
name
=
'kind'
,
field
=
models
.
CharField
(
default
=
b
'other'
,
max_length
=
64
,
choices
=
[(
b
'other'
,
b
'Other'
),
(
b
'blog'
,
b
'Blog post'
),
(
b
'social'
,
b
'Social network'
),
(
b
'press'
,
b
'Press interview'
),
(
b
'parliament'
,
b
'Parliament debate'
)]),
),
migrations
.
AddField
(
model_name
=
'position'
,
name
=
'score'
,
field
=
models
.
IntegerField
(
default
=
0
),
),
migrations
.
AddField
(
model_name
=
'position'
,
name
=
'title'
,
field
=
models
.
CharField
(
max_length
=
500
,
null
=
True
),
),
]
representatives_positions/migrations/0005_set_title.py
0 → 100644
View file @
a9d88685
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
def
set_titles
(
apps
,
schema_editor
):
"""
Set position title to first line for multiline positions
"""
Position
=
apps
.
get_model
(
"representatives_positions"
,
"Position"
)
for
pos
in
Position
.
objects
.
all
():
lines
=
pos
.
text
.
split
(
'
\n
'
)
if
len
(
lines
)
>
1
:
pos
.
title
=
lines
[
0
]
pos
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'representatives_positions'
,
'0004_add_kind_score_title'
),
]
operations
=
[
migrations
.
RunPython
(
set_titles
)
]
representatives_positions/models.py
View file @
a9d88685
...
...
@@ -3,14 +3,31 @@ from django.template.defaultfilters import truncatewords
from
representatives.models
import
Representative
KIND_CHOICES
=
(
(
'other'
,
'Other'
),
(
'blog'
,
'Blog post'
),
(
'social'
,
'Social network'
),
(
'press'
,
'Press interview'
),
(
'parliament'
,
'Parliament debate'
),
)
class
Position
(
models
.
Model
):
representative
=
models
.
ForeignKey
(
Representative
,
related_name
=
'positions'
)
datetime
=
models
.
DateField
()
kind
=
models
.
CharField
(
max_length
=
64
,
choices
=
KIND_CHOICES
,
default
=
'other'
)
title
=
models
.
CharField
(
max_length
=
500
,
null
=
True
)
text
=
models
.
TextField
()
link
=
models
.
URLField
(
max_length
=
500
)
score
=
models
.
IntegerField
(
default
=
0
)
published
=
models
.
BooleanField
(
default
=
False
)
@
property
def
short_title
(
self
):
return
truncatewords
(
self
.
title
,
5
)
@
property
def
short_text
(
self
):
return
truncatewords
(
self
.
text
,
5
)
...
...
representatives_recommendations/migrations/0008_representativescore_use_positions.py
0 → 100644
View file @
a9d88685
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'representatives_recommendations'
,
'0007_fix_underflow'
),
]
operations
=
[
migrations
.
RunSQL
(
"""
CREATE OR REPLACE VIEW "representatives_recommendations_representativescore"
AS
SELECT
"representatives_representative"."id" AS "representative_id",
COALESCE(SUM("scoresource"."score"), 0) AS "score"
FROM
"representatives_representative"
LEFT OUTER JOIN (
SELECT
"representatives_recommendations_votescores"."representative_id" AS "representative_id",
"representatives_recommendations_votescores"."score" AS "score"
FROM "representatives_recommendations_votescores"
UNION ALL
SELECT
"representatives_positions_position"."representative_id" AS "representative_id",
"representatives_positions_position"."score" AS "score"
FROM "representatives_positions_position"
) "scoresource" ON "scoresource"."representative_id" = "representatives_representative"."id"
GROUP BY "representatives_representative"."id"
"""
)
]
static/css/custom.css
View file @
a9d88685
...
...
@@ -253,10 +253,16 @@ a:hover .custom-thumbnail-details {
margin-bottom
:
0
;
}
.custom-listMEP
.thumbnail
.badge
{
.position-button
{
position
:
relative
;
}
.custom-listMEP
.thumbnail
.badge
,
.position-button
.badge
{
position
:
absolute
;
top
:
-0.5em
;
right
:
0.5em
;
right
:
-0.5em
;
z-index
:
1
;
}
...
...
templates/_position_form_modal.html
View file @
a9d88685
...
...
@@ -27,15 +27,18 @@
{% bootstrap_field position_form.representative layout='horizontal' %}
{% bootstrap_field position_form.datetime layout='horizontal' %}
{% bootstrap_field position_form.link layout='horizontal' %}
{% bootstrap_field position_form.title layout='horizontal' %}
</div>
<div
class=
"col-sm-6"
>
{% bootstrap_field position_form.kind layout='horizontal' %}
{% 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>
...
...
templates/blocks/_position_list.html
View file @
a9d88685
{% load i18n %}
{% load fontawesome %}
{% load humanize %}
{% load memopol_tags %}
{% load representatives_positions_tags %}
{% comment %}
...
...
@@ -32,6 +33,7 @@
<tbody>
<tr>
{% trans "Untitled" as untitled %}
{% for timeframe in positions|regroup_by_age %}
<td>
{% for position in timeframe %}
...
...
@@ -42,6 +44,8 @@
<div
class=
"text-center"
>
{{ position.datetime|naturalday }}
</div>
{% include "blocks/_themetags.html" with themes=position.themes.all exclude=theme.pk %}
{{ position.score|score_badge }}
</button>
<div
class=
"modal fade"
id=
"position-modal-{{ position.pk }}"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"position-button-{{ position.pk }}"
>
...
...
@@ -49,7 +53,12 @@
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"{% trans 'Close' %}"
><span
aria-hidden=
"true"
>
×
</span></button>
<h4
class=
"modal-title"
>
{% if position.title %}
<h4>
<div
class=
"col-sm-12"
>
{{ position.title|default:untitled }}
</div>
</h4>
{% endif %}
<
{%
if
position.title
%}
h5
{%
else
%}
h4
{%
endif
%}
class=
"modal-title"
>
{% if show_representative %}
{% trans "Public position" %}
{% else %}
...
...
@@ -57,10 +66,34 @@
Public position by {{ rep }}
{% endblocktrans %}
{% endif %}
</
h4
>
</
{%
if
position.title
%}h5{%
else
%}h4{%
endif
%}
>
</div>
<div
class=
"modal-body"
>
<div
class=
"row"
>
<dl
class=
"dl-horizontal col-sm-6 text-left"
>
<dt>
{% trans "Date" %}
</dt>
<dd>
{{ position.datetime|naturalday }}
</dd>
<dt>
{% trans "Kind" %}
</dt>
<dd>
{{ position.kind }}
</dd>
</dl>
<dl
class=
"dl-horizontal col-sm-6 text-left"
>
<dt>
{% trans "Themes" %}
</dt>
<dd>
{% include "blocks/_themetags.html" with themes=position.themes.all %}
</dd>
<dt>
{% trans "Score" %}
</dt>
<dd>
{{ position.score|score_badge }}
</dd>
</dl>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-12 text-justify"
>
<blockquote>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment