def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it ``global_conf`` The inherited configuration for this application. Normally from the [DEFAULT] section of the Paste ini file. ``full_stack`` Whether or not this application provides a full WSGI stack (by default, meaning it handles its own exceptions and errors). Disable full_stack when this application is "managed" by another WSGI middleware. ``app_conf`` The application's local configuration. Normally specified in the [app:<name>] section of the Paste ini file (where <name> defaults to main). """ # Configure the Pylons environment load_environment(global_conf, app_conf) # The Pylons WSGI app app = PylonsApp() # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) from facebook.wsgi import create_pylons_facebook_middleware app = create_pylons_facebook_middleware(app, app_conf) # Using ToscaWidgets middleware for Sprox components. Take this out if removing Sprox usage. app = twa.make_middleware(app, { 'toscawidgets.framework': 'pylons', 'toscawidgets.framework.default_view': 'mako' }) # Routing/Session/Cache Middleware app = RoutesMiddleware(app, config['routes.map']) app = SessionMiddleware(app, config) app = CacheMiddleware(app, config) if asbool(full_stack): # Handle Python exceptions app = ErrorHandler(app, global_conf, **config['pylons.errorware']) # Display error documents for 401, 403, 404 status codes (and # 500 when debug is disabled) if asbool(config['debug']): app = StatusCodeRedirect(app) else: app = StatusCodeRedirect(app, [400, 401, 403, 404, 500]) # Establish the Registry for this application app = RegistryManager(app) # Static files (If running in production, and Apache or another web # server is handling this static content, remove the following 2 lines) static_app = StaticURLParser(config['pylons.paths']['static_files']) app = Cascade([static_app, app]) return app
def setup_app(command, conf, vars): """Place any commands to setup wegive here""" load_environment(conf.global_conf, conf.local_conf) # Load the models from wegive.model import meta meta.metadata.bind = meta.engine # Create the tables if they aren't there already if asbool(config['debug']): meta.metadata.drop_all() meta.metadata.create_all(checkfirst=True) # add some test data if we're in debug mode if asbool(config['debug']): from wegive.model import User, Gift, Charity, SocialNetwork session = meta.Session() # add Facebook network network_1 = SocialNetwork(u'Facebook', u'http://www.facebook.com/') session.add(network_1) session.flush() # add test charities charity_1 = Charity(u'Aid to Children Without Parents', 'acwp') charity_1.url = u'http://www.acwp.org/' charity_2 = Charity(u'Test Charity', 'test1') session.add_all([charity_1, charity_2]) session.flush() # add test users test_user_1 = User() test_user_1.email = u'*****@*****.**' test_user_1.password = '******' test_user_2 = User() test_user_2.email = u'*****@*****.**' test_user_2.password = '******' test_artist_1 = User() test_artist_1.email = u'*****@*****.**' test_artist_1.password = '******' session.add_all([test_user_1,test_user_2,test_artist_1]) session.flush() # add test gifts test_gift_1 = Gift(test_artist_1.id, u'Test Gift 1', True) session.add(test_gift_1) session.add_all([Gift(test_artist_1.id, u'Test Gift 2', True), Gift(test_artist_1.id, u'Test Gift 3', True), Gift(test_artist_1.id, u'Test Gift 4', True), Gift(test_artist_1.id, u'Test Gift 5', True), Gift(test_artist_1.id, u'Test Gift 6'), Gift(test_artist_1.id, u'Test Gift 7', True), Gift(test_artist_1.id, u'Test Gift 8', True), Gift(test_artist_1.id, u'Test Gift 9', True), Gift(test_artist_1.id, u'Test Gift 10', True), Gift(test_artist_1.id, u'Test Gift 11', True), Gift(test_artist_1.id, u'Test Gift 12', True), Gift(test_artist_1.id, u'Test Gift 13'), Gift(test_artist_1.id, u'Test Gift 14', True), Gift(test_artist_1.id, u'Test Gift 15', True), Gift(test_artist_1.id, u'Test Gift 16', True), Gift(test_artist_1.id, u'Test Gift 17', True), Gift(test_artist_1.id, u'Test Gift 18', True), Gift(test_artist_1.id, u'Test Gift 19', True), Gift(test_artist_1.id, u'Test Gift 20', True), Gift(test_artist_1.id, u'Test Gift 21', True), Gift(test_artist_1.id, u'Test Gift 22', True), Gift(test_artist_1.id, u'Test Gift 23', True), Gift(test_artist_1.id, u'Test Gift 24', True), Gift(test_artist_1.id, u'Test Gift 25', True), Gift(test_artist_1.id, u'Test Gift 26', True), Gift(test_artist_1.id, u'Test Gift 27', True), Gift(test_artist_1.id, u'Test Gift 28', True), Gift(test_artist_1.id, u'Test Gift 29', True), Gift(test_artist_1.id, u'Test Gift 30', True), Gift(test_artist_1.id, u'Test Gift 31', True), Gift(test_artist_1.id, u'Test Gift 32', True), Gift(test_artist_1.id, u'Test Gift 33', True), Gift(test_artist_1.id, u'Test Gift 34', True), Gift(test_artist_1.id, u'Test Gift 35', True)]) session.commit() log.debug('added data:') for row in session.query(User).all(): print row for row in session.query(Gift).all(): print row