Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81066098
invenio_2014_08_31_next_collection_tree.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Sep 4, 01:23
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Sep 6, 01:23 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20508337
Attached To
R3600 invenio-infoscience
invenio_2014_08_31_next_collection_tree.py
View Options
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2012, 2014 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio 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
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
from
__future__
import
print_function
from
invenio.dbquery
import
run_sql
depends_on
=
[
'invenio_release_1_1_0'
]
def
info
():
return
"Update collection tree definition to match next structure"
def
do_upgrade
():
"""Change the score to the opposite order."""
def
change_collections_score
(
id_dad
,
collection_list
):
for
i
,
col
in
enumerate
(
collection_list
):
run_sql
(
"UPDATE collection_collection "
"SET score=
%s
"
"WHERE id_son=
%s
AND id_dad=
%s
"
,
(
i
,
col
[
0
],
id_dad
))
son_collections
=
run_sql
(
"SELECT cc.id_son "
"FROM collection_collection as cc, collection as c "
"WHERE cc.id_dad=
%s
and cc.id_son=c.id "
"ORDER BY cc.score DESC, c.name ASC"
,
(
col
[
0
],
))
change_collections_score
(
col
[
0
],
son_collections
)
main_collections
=
run_sql
(
"SELECT cc.id_son "
"FROM collection_collection as cc, collection as c "
"WHERE cc.id_dad=1 and cc.id_son=c.id "
"ORDER BY cc.score DESC, c.name ASC"
)
change_collections_score
(
1
,
main_collections
)
def
estimate
():
return
1
def
post_upgrade
():
print
(
'Running webcoll is highly recommended to update the collection tree.'
)
Event Timeline
Log In to Comment