Example #1
0
        request.data = json.loads(request.data)


@app.after_request
def add_headers(response):
    if isinstance(response.data, dict) or isinstance(response.data, list):
        response.headers["Content-Type"] = "application/json"
    response.headers.add_header("Access-Control-Allow-Origin", "*")
    response.headers.add_header("Access-Control-Allow-Headers", "Content-Type")
    print "response headers are %s" % response.headers
    return response


# TODO move this back to storage.__init__
app.config["MONGOALCHEMY_SERVER"] = os.environ.get("OPENSHIFT_MONGODB_DB_HOST", "localhost")
app.config["MONGOALCHEMY_PORT"] = int(os.environ.get("OPENSHIFT_MONGODB_DB_PORT", 27017))
app.config["MONGOALCHEMY_DATABASE"] = os.environ.get("MONGO_DB", "scribble")
app.config["MONGOALCHEMY_USER"] = os.environ.get("OPENSHIFT_MONGODB_DB_USERNAME")
app.config["MONGOALCHEMY_PASSWORD"] = os.environ.get("OPENSHIFT_MONGODB_DB_PASSWORD")
app.config["MONGOALCHEMY_SERVER_AUTH"] = True
app.config["REDIS_SERVER"] = os.environ.get("OPENSHIFT_REDIS_HOST", "localhost")
app.config["REDIS_PORT"] = int(os.environ.get("OPENSHIFT_REDIS_PORT", "6379"))

db = MongoAlchemy(app)

scrib_shots = db.session.db.connection.scribble_shots
scrib_grid = GridFS(scrib_shots)


def make_celery(app):
    celery = Celery(app.import_name, broker=app.config["CELERY_BROKER_URL"])
Example #2
0
import os, urlparse
from flask import Flask
from flaskext.mongoalchemy import MongoAlchemy, BaseQuery

app = Flask(__name__)

mongohq_url = os.environ.get("MONGOHQ_URL", None)
if mongohq_url:
    o = urlparse.urlparse(mongohq_url)
    app.config["MONGOALCHEMY_SERVER"] = o.hostname
    app.config["MONGOALCHEMY_PORT"] = o.port
    app.config["MONGOALCHEMY_USER"] = o.username
    app.config["MONGOALCHEMY_PASSWORD"] = o.password
    app.config["MONGOALCHEMY_DATABASE"] = o.path[1:]
    app.config["MONGOALCHEMY_SERVER_AUTH"] = False
else:
    app.config["MONGOALCHEMY_DATABASE"] = "library"

db = MongoAlchemy(app)


class Card(db.Document):
    # stores whats on the card. May be abstracted further out
    front = db.StringField()
    back = db.StringField()

    uniqueId = db.StringField()
    # used for calculating the SRS numbers

    repetition = db.IntField()
    interval = db.IntField()