app.config["UPLOADED_DOCS_DEST"] = TEMP_DIR docs = UploadSet(name="docs", extensions=("txt")) configure_uploads(app, (docs,)) patch_request_class(app, 4 * 1024 * 1024) # 4MB # setup logging logging.basicConfig(filename=os.path.join(base_dir, "../", "samediff.log"), level=logging.DEBUG) logger = logging.getLogger(__name__) logger.info("Temp Dir is %s" % TEMP_DIR) db_client = MongoClient(get_mongo_uri()) app.db = db_client[settings.get("db", "name")] app.db_collection = app.db[settings.get("db", "collection")] @app.before_request def before(): if request.view_args and "lang_code" in request.view_args: if request.view_args["lang_code"] not in ("es", "en"): return abort(404) # bail on invalid language g.current_lang = request.view_args["lang_code"] request.view_args.pop("lang_code") @babel.localeselector def get_locale():
def _get_db_collection(): db_client = MongoClient(samediff.get_mongo_uri()) db = db_client[settings.get('db','name')] db_collection = db[settings.get('db','collection')] return db_collection