Commit 65807294 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Add score refresh to management commands + admin actions

parent be45d3d8
......@@ -6,3 +6,5 @@ cmd=$1
export CLEAN=1
nohup bin/update_all > $OPENSHIFT_LOG_DIR/update_all.log 2>&1 &
./ refresh_scores
from import BaseCommand
from ...models import RepresentativeScore
class Command(BaseCommand):
help = 'Recomputes all scores'
def handle(self, *args, **options):
self.stdout.write('Refreshing scores... ', ending='')
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):
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
refresh_scores.short_description = 'Refresh representative scores', 'refresh_scores')
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