Example #1
0
def create_app(app_name, config):
	
	app = Flask(app_name)
	app.config.from_object(config)

	app.db = SQLAlchemy(app)

	app.migrate = Migrate(app,app.db)

	app.bcrypt = Bcrypt(app)

	app.api = Api(app, prefix='/api/v1')

	app.api_registry = []

	return app
Example #2
0
from app.api_1_0 import blueprint as api

# configure according which machine we're running
module = __import__('config')
configuration = getattr(module, os.getenv('LOCAL_ENV', 'ProductionEnvironment'))

# Basic App initialization     ===============================================

app = Flask(__name__)
app.config.from_object(configuration)

app.appBucket = Bucket('couchbase://' + app.config['CB_HOST'] + '/' + app.config['CB_APP_BUCKET'])
app.userBucket = Bucket('couchbase://' + app.config['CB_HOST'] + '/' + app.config['CB_USERS_BUCKET'])

jwt = JWT(app)
app.bcrypt = Bcrypt(app)

# initialize JWT authentication  ======================================
@jwt.authentication_handler
def authenticate(username, password):
    bucket = app.userBucket
    print '@authentication handler'
    user = []
    try:
        q = N1QLQuery('SELECT * FROM ' + app.config['CB_USERS_BUCKET'] + ' WHERE username = $user', user=username)
        results = bucket.n1ql_query(q)

        print vars(results)

        resultsCount = 0
Example #3
0
def create_app(app_name, config_obj, with_api=True):
	""" Generates and configures the main shop application. All additional """
	# Launching application
	app = Flask(app_name) # So the engine would recognize the root package

	# Load Configuration
	app.config.from_object(config_obj)

	# Loading assets
	assets = Environment(app)
	assets.from_yaml('assets.yaml')
	app.assets = assets

	# Initialize Mail
	app.mail = Mail(app)

	# Initializing login manager
	login_manager = LoginManager()
	login_manager.login_view = app.config.get('LOGIN_VIEW', 'main.index')
	# login_manager.login_message = 'You need to be logged in to access this page'
	login_manager.session_protection = 'strong'
	login_manager.setup_app(app)
	app.login_manager = login_manager

	# Initializing principal manager
	app.principal = Principal(app)

	# Initializing bcrypt password encryption
	bcrypt = Bcrypt(app)
	app.bcrypt = bcrypt

	# Initializing Database
	db = SQLAlchemy(app)
	app.db = db

	# Initializing Migrate
	migrate = Migrate(app, db, "from fitted.models import *")
	app.migrate = migrate

	photos = UploadSet('photos', IMAGES)
	archives = UploadSet('archives', ARCHIVES)

	configure_uploads(app, (photos, archives))

	patch_request_class(app, 2 * 1024 * 1024) # Patches to 2MB file uploads max.

	app.photos = photos
	app.archives = archives

	# Integrate Elasticsearch

	es_config = app.config.get("ES_CONFIG", [])

	app.es = Elasticsearch(es_config)

	# Integrate sms with Twilio
	app.sms = TwilioRestClient(app.config.get("TWILIO_API_SID"), app.config.get("TWILIO_API_TOKEN"))


	# Redis store for session management
	# The process running Flask needs write access to this directory:
	# store = RedisStore(redis.StrictRedis())

	# # this will replace the app's session handling
	# KVSessionExtension(store, app)

	# configure sentry
	# if not app.config.get("DEBUG", False):
	# 	sentry = Sentry(app)

	# 	app.sentry = sentry

	# inject celery into the app
	app.celery = make_celery(app)

	# injecting mongodb support
	# app.mongo = PyMongo(app)

	# flask s3 integration
	app.s3 = FlaskS3(app)


	# Facebook & Twitter Integration
	app.facebook = oauth.remote_app('facebook',
		app_key='FACEBOOK'
	)


	oauth.init_app(app)



	# Initializing the restful API
	if with_api:
		api = restful.Api(app, prefix='/api/v1')
		app.api = api

	# Initialize Logging
	if not app.debug:
		import logging
		from logging.handlers import RotatingFileHandler
		file_handler = RotatingFileHandler("/var/log/fitted/%s.log" % app.config.get("LOGFILE_NAME", app_name), maxBytes=500*1024)
		file_handler.setLevel(logging.WARNING)
		from logging import Formatter
		file_handler.setFormatter(Formatter(
		    '%(asctime)s %(levelname)s: %(message)s '
		    '[in %(pathname)s:%(lineno)d]'
		))
		app.logger.addHandler(file_handler)

	#include an api_registry to the application
	app.api_registry = [] #a simple list holding the values to be registered

	return app