示例#1
0
文件: app.py 项目: tinanimo/L8pR
def get_app():
    root = os.path.dirname(os.path.realpath(__file__))
    app = Eve(__name__, template_folder='templates', auth=BasicAuth, settings=os.path.join(root, 'settings.py'))
    Environment(app)
    api.register_api(app)

    @app.route('/')
    def index(path=None):
        return render_template('editor.html')

    @app.route('/<username>')
    def player(username):
        user = app.data.driver.db['accounts'].find_one({'username': username})
        loop = app.data.driver.db['loops'].find({'user_id': user['_id']})[0]
        nb_show = str(len(loop['shows']))
        scope = {
            'user': user,
            'nb_show': nb_show
        }
        if request.args.get('show'):
            scope['show'] = app.data.driver.db['shows'].find({'_id': ObjectId(request.args.get('show'))})[0]
        if request.args.get('item'):
            scope['item'] = scope['show']['links'][int(request.args.get('item'))]
        return render_template('player.html', **scope)

    @app.route('/catalog')
    @app.route('/catalog/<path:path>')
    def catalog(path=None):
        return render_template('catalog.html')
    return app
示例#2
0
文件: app.py 项目: thnkloud9/L8pR
def get_app():
    root = os.path.dirname(os.path.realpath(__file__))
    app = Eve(__name__, template_folder='templates', auth=BasicAuth, settings=os.path.join(root, 'settings.py'))
    Environment(app)
    api.register_api(app)

    @app.route('/')
    def index(path=None):
        scope = {
            'GA': app.config.get('GA')
        }
        return render_template('editor.html', **scope)

    @app.route('/<username>')
    def player(username):
        user = app.data.driver.db['accounts'].find_one({'username': username})
        loop = app.data.driver.db['loops'].find({'user_id': user['_id']})[0]
        nb_show = str(len(loop['shows']))
        scope = {
            'user': user,
            'nb_show': nb_show,
            'GA': app.config.get('GA')
        }
        if request.args.get('show'):
            scope['show'] = app.data.driver.db['shows'].find({'_id': ObjectId(request.args.get('show'))})[0]
            if request.args.get('item'):
                def findItem():
                    for link in scope['show']['links']:
                        if link.get('uuid') == request.args.get('item'):
                            return link
                scope['item'] = findItem()
        return render_template('player.html', **scope)

    return app
示例#3
0
def create_app():
    """
    Creates the Flask app. It takes care of everything that is
    necessary in order to run the app; especially to register
    the API and enable the CORS.
    :return:
    """
    app = Flask(__name__)
    CORS(app)
    register_api(app)
    return app
示例#4
0
def init_app(config_file='config.py', is_register_api=True, is_register_view=True):
    app = Flask(__name__)
    app.config.from_pyfile(config_file)
    app.debug = app.config.get('DEBUG', True)

    db.app = app;
    db.init_app(app)

    if is_register_api:
        register_api(app)

    return app
示例#5
0
文件: createapp.py 项目: wyn155/CRM
def create_app():
    app = Flask(__name__)
    app.register_blueprint(search)
    app.config.from_object("config")
    register_api()
    # 连接所有扩展
    app_extend(app)
    with app.app_context():
        db.create_all()


    return app
示例#6
0
from configs.config import LOGGING
from api import register_api
from cli import register_cli
from middlewares import request_logging
from admin import register_admin

# Trick: call app.logger before config app.logger by dictConfig.
app.logger.info("Init flask app ...")
dictConfig(LOGGING)
request_logger = logging.getLogger("api.request")

# Init JWT
jwt = JWTManager(app)

# Init API
register_api(app)

# Allow CORS
CORS(app)

# Register custom CLI
register_cli(app)

# Register middleware
request_logging.register_middleware(app)

# Register admin
register_admin(app)


def log_exception(sender, exception, **extra):
示例#7
0
    print "POST"
    if not session.get('logged_in'):
        abort(401)

    print request.path
    g.db.execute('insert into entries (title, text, type, created) values (?, ?, ?, ?)',
                 [request.form['title'], 
                  request.form['text'], 
                  request.form['type'],
                  datetime.now()])
    g.db.commit()
    flash('New entry was successfully posted')
        return redirect(url_for('show_entries'))

@app.route('/entry/del/<entry_id>', methods=['POST'])
def delete(self, entry_id):
    print "Got DELETE Request %s" % entry_id
    if not session.get('logged_in'):
        abort(401)

    #print request.form.get('entry_id')
    #cur = g.db.execute("delete from entries WHERE id=?", [entry_id])
    #g.db.commit()

    print "Delete succeeded"
    flash('Entry %s was successfully deleted' % entry_id)
    return redirect(url_for('show_entries'))

# Register the View
register_api(EntryAPI, 'entry_api', '/entry/', pk='entry_id')
示例#8
0
from django.conf.urls.defaults import *

from tastypie.api import Api
from api import register_api

v1_api = Api(api_name='v1')
register_api(v1_api)

urlpatterns = patterns('packageindex.views',
    url(r'^api/', include(v1_api.urls)),
    url(r'^p/$', 'application_list', name='packageindex.application_list'),
    url(r'^p/(?P<name>[\.\w\d-]+)/$', 'application_detail', name='packageindex.application_detail'),
    url(r'^p/(?P<name>[\.\w\d-]+)/(?P<title>[\.\w\d-]+)', 'download_package', name='packageindex.download_package'),
    
    url(r'^(?P<access_key>[\w\d]+)/$', 'application_list', name='packageindex.keyed_application_list'),
    url(r'^(?P<access_key>[\w\d]+)/download/(?P<package_id>\d+)/$', 'direct_download_package', name='packageindex.direct_download_package'),
    url(r'^(?P<access_key>[\w\d]+)/(?P<name>[\.\w\d-]+)/$', 'application_detail', name='packageindex.keyed_application_detail'),
    url(r'^(?P<access_key>[\w\d]+)/(?P<name>[\.\w\d-]+)/(?P<title>[\.\w\d-]+)', 'download_package', name='packageindex.keyed_download_package'),
)