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
Anthony
memopol
Commits
65807294
Commit
65807294
authored
Sep 07, 2016
by
Nicolas Joyard
Browse files
Add score refresh to management commands + admin actions
parent
be45d3d8
Changes
5
Hide whitespace changes
Inline
Side-by-side
.openshift/cron/daily/update_database
View file @
65807294
...
...
@@ -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
memopol_scores/management/__init__.py
0 → 100644
View file @
65807294
memopol_scores/management/commands/__init__.py
0 → 100644
View file @
65807294
memopol_scores/management/commands/refresh_scores.py
0 → 100644
View file @
65807294
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'
)
memopol_scores/models.py
View file @
65807294
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'
)
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