Personal wiki notebook (not under development)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

set_plan.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python2.4
  2. import os
  3. import os.path
  4. import sys
  5. from controller.Database import Database
  6. from controller.Users import Users
  7. from model.Notebook import Notebook
  8. from model.User import User
  9. class Plan_setter( object ):
  10. """
  11. Set the rate plan for a particular user.
  12. """
  13. def __init__( self, database, settings, user_id, rate_plan ):
  14. self.database = database
  15. self.user_id = user_id
  16. self.rate_plan = int( rate_plan )
  17. rate_plans = settings[ u"global" ][ u"luminotes.rate_plans" ]
  18. self.users = Users( database, None, None, None, None, rate_plans, [] )
  19. self.set_plan()
  20. self.database.commit()
  21. def set_plan( self ):
  22. user = self.database.load( User, self.user_id )
  23. if not user:
  24. print "user id %s unknown" % self.user_id
  25. sys.exit( 1 )
  26. user.rate_plan = self.rate_plan
  27. self.database.save( user, commit = False )
  28. # update a user's group membership as a result of a rate plan change
  29. self.users.update_groups( user )
  30. def main( args ):
  31. import cherrypy
  32. from config import Common
  33. cherrypy.config.update( Common.settings )
  34. desktop = False
  35. if args and "-d" in args:
  36. from config import Development
  37. settings = Development.settings
  38. args.remove( "-d" )
  39. elif args and "-l" in args:
  40. from config import Desktop
  41. settings = Desktop.settings
  42. desktop = True
  43. args.remove( "-l" )
  44. else:
  45. from config import Production
  46. settings = Production.settings
  47. cherrypy.config.update( settings )
  48. database = Database(
  49. host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
  50. ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
  51. data_dir = ".",
  52. )
  53. ranker = Plan_setter( database, cherrypy.config.configMap, *args )
  54. if __name__ == "__main__":
  55. main( sys.argv[ 1: ] )