def test_should_be_able_to_work_without_providing_server_port_user_and_password_for_database_connection(self):
     app = Flask(__name__)
     app.config["MONGOALCHEMY_DATABASE"] = "my_database"
     MongoAlchemy(app)
     self.assertEqual(app.config["MONGOALCHEMY_SERVER"], "localhost")
     self.assertEqual(app.config["MONGOALCHEMY_PORT"], "27017")
     self.assertEqual(app.config["MONGOALCHEMY_USER"], None)
     self.assertEqual(app.config["MONGOALCHEMY_PASSWORD"], None)
 def test_loads_without_database_connection_data(self):
     app = Flask(__name__)
     app.config["MONGOALCHEMY_DATABASE"] = "my_database"
     MongoAlchemy(app)
     self.assertEqual(app.config["MONGOALCHEMY_SERVER"], "localhost")
     self.assertEqual(app.config["MONGOALCHEMY_PORT"], "27017")
     self.assertEqual(app.config["MONGOALCHEMY_USER"], None)
     self.assertEqual(app.config["MONGOALCHEMY_PASSWORD"], None)
     self.assertEqual(app.config["MONGOALCHEMY_REPLICA_SET"], "")
    def should_be_able_to_work_without_providing_server_port_user_and_password_for_database_connection(self):
        from flaskext.mongoalchemy import MongoAlchemy

        app = Flask("newest_test")
        app.config["MONGOALCHEMY_DATABASE"] = "my_database"
        db = MongoAlchemy(app)
        assert_equals(app.config["MONGOALCHEMY_SERVER"], "localhost")
        assert_equals(app.config["MONGOALCHEMY_PORT"], "27017")
        assert_equals(app.config["MONGOALCHEMY_USER"], None)
        assert_equals(app.config["MONGOALCHEMY_PASSWORD"], None)
Example #4
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("portal.settings")
    app.config["MONGOALCHEMY_DATABASE"] = "portal"

    from portal.models import db

    db.init_app(app)

    from portal.login import door

    app.register_module(door)

    from portal.users import portal

    app.register_module(portal)

    return app
Example #5
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()
 def test_should_be_able_to_create_two_decoupled_mongoalchemy_instances(self):
     app = Flask(__name__)
     app.config["MONGOALCHEMY_DATABASE"] = "my_database"
     db1 = MongoAlchemy(app)
     db2 = MongoAlchemy(app)
     assert db1.Document is not db2.Document, "two documents should not be the same object"
Example #7
0
import datetime
from pytz import timezone, UTC
import json
import re

from jinja2 import evalcontextfilter, Markup, escape

from flask import Flask, request, render_template, jsonify
from flaskext.mongoalchemy import MongoAlchemy

app = Flask(__name__)
app.config["DEBUG"] = True
app.config["MONGOALCHEMY_DATABASE"] = "zarkov"
app.config["MONGOALCHEMY_SERVER"] = "kilgore"
db = MongoAlchemy(app)

_paragraph_re = re.compile(r"(?:\r\n|\r|\n){2,}")


class Context(db.Document):
    config_collection_name = "context"

    status = db.IntField()
    description = db.StringField()
    server = db.StringField()


class Extra(db.Document):
    config_collection_name = "extra"

    stderr = db.StringField()
Example #8
0
from flaskext.script import Manager
from flaskext.mongoalchemy import MongoAlchemy
import os, datetime

# ------------
# App Config
# ------------
app = Flask(__name__)
app.config["SECRET_KEY"] = "asdf"
app.config["DEBUG"] = False
app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False
app.config["CACHE_TYPE"] = "simple"
toolbar = DebugToolbarExtension(app)

# Database URI - sqlite3 for testing
app.config["MONGOALCHEMY_DATABASE"] = "tweeter"

# Password hashing configuration
app.config["BCRYPT_SALT_ROUNDS"] = 12

# Declare database object
db = MongoAlchemy(app)

# Setup login managers
login_manager = LoginManager()
login_manager.setup_app(app)
login_manager.login_view = "login"


# ---------------
# JS/CSS Assets
Example #9
0

@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"])
    celery.conf.update(app.config)
Example #10
0
from flask import Flask, url_for
from flask.ext.login import LoginManager
from flask.ext.uploads import UploadSet, configure_uploads, IMAGES, UploadNotAllowed
from flask.ext.mongoalchemy import MongoAlchemy
from flask.ext.gravatar import Gravatar
from flask.ext.admin import Admin, BaseView, expose
import os

app = Flask(__name__)
app.config["DEBUG"] = True
app.config["MONGOALCHEMY_DATABASE"] = "test"
app.config["SECRET_KEY"] = "somesecretkey"
app.config["UPLOADED_FILES_DEST"] = os.getcwd() + "/stone/static/files"

db = MongoAlchemy(app)
gravatar = Gravatar(app, size=64, rating="g", default="retro", force_default=False, force_lower=False)
files = UploadSet("files", IMAGES)
login_manager = LoginManager()

login_manager.init_app(app)
configure_uploads(app, files)


@login_manager.user_loader
def load_user(userid):
    return User.query.get(userid)


def datetimeformat(value, format="%H:%M / %d-%m-%Y"):
    return value.strftime(format)
Example #11
0
TWITTER_APP_ID = "4TTmTkkoDqUuxsDhKYzXQ"
TWITTER_APP_SECRET = "nebfZIBjCa8VnKxkf2KVe76EjtFbEalGr5DPqa7YU9A"


_is_deploy = True
if socket.gethostname() in ["au01rh00122", "SteMac.local"]:
    _is_deploy = False


app = Flask(__name__)
if _is_deploy:
    app.config["MONGOALCHEMY_SERVER"] = os.environ["OPENSHIFT_MONGODB_DB_HOST"]
    app.config["MONGOALCHEMY_USER"] = os.environ["OPENSHIFT_MONGODB_DB_USERNAME"]
    app.config["MONGOALCHEMY_PASSWORD"] = os.environ["OPENSHIFT_MONGODB_DB_PASSWORD"]
    app.config["MONGOALCHEMY_DATABASE"] = os.environ["OPENSHIFT_APP_NAME"]
else:
    app.config["MONGOALCHEMY_DATABASE"] = "watchit"

db = MongoAlchemy(app)

from User import User

oauth = OAuth()
twitter = oauth.remote_app(
    "twitter",
    base_url="https://api.twitter.com/1/",
    request_token_url="https://api.twitter.com/oauth/request_token",
    access_token_url="https://api.twitter.com/oauth/access_token",
    authorize_url="https://api.twitter.com/oauth/authenticate",
    consumer_key=TWITTER_APP_ID,
    consumer_secret=TWITTER_APP_SECRET,
Example #12
0
from flask import Flask, jsonify
from flask.ext.mongoalchemy import MongoAlchemy
from bson.objectid import ObjectId


app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "hacktx"
db = MongoAlchemy(app)


class Course(db.Document):
    deptAb = db.StringField()
    deptName = db.StringField()
    courseNum = db.StringField()
    courseName = db.StringField()
    teacherName = db.StringField()


class StudyInstance(db.Document):
    building = db.StringField()
    gpsCoords = db.StringField()
    courseID = db.DocumentField(Course)
    notes = db.StringField()


@app.route("/search/dept/<ab>")
def search_dept(ab):
    c = Course.query.filter(Course.deptAb == ab).all()
    l = []
    for course in c:
        l.append([course.courseNum, course.courseName])
Example #13
0
import json

from flask import Flask, jsonify, request, Response
from flaskext.mongoalchemy import MongoAlchemy


ENDPOINT = "http://data.nasa.gov/api/"

app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "nasadata"
db = MongoAlchemy(app)

# These imports must be below the db definition
from api.parsers import datanasa
from api.parsers.datanasa import Dataset, Tag
from api.parsers import grin
from api.parsers.grin import Grin
from api.parsers import kepler

# FIXME: Need to call an 'update' function which loops and gets each dataset
datanasa.get_dataset(619)


def hacky_jsonify_list(data_list):
    # this can be replaced by providing a serialization methods on the Dataset
    # and the DatasetQuery objects
    return Response(json.dumps(data_list), mimetype="application/json")


@app.route("/", methods=["GET"])
def index():
Example #14
0
import cPickle as pickle

from flaskext.mongoalchemy import MongoAlchemy

from models import Call, SMS, Trax
from call import CallStateMachDaddy

from functools import wraps

# import pymongo.objectid


app = Flask(__name__)
app.config.from_object("config")
app.config["MONGOALCHEMY_DATABASE"] = "callz"
db = MongoAlchemy(app)

song_urls = [
    "http://50.116.10.109/~csik/plivo_sounds/old_skool.mp3",
    "http://50.116.10.109/~csik/plivo_sounds/reggae_1.mp3",
    "http://50.116.10.109/~csik/plivo_sounds/swing.mp3",
    "http://50.116.10.109/~csik/plivo_sounds/vibrant_thing.mp3",
    "http://50.116.10.109/~csik/plivo_sounds/afro_classic.mp3",
]


@app.route("/")
def hello():
    return "A very serious Hello World."
A simple application that shows how Flask and jQuery get along.

:copyright: (c) 2010 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""

# INIT

from __future__ import division
from flask import Flask, jsonify, render_template, request, redirect, url_for, session
from flaskext.mongoalchemy import MongoAlchemy
import urllib, json, score_calculation, fetch_fb_functions, datetime

app = Flask(__name__)
app.config["DEBUG"] = True
app.config["MONGOALCHEMY_DATABASE"] = "fb_close_friends"
db = MongoAlchemy(app)

# DOCUMENTS


class Score(db.Document):
    friend_uid = db.StringField()
    score = db.FloatField()


class User(db.Document):
    uid = db.StringField()
    modified_time = db.ModifiedField()
    set_of_scores = db.ListField(db.DocumentField(Score), min_capacity=0, max_capacity=20)
Example #16
0
import datetime
from copy import deepcopy
from flask import Flask
from flask import request, url_for, render_template
from flaskext.mongoalchemy import MongoAlchemy
import shelve
import feedparser
import plivo
import sys
import re
import twitter
from HTMLParser import HTMLParser

app = Flask(__name__)
app.config.from_object("config")
app.config["MONGOALCHEMY_DATABASE"] = "watchTest"
db = MongoAlchemy(app)

c_key = app.config("CONSUMER_KEY")
c_secret = app.config("CONSUMER_SECRET")
a_t_key = app.config("ACCESS_TOKEN_KEY")
a_t_secret = app.config("ACCESS_TOKEN_SECRET")

api = twitter.Api(
    consumer_key=c_key, consumer_secret=c_secret, access_token_key=a_t_key, access_token_secret=a_t_secret
)

auth_id = app.config("AUTH_ID")
auth_token = app.config("AUTH_TOKEN")

Example #17
0
@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-Methods", "GET,PUT,POST,DELETE,OPTIONS,HEAD")
    response.headers.add_header("Access-Control-Allow-Origin", "*")
    response.headers.add_header("Access-Control-Allow-Headers", "Content-Type,Authorization")
    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", "wrestlerdb")
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

db = MongoAlchemy(app)

app.secret_key = str(uuid.uuid4())
DEBUG = True

redis_cli = redis.Redis(
    host=os.environ.get("OPENSHIFT_REDIS_HOST", "localhost"),
    port=int(os.environ.get("OPENSHIFT_REDIS_PORT", "6379")),
    password=os.environ.get("REDIS_PASSWORD", None),
)
Example #18
0
from flask import Flask
from flaskext.mongoalchemy import MongoAlchemy
from models import SMS, User, Status


app = Flask(__name__)
app.config.from_pyfile("config.py")
app.config["MONGOALCHEMY_DATABASE"] = "smsTest2"
db = MongoAlchemy(app)

import views
import utilities

if __name__ == "__main__":
    app.run()
Example #19
0
File: app.py Project: geekone/pyweb
__author__ = "Administrator"

from flask import Flask
from flaskext.mongoalchemy import MongoAlchemy

app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "library"
db = MongoAlchemy(app)


class Category(db.Document):
    name = db.StringField()


class Item(db.Document):
    content = db.StringField()
    category = db.DocumentField(Category)


@app.route("/")
def index():
    category1 = Category(name="category1")
    item1 = Item(content="item1 title", category=category1)
    category1.save()
    item1.save()
    return "Msg home"


@app.route("/initdata")
def initdata():
    category = Category(name="category1")
from flask import Flask
from flaskext.mongoalchemy import MongoAlchemy
import string

app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "task_collection"
app.config["SECRET_KEY"] = "very secret, do you believe?"
app.config["DEBUG"] = True
db = MongoAlchemy(app)

from views import *
Example #21
0
# -*- coding: utf-8 -*-

# Copyright 2010 flask-mongoalchemy authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from flask import Flask
from flaskext.mongoalchemy import MongoAlchemy
import string

app = Flask(__name__)
app.config["MONGOALCHEMY_DATABASE"] = "books_collection"
app.config["SECRET_KEY"] = "very secret, do you believe?"
app.config["DEBUG"] = True
db = MongoAlchemy(app)


@app.context_processor
def put_letters_on_request():
    return {"letters": string.ascii_uppercase}


from views import *
Example #22
0
log = getLogger()

app = Flask(__name__)
app.debug = True
# Configuracion de app.
app.config["SECRET_KEY"] = "super-secret"
app.config["JWT_REQUIRED_CLAIMS"] = []
app.config["JWT_EXPIRATION_DELTA"] = timedelta(hours=12)
app.config["BUNDLE_ERRORS"] = True
app.config["SEND_EMAILS"] = True

# Configuracion de MongoDB.
url = os.environ.get("MONGOLAB_URI", "mongodb://localhost/enjoy-events")
app.config["MONGOALCHEMY_CONNECTION_STRING"] = url
parsed = urlsplit(url)
app.config["MONGOALCHEMY_DATABASE"] = parsed.path[1:]
db = MongoAlchemy(app)


CORS(app)


errors = {
    "SpecsError": {"message": "This field can't be empty.", "status": 401},
    "ValidationError": {"message": "This field can't be empty.", "status": 402},
    "RestException": {"message": "This field can't be empty.", "status": 400},
}

api = Api(app, version="1.0", title="API", description="Api para el tp de arquitectura", errors=errors)