Commit 0838d262 authored by Arnaud Fabre's avatar Arnaud Fabre

Adds a command from votes to legislature

parent 1bf92403
# 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')
......
# 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')
......@@ -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 representatives
Call MemopolRepresentative.update_all methods
'''
for representative in MemopolRepresentative.objects.all():
representative.update_score()
representative.update_all()
......@@ -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 '&nbsp;<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',)
......
......@@ -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(
......
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