Implemented transition script to set the ranks for all users' notebooks.
This commit is contained in:
parent
f3b0d563c1
commit
0967965847
2
NEWS
2
NEWS
|
@ -1,4 +1,4 @@
|
||||||
1.2.14: March ??, 2008
|
1.2.14: March 17, 2008
|
||||||
* Added ability to reorder notebooks on the right side of the page.
|
* Added ability to reorder notebooks on the right side of the page.
|
||||||
* Fixed database transaction leak that was wasting memory.
|
* Fixed database transaction leak that was wasting memory.
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ class User( Persistent ):
|
||||||
|
|
||||||
return \
|
return \
|
||||||
"insert into user_notebook ( user_id, notebook_id, read_write, owner, rank ) values " + \
|
"insert into user_notebook ( user_id, notebook_id, read_write, owner, rank ) values " + \
|
||||||
"( %s, %s, %s, %s );" % ( quote( self.object_id ), quote( notebook_id ), quote( read_write and 't' or 'f' ),
|
"( %s, %s, %s, %s, %s );" % ( quote( self.object_id ), quote( notebook_id ), quote( read_write and 't' or 'f' ),
|
||||||
quote( owner and 't' or 'f' ), rank )
|
quote( owner and 't' or 'f' ), rank )
|
||||||
|
|
||||||
def sql_remove_notebook( self, notebook_id ):
|
def sql_remove_notebook( self, notebook_id ):
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/python2.4
|
||||||
|
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
from controller.Database import Database
|
||||||
|
from model.Notebook import Notebook
|
||||||
|
from model.User import User
|
||||||
|
|
||||||
|
|
||||||
|
class Ranker( object ):
|
||||||
|
def __init__( self, database ):
|
||||||
|
self.database = database
|
||||||
|
|
||||||
|
self.rank_notebooks()
|
||||||
|
self.database.commit()
|
||||||
|
|
||||||
|
def rank_notebooks( self ):
|
||||||
|
users = self.database.select_many( User, u"select * from luminotes_user_current where username is not null and username != 'anonymous';" )
|
||||||
|
|
||||||
|
# rank the notebooks for each user
|
||||||
|
for user in users:
|
||||||
|
rank = 0
|
||||||
|
notebooks = self.database.select_many( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
|
||||||
|
|
||||||
|
for notebook in notebooks:
|
||||||
|
self.database.execute( user.sql_update_notebook_rank( notebook.object_id, rank ), commit = False )
|
||||||
|
rank += 1
|
||||||
|
|
||||||
|
|
||||||
|
def main( args ):
|
||||||
|
database = Database()
|
||||||
|
ranker = Ranker( database )
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
main( sys.argv[ 1: ] )
|
Reference in New Issue