Commit 65807294 authored by Nicolas Joyard's avatar Nicolas Joyard

Add score refresh to management commands + admin actions

parent be45d3d8
......@@ -6,3 +6,5 @@ cmd=$1
cd $OPENSHIFT_REPO_DIR
export CLEAN=1
nohup bin/update_all > $OPENSHIFT_LOG_DIR/update_all.log 2>&1 &
./manage.py refresh_scores
from django.core.management.base import BaseCommand
from ...models import RepresentativeScore
class Command(BaseCommand):
help = 'Recomputes all scores'
def handle(self, *args, **options):
self.stdout.write('Refreshing scores... ', ending='')
self.stdout.flush()
RepresentativeScore.refresh()
self.stdout.write('done')
from django.contrib import admin
from django.db import connection, models
from django.http import HttpResponseRedirect
from representatives.models import Representative
from representatives_votes.models import Dossier, Vote
......@@ -46,3 +48,12 @@ class RepresentativeScore(models.Model):
def refresh(cls):
with connection.cursor() as cursor:
cursor.execute('SELECT refresh_representative_scores();')
def refresh_scores(modeladmin, request, queryset):
RepresentativeScore.refresh()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
refresh_scores.short_description = 'Refresh representative scores'
admin.site.add_action(refresh_scores, 'refresh_scores')
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