witten
/
luminotes
Archived
1
0
Fork 0

Added a tool to create a download access record and make a download link from it.

This commit is contained in:
Dan Helfman 2008-09-11 21:02:12 -07:00
parent c2f4e433e0
commit cfb6a04817
3 changed files with 95 additions and 15 deletions

View File

@ -130,7 +130,7 @@ def main( args = None ):
return
print "Initializing the database with default data."
host = settings[ u"global" ].get( u"luminotes.db_host" )
host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" )
database = Database(
host = host,
ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),

64
tools/make_download_link.py Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/python2.4
import os
import os.path
import sys
import cherrypy
from controller.Database import Database
from model.Download_access import Download_access
class Link_maker( object ):
"""
Create a product download access record and print the download link for it.
"""
def __init__( self, database, settings, item_number, transaction_id = None ):
self.database = database
self.settings = settings
self.item_number = item_number
self.transaction_id = transaction_id
self.grant_access()
self.database.commit()
def grant_access( self ):
access_id = self.database.next_id( Download_access, commit = False )
download_access = Download_access.create( access_id, self.item_number, self.transaction_id )
self.database.save( download_access, commit = False )
https_url = self.settings[ u"global" ][ u"luminotes.https_url" ]
print u"%s/d/%s" % ( https_url, access_id )
def main( args ):
import cherrypy
from config import Common
cherrypy.config.update( Common.settings )
desktop = False
if args and "-d" in args:
from config import Development
settings = Development.settings
args.remove( "-d" )
elif args and "-l" in args:
from config import Desktop
settings = Desktop.settings
desktop = True
args.remove( "-l" )
else:
from config import Production
settings = Production.settings
cherrypy.config.update( settings )
database = Database(
host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
data_dir = ".",
)
ranker = Link_maker( database, cherrypy.config.configMap, *args )
if __name__ == "__main__":
main( sys.argv[ 1: ] )

View File

@ -3,25 +3,23 @@
import os
import os.path
import sys
import cherrypy
from controller.Database import Database
from controller.Users import Users
from model.Notebook import Notebook
from model.User import User
from config import Common
class Plan_setter( object ):
"""
Set the rate plan for a particular user.
"""
def __init__( self, database, user_id, rate_plan ):
def __init__( self, database, settings, user_id, rate_plan ):
self.database = database
self.user_id = user_id
self.rate_plan = int( rate_plan )
rate_plans = Common.settings[ u"global" ][ u"luminotes.rate_plans" ]
self.users = Users( database, None, None, None, None, rate_plans )
rate_plans = settings[ u"global" ][ u"luminotes.rate_plans" ]
self.users = Users( database, None, None, None, None, rate_plans, [] )
self.set_plan()
self.database.commit()
@ -40,15 +38,33 @@ class Plan_setter( object ):
self.users.update_groups( user )
def main( args ):
database = Database()
ranker = Plan_setter( database, *args )
import cherrypy
from config import Common
cherrypy.config.update( Common.settings )
desktop = False
if args and "-d" in args:
from config import Development
settings = Development.settings
args.remove( "-d" )
elif args and "-l" in args:
from config import Desktop
settings = Desktop.settings
desktop = True
args.remove( "-l" )
else:
from config import Production
settings = Production.settings
cherrypy.config.update( settings )
database = Database(
host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
data_dir = ".",
)
ranker = Plan_setter( database, cherrypy.config.configMap, *args )
if __name__ == "__main__":
args = sys.argv[ 1: ]
if len( args ) != 2:
print "usage: %s user_id rate_plan_index" % sys.argv[ 0 ]
sys.exit( 1 )
main( args )
main( sys.argv[ 1: ] )