def main(): app = create_app() csrf(app) # If we're on the local server, let's enable Flask debugging. # For more information: http://goo.gl/RNofH if settings.debug: app.debug = True app = get_debugged_app(app) settings.debug_profiler_enabled = profiler_config.should_profile(app) app = profiler.ProfilerWSGIMiddleware(app) CGIHandler().run(app)
def init_app(self, app): self.app = app self.banner = 'Welcome!' self.cookie_httponly = True self._json_views = [] self.app.before_request(self.before_request) self.app.after_request(self.after_request) # Set other extentions to app store = DictStore() KVSessionExtension(store, self.app) csrf(self.app) self.csrf_exempt = csrf_exempt
import httplib2 import json import os from flask import make_response import requests # dicttoxml for XML functions from dicttoxml import dicttoxml app = Flask(__name__) from functools import wraps # call the csrf function csrf(app) CLIENT_ID = json.loads( open('client_secrets.json', 'r').read())['web']['client_id'] APPLICATION_NAME = "Restaurant Menu Application" # Connect to Database and create database session engine = create_engine('sqlite:///catalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # function decorator to avoid code repetition for login
def create_app(cyd=None): """Create the web interface WSGI application""" if cyd is None: cyd = cydra.Cydra() from flask import Flask from flaskext.csrf import csrf from cydra.web.themes import IThemeProvider, ThemedTemplateLoader, patch_static app = Flask(__name__) # register themes theme_providers = ExtensionPoint(IThemeProvider, component_manager=cyd) app.config['cydra_themes'] = dict([(theme.name, theme) for theme in theme_providers.get_themes()]) default_theme = cyd.config.get('web').get('default_theme') if default_theme is not None and default_theme in app.config['cydra_themes']: default_theme = app.config['cydra_themes'][default_theme] logger.debug("Default theme: %s", default_theme.name) else: default_theme = None theme_detector = ThemeDetector(default_theme) app.before_request(theme_detector) # replace default loader app.jinja_options = Flask.jinja_options.copy() app.jinja_options['loader'] = ThemedTemplateLoader(app) # patch static file resolver patch_static(app) # secret key for cookies app.secret_key = os.urandom(24) # consider the cydra instance to be a form of configuration # and therefore store it in the config dict. app.config['cydra'] = cyd # common views app.add_url_rule('/login', 'login', login) # Add shorthands to context app.context_processor(add_shorthands_to_context) # load frontend and backend from cydra.web.frontend import blueprint as frontend_blueprint patch_static(frontend_blueprint, 'frontend') #from cydra.web.admin import blueprint as admin_blueprint #patch_static(admin_blueprint, 'admin') app.register_blueprint(frontend_blueprint) #app.register_blueprint(admin_blueprint) # load additional blueprints pages = ExtensionPoint(IBlueprintProvider, component_manager=cyd) for bpprovider in pages: bp = bpprovider.get_blueprint() patch_static(bp, bp.name) app.register_blueprint(bp) # some utility template filters from cydra.web.filters import filters #map(app.template_filter(), filters) _ = [app.template_filter()(f) for f in filters] # prevent flask from handling exceptions app.debug = True # add CSRF protection csrf(app) # wrap in authentication middleware from cydra.web.wsgihelper import AuthenticationMiddleware app = AuthenticationMiddleware(cyd, app) # enable debugging for certain users debugusers = cyd.config.get('web').get('debug_users', []) if debugusers: from cydra.web.debugging import DebuggingMiddleware app = DebuggingMiddleware(app, debugusers) return app
request,session, g, send_file, jsonify, Response, flash from flaskext.csrf import csrf, csrf_exempt from functools import wraps from psycopg2.extras import DictCursor from jinja2 import TemplateNotFound #from werkzeug.contrib.cache import MemcachedCache from email.mime.text import MIMEText import default_settings import model #cache = MemcachedCache(['127.0.0.1:11211']) instance_path = os.path.expanduser('~/fatnest_instance/') app = Flask(__name__, instance_path=instance_path) csrf(app) app.config.from_object('fatnest.default_settings') external_cfg = os.path.join(app.instance_path, 'application.cfg') app.config.from_pyfile(external_cfg, silent=True) app.TRAP_BAD_REQUEST_ERRORS = True cached_ip = None def gen_token(): return ''.join(random.choice(string.letters) for x in range(20)) def full_url_for(name): return "http://fatnest.com%s" % (url_for(name))
cursor.execute("PRAGMA foreign_keys=ON;") cursor.close() elif os.environ.get('FLASK_ENV') == 'Production': env.from_object(config.Production) else: print >> sys.stderr, 'ERROR: No environment setup' env.from_object(config.Production) # If we don't have an environment, fall back to production ### Setup DB db.app = application db.init_app(application) db.create_all() ### Setup csrf protection csrf(application) ### Setup Mail mail = Mail() mail.init_app(application) mailerController = MailerController(application, mail) ### Register our routes from blueprints.static_routes import static_routes from blueprints.user_routes import user_routes from blueprints.campaign_routes import campaign_routes application.register_blueprint(static_routes) application.register_blueprint(user_routes) application.register_blueprint(campaign_routes)