Personal wiki notebook (not under development)

set_ranks.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/python2.4
  2. import os
  3. import os.path
  4. from controller.Database import Database
  5. from model.Notebook import Notebook
  6. from model.User import User
  7. class Ranker( object ):
  8. def __init__( self, database ):
  9. self.database = database
  10. self.rank_notebooks()
  11. self.database.commit()
  12. def rank_notebooks( self ):
  13. users = self.database.select_many( User, u"select * from luminotes_user_current where username is not null and username != 'anonymous';" )
  14. # rank the notebooks for each user
  15. for user in users:
  16. rank = 0
  17. notebooks = self.database.select_many( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
  18. for notebook in notebooks:
  19. self.database.execute( user.sql_update_notebook_rank( notebook.object_id, rank ), commit = False )
  20. rank += 1
  21. users = self.database.select_many( User, u"select * from luminotes_user_current where username is not null and username = 'anonymous';" )
  22. user = users[ 0 ]
  23. # rank the notebooks for the anonymous user
  24. rank = 0
  25. notebooks = self.database.select_many( Notebook, user.sql_load_notebooks( undeleted_only = True ) )
  26. for notebook in notebooks:
  27. self.database.execute( user.sql_update_notebook_rank( notebook.object_id, rank ), commit = False )
  28. rank += 1
  29. def main( args ):
  30. database = Database()
  31. ranker = Ranker( database )
  32. if __name__ == "__main__":
  33. import sys
  34. main( sys.argv[ 1: ] )