witten
/
luminotes
Archived
1
0
Fork 0

Implemented transition script to set the ranks for all users' notebooks.

This commit is contained in:
Dan Helfman 2008-03-17 21:51:26 +00:00
parent f3b0d563c1
commit 0967965847
3 changed files with 39 additions and 2 deletions

2
NEWS
View File

@ -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.
* Fixed database transaction leak that was wasting memory.

View File

@ -168,7 +168,7 @@ class User( Persistent ):
return \
"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 )
def sql_remove_notebook( self, notebook_id ):

37
tools/set_ranks.py Executable file
View File

@ -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: ] )