Example #1
0
def create_app(config_name):
    app = Flask(__name__)
    app.config["MONGODB_DB"] = os.environ.get("DB_NAME", "semcomp")
    app.config["MONGODB_HOST"] = os.environ.get("DB_HOST", "localhost")
    app.config["MONGODB_PORT"] = int(os.environ.get("DB_PORT", 27017))
    app.config["MONGODB_USERNAME"] = os.environ.get("DB_USER", "")
    app.config["MONGODB_PASSWORD"] = os.environ.get("DB_PASS", "")

    db.init_app(app)

    app.jinja_env.add_extension("pyjade.ext.jinja.PyJadeExtension")

    from .main import main as main_blueprint
    from .api import api as api_blueprint

    app.register_blueprint(main_blueprint)
    app.register_blueprint(api_blueprint)

    api_rest = Api(app, prefix="/api")

    # adicionar rotas
    from .api import routes

    routes.route_all_resources(api_rest)

    return app
def create_app():
    app = Flask(__name__, static_folder=os.path.join(PROJECT_ROOT, "public"), static_url_path="/public")

    app.config.update(os.environ)

    # TODO: read in right hand side from HT config vars
    app.config["SECRET_KEY"] = "secret"
    app.config["SECURITY_PASSWORD_HASH"] = "bcrypt"
    app.config["MONGODB_DB"] = "flask_security_test"
    app.config["MONGODB_HOST"] = "localhost"
    app.config["MONGODB_PORT"] = 27017

    app.debug = app.config["X_HT_DEBUG"] == "True"

    app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {"/": os.path.join(os.path.dirname(__file__), "public")})

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template("404.html"), 404

    SecuritySetup(app)

    # import & register blueprints here:
    # ===================================
    from hero_tmpl.views.security import security

    app.register_blueprint(security)

    from hero_tmpl.views.misc import misc

    app.register_blueprint(misc)

    return app
Example #3
0
def create_app(config=None):
    app = Flask("tweet_wall")
    app.config["MONGODB_DB"] = os.getenv("TW_MONGODB_DB")
    app.config["MONGODB_HOST"] = os.getenv("TW_MONGODB_HOST")

    db.init_app(app)

    app.jinja_env.filters["twitter_normal_to_bigger"] = twitter_normal_to_bigger

    token = read_bearer_token_file(".oauth2_bearer_token")
    twitter = Twitter(auth=OAuth2(bearer_token=token))

    @app.route("/approved")
    @app.route("/index")
    @app.route("/")
    def approved_tweets():
        tweets = model.Tweet.objects(approved=True).order_by("-id_str").all()
        return render_template("public.html", tweets=tweets)

    @app.route("/approve", methods=["GET"])
    @requires_auth
    def approve_tweet_get():
        hash_tag = _get_hash_tag_query_param()
        tweets_twitter = twitter.search.tweets(q=hash_tag)["statuses"]

        tweets_local = model.Tweet.objects(approved=True).all()
        tweets_local_ids = [tweet.id_str for tweet in tweets_local]

        tweets_not_approved = [tweet for tweet in tweets_twitter if tweet["id_str"] not in tweets_local_ids]

        return render_template("approve_tweets.html", tweets=tweets_not_approved)

    @app.route("/approve/<string:id_str>", methods=["POST"])
    @requires_auth
    def approve_tweet_post(id_str):
        tweet = twitter.statuses.show(id=id_str)
        tweet["approved"] = True
        tweet.pop("id")
        model.Tweet.objects(id_str=tweet["id_str"]).update_one(upsert=True, **tweet)
        return redirect(url_for("approve_tweet_get"))

    @app.route("/twitter")
    def tweets():
        hash_tag = _get_hash_tag_query_param()
        tweet_search = twitter.search.tweets(q=hash_tag)["statuses"]
        return render_template("public.html", tweets=tweet_search)

    return app
Example #4
0
def generate_app(
    debug=False,
    config_file=None,
    secret="",
    session_secret="",
    github_client_id="",
    github_client_secret="",
    github_hook_secret="",
    mongodb_db="Hook",
    mongodb_host="127.0.0.1",
    mongodb_port=27017,
    mongodb_user=None,
    mongodb_password=None,
    hooktest_secret="",
    hooktest_remote="http://127.0.0.1:5002/hooktest/rest/api/queue",
):
    app = Flask(__name__)
    app.config["JSONIFY_PRETTYPRINT_REGULAR"] = False

    if not config_file:
        app.config["SECRET_KEY"] = (session_secret,)
        app.config["GITHUB_CLIENT_ID"] = github_client_id
        app.config["GITHUB_CLIENT_SECRET"] = github_client_secret

        app.config["MONGODB_DB"] = mongodb_db
        app.config["MONGODB_HOST"] = mongodb_host
        app.config["MONGODB_PORT"] = mongodb_port

        if mongodb_user:
            app.config["MONGODB_USERNAME"] = mongodb_user
        if mongodb_password:
            app.config["MONGODB_PASSWORD"] = mongodb_password

        app.config["HOOKUI_HOOKTEST_SECRET"] = hooktest_secret
        app.config["HOOKUI_GITHUB_SECRET"] = github_hook_secret
        app.config["HOOKUI_REMOTE"] = hooktest_remote
    else:
        app.config.update(read_yaml(config_file)[0])

    app.debug = debug
    app.config["DEBUG"] = debug
    hook = HookUI(prefix="", app=app)
    return app
Example #5
0
def create_app(object_name, env="prod"):
    """
    A flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Inputs:  ::\n
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # Init the cache
    cache.init_app(app)

    # Init debug toolbar
    debug_toolbar.init_app(app)

    # Init Mongo engine
    # mongoengine.connect(config.MONGODB_FRONTEND_DB_NAME, host=config.MONGODB_HOST, port=config.MONGODB_PORT)
    app.config["MONGODB_DB"] = config.MONGODB_FRONTEND_DB_NAME
    app.config["MONGODB_HOST"] = config.MONGODB_HOST
    app.config["MONGODB_PORT"] = config.MONGODB_PORT
    db.init_app(app)

    # Init login_manager
    login_manager.init_app(app)
    login_manager.login_view = "main.login"
    login_manager.refresh_view = "main.login"
    # Init current to track current project/experiment
    current.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register all the  blueprints
    from controllers import (
        main,
        error,
        dashboard,
        new_experiment,
        new_project,
        account_settings,
        project,
        experiment,
        targets,
        setup,
    )

    app.register_blueprint(main)
    app.register_blueprint(error, url_prefix="/error")
    app.register_blueprint(dashboard, url_prefix="/dashboard")
    app.register_blueprint(new_experiment, url_prefix="/new_experiment")
    app.register_blueprint(new_project, url_prefix="/new_project")
    app.register_blueprint(account_settings, url_prefix="/account_settings")
    app.register_blueprint(project, url_prefix="/project")
    app.register_blueprint(experiment, url_prefix="/experiment")
    app.register_blueprint(targets, url_prefix="/targets")
    app.register_blueprint(setup, url_prefix="/setup")

    return app
Example #6
0
from flask import Flask, request, g
from flaskext.mongoobject import MongoObject
import settings
from json import dumps

app = Flask(__name__)

app.config["MONGODB_HOST"] = settings.MONGODB_HOST
app.config["DEBUG"] = settings.DEBUG
app.config["MONGODB_DATABASE"] = settings.MONGODB_DATABASE_DEVELOPMENT

db = MongoObject(app)


class Task(db.Model):
    __collection__ = "tasks"


@app.route("/add", methods=["POST"])
def new_task():
    name = request.form["name"]
    description = request.form["description"]
    task = Task(name=name, description=description)
    task.save()
    return "Saved!"


@app.route("/delete", methods=["GET"])
def delete_task():
    id = request.args["id"]
    # XXX - Not scalable way to delete one task
from flask import Flask
from flaskext.mongoobject import MongoObject

app = Flask(__name__)
app.config["MONGODB_HOST"] = "mongodb://localhost:27017"
app.config["DEBUG"] = True
app.config["MONGODB_DATABASE"] = "hello"

db = MongoObject(app)


class Post(db.Model):
    __collection__ = "posts"


@app.route("/")
def index():
    post = Post(name="test", author="Daniel")
    post.save()

    post = Post.query.find_one({"name": "test"})
    total = Post.query.count()
    return "Total: %d. Post name: %s by author: %s" % (total, post.name, post.author)


if __name__ == "__main__":
    app.run()
Example #8
0
# -*- coding: utf-8 -*-
from flask import Flask, g
from flask.ext.mongoengine import MongoEngine
from timetable.api import api_part
from timetable.schedule import schedule_part
import os

app = Flask(__name__)

app.config["MONGODB_DB"] = os.environ["MONGODB_DB"]
app.config["MONGODB_HOST"] = os.environ["MONGODB_HOST"]
app.config["MONGODB_PORT"] = os.environ["MONGODB_PORT"]
app.config["MONGODB_USERNAME"] = os.environ["MONGODB_USERNAME"]
app.config["MONGODB_PASSWORD"] = os.environ["MONGODB_PASSWORD"]

app.config["SERVER_NAME"] = os.environ["SERVER_NAME"]  # 'localhost:5000'

db = MongoEngine(app)

import timetable.controllers
import timetable.api.controllers
import timetable.schedule.controllers


app.register_blueprint(api_part, url_prefix="/api")  # subdomain='api'
app.register_blueprint(schedule_part, url_prefix="/schedule")  # subdomain='schedule'
Example #9
0
File: hello.py Project: CMarth/OBET
from flask.ext.wtf import Form
from wtforms import StringField, SubmitField
from wtforms.validators import Required

##################
#    Config      #
##################
app = Flask(__name__)
app.config["SECRET_KEY"] = "LSKFJDSLf84wi7rleIFdso8fsL9F87SDAOIFUSOH87FS70Q03958734LKdllkjdsflskjf"

###################
#    DB Config    #
###################

app.config["MONGO_URI"] = "mongodb://mikachama:Haruka10@ds033419.mongolab.com:33419/inventory"
app.config["MONGODB_HOST"] = "ds033419.mongolab.com"
app.config["MONGODB_PORT"] = 33419
app.config["MONGO_DBNAME"] = "inventory"
app.config["MONGODB_USERNAME"] = "mikachama"
app.config["MONGODB_PASSWORD"] = "Haruka10"
app.config["ADMIN_EMAIL"] = "admin@admin.com"
app.config["ADMIN_PASS"] = "testerpassword"
app.config["MONGODB_SETTINGS"] = {
    "db": "inventory",
    "host": "mongodb://mikachama:Haruka10@ds033419.mongolab.com:33419/inventory",
}


###############
#    Init     #
###############
    template_folder="../angular/app/jinja-templates",
)

# overriding default jinja template tags, to avoid conflicts with angularjs
app.jinja_env.variable_start_string = "{["
app.jinja_env.variable_end_string = "]}"

app.config["SECRET_KEY"] = os.environ["SECRET_KEY"]

# allow debugging heroku code
if os.environ.get("DEBUG"):
    app.config["DEBUG"] = True

# create the db connection, username and password only set if it exists
if os.environ.get("ENV", "dev") == "pro":
    app.config["MONGODB_HOST"] = os.environ.get("MONGOLAB_URI")
    app.config["MONGODB_DB"] = "final"
else:
    app.config["MONGODB_USERNAME"] = os.environ.get("MONGO_DB_USERNAME")
    app.config["MONGODB_PASSWORD"] = os.environ.get("MONGO_DB_PASSWORD")
    app.config["MONGODB_DB"] = "test"

db = MongoEngine(app)

app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER

# set up login manager
login_manager = LoginManager()
login_manager.init_app(app)

# set url to redirect to for login
Example #11
0
import os
from flask import Flask, jsonify, make_response, request, abort
from flask.ext.httpauth import HTTPBasicAuth
from passlib.apps import custom_app_context as pwd_context
from pymongo import MongoClient
from bson import json_util
from bson.objectid import ObjectId
import datetime
import json

app = Flask(__name__)
app.config["MONGODB_HOST"] = "localhost"
app.config["MONGODB_PORT"] = 27017
app.config["CMS_DB"] = "cms"

client = MongoClient()
db = client[app.config["CMS_DB"]]

auth = HTTPBasicAuth()


class User:
    """Represents a user with methods for generating 
  password hashes and verification
  """

    username = ""
    password_hash = ""

    def __init__(self, username):
        self.username = username
Example #12
0
from flask import Flask
from flask.ext.mongoengine import MongoEngine

app = Flask(__name__)
app.config["MONGODB_DB"] = "DataRoomba"
app.config["MONGODB_HOST"] = "dharma.mongohq.com"
app.config["MONGODB_PORT"] = 10019
app.config["MONGODB_USER"] = "dataroomba"
app.config["MONGODB_PASS"] = "There is no data"
app.config["SECRET_KEY"] = "KeepThisS3cr3t"

db = MongoEngine(app)

if __name__ == "__main__":
    app.run()
Example #13
0
configuration = None
if env == "development":
    app.config["SECRET_KEY"] = config.dev["secret_key"]
    app.config["STRIPE_PUBLISHABLE_KEY"] = config.dev["stripe_publishable_key"]
    stripe.api_key = config.dev["stripe_secret_key"]
    app.config["SEND_FILE_MAX_AGE_DEFAULT"] = 0
    app.config["passwordResetPrefix"] = config.dev["passwordResetPrefix"]
    app.config["MONGODB_DB"] = config.dev["mongodb_db"]
    app.config["SECRET_KEY"] = config.dev["secret_key"]
    app.config["MONGODB_USERNAME"] = config.dev["mongodb_username"]
    app.config["MONGODB_PASSWORD"] = config.dev["mongodb_password"]
    app.config["MONGODB_HOST"] = config.dev["mongodb_host"]
    app.config["MONGODB_PORT"] = config.dev["mongodb_port"]
    app.config["checkoutRedirect"] = config.dev["checkoutRedirect"]
elif env == "production":
    app.config["MONGODB_DB"] = config.production["mongodb_db"]
    app.config["SECRET_KEY"] = config.production["secret_key"]
    app.config["MONGODB_USERNAME"] = config.production["mongodb_username"]
    app.config["MONGODB_PASSWORD"] = config.production["mongodb_password"]
    app.config["MONGODB_HOST"] = config.production["mongodb_host"]
    app.config["MONGODB_HOST"] = config.production["mongodb_host"]
    app.config["MONGODB_PORT"] = config.production["mongodb_port"]
    app.config["STRIPE_PUBLISHABLE_KEY"] = config.production["stripe_publishable_key"]
    app.config["passwordResetPrefix"] = config.production["passwordResetPrefix"]
    app.config["checkoutRedirect"] = config.production["checkoutRedirect"]
    stripe.api_key = config.production["stripe_secret_key"]

app.config["bitlyAccessToken"] = "b9aa357f2106667319586b4d47b30441553e4098"


db = MongoEngine(app)
Example #14
0
from application import (
    register_views,
    register_filters,
    register_db,
    set_logging,
    configure_errorhandlers,
    configure_develop_handlers,
)
from config import DefaultConfig

config = DefaultConfig()
app = Flask(__name__)
app.debug = config.DEBUG
app.secret_key = config.SECRET_KEY
app.config["CACHE_TYPE"] = config.CACHE_TYPE
app.config["MONGODB_HOST"] = config.MONGODB_HOST
app.config["MONGODB_PORT"] = config.MONGODB_PORT
app.config["MONGODB_DATABASE"] = config.MONGODB_DATABASE

db = MongoKit(app)
setup_themes(app, app_identifier="wordstore", theme_url_prefix="/themes")
cache = Cache(app)

register_db(db)
register_views(app)
register_filters(app)
configure_errorhandlers(app)

if config.DEV:
    configure_develop_handlers(app)
Example #15
0
import local_settings
from flaskext.mongoengine import MongoEngine


# Declare and configure application
app = Flask(__name__, static_url_path="/static")
app.config.from_pyfile("local_settings.py")
if app.config["MONGOLAB_URI"]:
    from pymongo.uri_parser import parse_uri

    params = parse_uri(app.config["MONGOLAB_URI"])
    app.config["MONGODB_DB"] = params["database"]
    app.config["MONGODB_USERNAME"] = params["username"]
    app.config["MONGODB_PASSWORD"] = params["password"]
    app.config["MONGODB_HOST"] = params["nodelist"][0][0]
    app.config["MONGODB_PORT"] = params["nodelist"][0][1]
else:
    app.config["MONGODB_DB"] = "tetetetelephone"


db = MongoEngine(app)


def register_blueprints():
    from mmdgot.views import game_blueprint

    app.register_blueprint(game_blueprint)


register_blueprints()
Example #16
0
from datetime import datetime
from flask import Flask, session
from flask.ext.mosession import MoSessionExtension

app = Flask(__name__)

app.config["MONGODB_HOST"] = "127.0.0.1"
app.config["MONGODB_PORT"] = 27017
app.config["MONGODB_DATABASE"] = "session_test_db"
mosession = MoSessionExtension(app)


@app.route("/")
def hello():
    if "first_visit" not in session:
        session["first_visit"] = datetime.now()

    return "Hi dear, your first visit was on " + str(session["first_visit"])


if __name__ == "__main__":
    app.run()
Example #17
0
from flask import Flask
from flask.ext.mongoengine import MongoEngine
import hashlib

app = Flask(__name__)

HOST = "oceanic.mongohq.com"
db_settings = {"MONGODB_DB": "<db>", "MONGODB_USERNAME": "<user>", "MONGODB_PASSWORD": "<pass>", "MONGODB_PORT": 10046}
app.config = dict(list(app.config.items()) + list(db_settings.items()))
app.config["MONGODB_HOST"] = (
    "mongodb://%(MONGODB_USERNAME)s:%(MONGODB_PASSWORD)s@" + HOST + ":%(MONGODB_PORT)s/%(MONGODB_DB)s"
) % db_settings
secret_key = hashlib.sha1()
app.config["SECRET_KEY"] = secret_key.digest()

db = MongoEngine(app)


def register_blueprints(app):
    # Prevents circular imports
    from tumblelog.views import posts
    from tumblelog.admin import admin

    app.register_blueprint(posts)
    app.register_blueprint(admin)


register_blueprints(app)

if __name__ == "__main__":
    app.run()
Example #18
0
    mail_SSL,
    mail_port,
    mail_TLS,
    mail_user,
    mail_pass,
)


app = Flask(__name__)

app.config["DEBUG"] = False
app.config["SECRET_KEY"] = secret_key

# MongoDB Config
app.config["MONGODB_DB"] = mongo_db
app.config["MONGODB_HOST"] = mongo_host
app.config["MONGODB_PORT"] = mongo_port

# Security Features
app.config["SECURITY_REGISTERABLE"] = user_enable_registration
app.config["SECURITY_TRACKABLE"] = user_enable_tracking
app.config["SECURITY_EMAIL_SENDER"] = user_from_email
app.config["SECURITY_PASSWORD_HASH"] = pwhash
app.config["SECURITY_PASSWORD_SALT"] = salt
app.config["SECURITY_CONFIRMABLE"] = True
app.config["SECURITY_EMAIL_SUBJECT_REGISTER"] = user_register_email_subject

# Email
app.config["MAIL_SERVER"] = mail_url
app.config["DEBUG"] = False
app.config["MAIL_PORT"] = mail_port
Example #19
0
from flask import session
from flask import url_for
from flaskext.mongokit import MongoKit
from functools import wraps
from models.bookmark import BOOKMARK_SORT_OPTIONS
from models.bookmark import BOOKMARK_SORT_OPTIONS_REVERSE
from utils import MAX_CIRCLE_NAME_LENGTH
from utils import check_circle_name
from utils import check_email
from utils import check_name
from utils import check_password
from utils import url_title

app = Flask(__name__)
app.config["MONGODB_DATABASE"] = MONGODB_DATABASE
app.config["MONGODB_HOST"] = MONGODB_HOST
app.config["MONGODB_PORT"] = MONGODB_PORT
# app.config['MONGODB_USERNAME'] = MONGODB_USERNAME
# app.config['MONGODB_PASSWORD'] = MONGODB_PASSWORD
app.config["SECRET_KEY"] = SECRET_KEY
db = Database(app)

#####################
##                 ##
## Utility Methods ##
##                 ##
#####################


def access_denied():
    """