Exemplo n.º 1
0
def setup_app(**kwargs):
    global app, api, admin, assets

    app = Application(**kwargs)
    app.debug = True

    #TODO: Set secret dynamically
    app.secret_key = '29adsnlzh0e20asdf289'

    # Flask-Assets
    assets = flask.ext.assets.Environment(app)

    assets.manifest = 'json:.webassets-manifest.json'

    if 'STATIC_HOST' in app.config:
        assets.config['url'] = app.config['STATIC_HOST']
    if app.debug:
        assets.cache = False

# TODO: Get rid of this hacked less compiler
#    import sendtask.bootstrap_less

# TOOD add new jquery version
    js_files = [
        'lib/jquery/jquery-1.8.1.min.js',
        'lib/ddslick/jquery.ddslick.min.js',
        'lib/jquery/jquery.validate.js',
        'js/core.js',
        'lib/retina/retina.js',
    ]

    if app.config.get('LESSC_AVAILABLE', False) and not app.config.TESTING:
        assets.register('all_css',
                        'style/style.less',
                        filters=['bootstrap_less', 'yui_css'],
                        output='style/style.css')
    else:
        assets.register('all_css',
                        'style/style_compiled.css',
                        filters=['yui_css'],
                        output='style/style.css')

    assets.register('all_js',
                    *js_files,
                    filters=['yui_js'],
                    output='js/all.js')
    app.assets = assets

    # Override the template context {{ url_for }} function.
    #    @app.context_processor
    #    def override_url_for():
    #        return dict(url_for=cdn_url_for)

    # MongoRest
    api = MongoRest(app, url_prefix='/api/v1')

    # Admin
    admin = Admin(app=app, url='/admin')

    # Error emails
    #   if not app.debug:
    #       import logging
    #       #from logging.handlers import SMTPHandler
    #
    #       mail_handler = SMTPHandler((config['MAIL_SERVER'], config['MAIL_PORT']),
    #                                  config['SERVER_EMAIL'],
    #                                  config['ADMINS'],
    #                                  'Server error',
    #                                  (config['MAIL_USERNAME'], config['MAIL_PASSWORD']),
    #                                  secure=config['MAIL_USE_TLS'] and ())
    #       mail_handler.setLevel(logging.ERROR)
    #       app.logger.addHandler(mail_handler)

    #       mail_handler.setFormatter(logging.Formatter('''\
    #           Message type:       %(levelname)s
    #           Location:           %(pathname)s:%(lineno)d
    #           Module:             %(module)s
    #           Function:           %(funcName)s
    #           Time:               %(asctime)s
    #
    #           Message:
    #
    #           %(message)s
    #       '''))

    from jknavigator import resources

    @app.route('/')
    def homepage():
        context = {}
        return render_template('base.html', **context)

    return app
Exemplo n.º 2
0

app = Flask(__name__)

MONGOLAB_URI = os.environ.get("MONGOLAB_URI")
if MONGOLAB_URI is None:
    app.config.update(
        MONGODB_HOST='localhost',
        MONGODB_PORT='27017',
        MONGODB_DB='atlas-tb',
    )
else:
    app.config.update(MONGOLAB_URI=MONGOLAB_URI)

db = MongoEngine(app)
api = MongoRest(app)


class ReferenceSetResource(Resource):
    document = ReferenceSet


class ReferenceResource(Resource):
    document = Reference
    related_resources = {
        'reference_sets': ReferenceSetResource,
    }


class VariantSetResource(Resource):
    document = VariantSet
Exemplo n.º 3
0
app.url_map.strict_slashes = False

app.config.update(
    DEBUG = True,
    TESTING = True,
    MONGODB_SETTINGS = {
        'HOST': 'localhost',
        'PORT': 27017,
        'DB': 'mongorest_example_app',
        'TZ_AWARE': True,
    },
)

db = MongoEngine()
api = MongoRest()

class UserResource(Resource):
    document = documents.User
    schema = schemas.User
    filters = {
        'datetime': [ops.Exact]
    }

@api.register()
class UserView(ResourceView):
    resource = UserResource
    methods = [Create, Update, Fetch, List, Delete]

class ContentResource(Resource):
    document = documents.Content