Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
memopol
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
32
Issues
32
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Political Memory
memopol
Commits
0838d262
Commit
0838d262
authored
Jul 20, 2015
by
Arnaud Fabre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a command from votes to legislature
parent
1bf92403
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
26 deletions
+70
-26
legislature/admin.py
legislature/admin.py
+24
-1
legislature/admin_views.py
legislature/admin_views.py
+29
-0
legislature/tasks.py
legislature/tasks.py
+4
-5
votes/admin.py
votes/admin.py
+5
-7
votes/admin_views.py
votes/admin_views.py
+8
-13
No files found.
legislature/admin.py
View file @
0838d262
# 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
__future__
import
absolute_import
from
django.contrib
import
admin
from
representatives.models
import
Email
,
WebSite
,
Address
,
Phone
,
Country
from
.admin_views
import
representatives_update_all
from
.models
import
MemopolRepresentative
admin
.
site
.
register_view
(
'representatives_update_all'
,
view
=
representatives_update_all
)
class
EmailInline
(
admin
.
TabularInline
):
model
=
Email
extra
=
0
...
...
@@ -43,7 +67,6 @@ class MemopolRepresentativeAdmin(admin.ModelAdmin):
]
# class MandateAdmin(admin.ModelAdmin):
# list_display = ('representative', 'group', 'role', 'constituency', 'begin_date', 'end_date', 'active')
# search_fields = ('representative', 'group', 'constituency')
...
...
legislature/admin_views.py
0 → 100644
View file @
0838d262
# coding: utf-8
# This file is part of mempol.
#
# mempol 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.
#
# mempol 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
__future__
import
absolute_import
from
django.shortcuts
import
redirect
from
.tasks
import
representatives_update_all
as
rpr_update_task
def
representatives_update_all
(
request
):
rpr_update_task
.
delay
()
return
redirect
(
'/admin'
)
votes
/tasks.py
→
legislature
/tasks.py
View file @
0838d262
...
...
@@ -17,17 +17,16 @@
# If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2015 Arnaud Fabre <af@laquadrature.net>
from
__future__
import
absolute_import
from
celery
import
shared_task
from
legislature
.models
import
MemopolRepresentative
from
.models
import
MemopolRepresentative
@
shared_task
def
update_representatives_score
():
def
representatives_update_all
():
'''
Update score for all representative
s
Call MemopolRepresentative.update_all method
s
'''
for
representative
in
MemopolRepresentative
.
objects
.
all
():
representative
.
update_
score
()
representative
.
update_
all
()
votes/admin.py
View file @
0838d262
...
...
@@ -22,13 +22,11 @@ from __future__ import absolute_import
from
django.contrib
import
admin
from
django.core.urlresolvers
import
reverse
from
.admin_views
import
import_vote_with_recommendation
,
import_vote
,
update_representatives_score
from
.admin_views
import
import_vote_with_recommendation
,
import_vote
from
.models
import
Recommendation
,
MemopolDossier
admin
.
site
.
register_view
(
'import_vote'
,
view
=
import_vote
)
admin
.
site
.
register_view
(
'import_vote_with_recommendation'
,
view
=
import_vote_with_recommendation
)
admin
.
site
.
register_view
(
'update_representatives_score'
,
view
=
update_representatives_score
)
def
link_to_edit
(
obj
,
field
):
try
:
...
...
@@ -42,15 +40,15 @@ def link_to_edit(obj, field):
)
return
' <strong><a href="{url}">{obj}</a></strong>'
.
format
(
url
=
url
,
obj
=
related_obj
)
except
:
return
'???'
class
MemopolDossierAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
'name'
,
'dossier_ptr'
)
search_fields
=
(
'name'
,)
fields
=
(
'dossier_ptr'
,
'name'
)
readonly_fields
=
(
'dossier_ptr'
,)
...
...
votes/admin_views.py
View file @
0838d262
...
...
@@ -27,25 +27,20 @@ import requests
from
representatives_votes.tasks
import
import_a_proposal_from_toutatis
from
.forms
import
RecommendationForm
from
.tasks
import
update_representatives_score
as
task_urs
class
SearchForm
(
forms
.
Form
):
query
=
forms
.
CharField
(
label
=
'Search'
,
max_length
=
100
)
def
update_representatives_score
(
request
):
task_urs
.
delay
()
return
redirect
(
'/admin'
)
def
import_vote_with_recommendation
(
request
):
context
=
{}
toutatis_server
=
getattr
(
settings
,
'TOUTATIS_SERVER'
,
'http://toutatis.mm.staz.be'
)
if
request
.
method
==
'POST'
and
'search'
in
request
.
POST
:
form
=
SearchForm
(
request
.
POST
)
form
=
SearchForm
(
request
.
POST
)
if
form
.
is_valid
():
query
=
form
.
cleaned_data
[
'query'
]
context
[
'api_url'
]
=
'{}/api/proposals/?search={}&limit=30'
.
format
(
...
...
@@ -59,7 +54,7 @@ def import_vote_with_recommendation(request):
if
form
.
is_valid
():
# First import proposal
proposal_fingerprint
=
request
.
POST
[
'proposal_fingerprint'
]
proposal
=
import_a_proposal_from_toutatis
(
proposal_fingerprint
)
recommendation
=
form
.
save
(
commit
=
False
)
recommendation
.
proposal
=
proposal
...
...
@@ -79,7 +74,7 @@ def import_vote_with_recommendation(request):
context
[
'recommendation_proposal_fingerprint'
]
=
proposal
[
'fingerprint'
]
context
[
'recommendation_form'
]
=
RecommendationForm
()
form
=
SearchForm
()
context
[
'form'
]
=
form
return
render
(
request
,
'votes/admin/import.html'
,
context
)
...
...
@@ -89,10 +84,10 @@ def import_vote(request):
toutatis_server
=
getattr
(
settings
,
'TOUTATIS_SERVER'
,
'http://toutatis.mm.staz.be'
)
if
request
.
method
==
'POST'
and
'search'
in
request
.
POST
:
print
(
request
.
POST
)
form
=
SearchForm
(
request
.
POST
)
form
=
SearchForm
(
request
.
POST
)
if
form
.
is_valid
():
query
=
form
.
cleaned_data
[
'query'
]
context
[
'api_url'
]
=
'{}/api/proposals/?search={}&limit=1000'
.
format
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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