예제 #1
0
from bottle import app as bottleapp
from bottle import run, route, request, template, static_file, abort
from beaker.middleware import SessionMiddleware
from json import dumps
from random import randint

beaker_opts = {
    'session.type': 'file',
    'session.data_dir': '.',
    'session.auto': True
}

app = SessionMiddleware(bottleapp(), beaker_opts)

@route('/assets/<filename:path>')
def assets(filename):
    return static_file(filename, root='./assets/')

@route('/')
def index():
    s = request.environ['beaker.session']

    s['count'] = 0
    s['num'] = randint(1, 100)
    s['num'] = 87
    s.save()

    return template('index.html', locals())

@route('/get/<num:int>')
def get(num):
예제 #2
0
@route('/list')
def objlist():
    try:
        dbobj = list(col.find({}))  # page separation TBD
    except:
        dbobj = []
    return template("list.html", locals())


@route('/delete')
@route('/delete', method="POST")
def delete():
    if request.method == "POST":
        objid = int(request.POST['id'])

        if col.find_one_and_delete({'id': objid}):
            return "success"
        else:
            abort(text="該遺失物不存在!請重新輸入")
    else:
        return template("delete.html")


@route('/')
def index():
    return template('index.html', locals())


run(app=bottleapp(), port=8787, debug=True, reloader=True, server='meinheld')
예제 #3
0
파일: app.py 프로젝트: pcchou/plant-rank
@route('/assets/<filename:path>')
def assets(filename):
    return static_file(filename, root='./assets/')

@route('/')
def index():
    board = list(map(readable, col.find({})))
    countboard = sorted(board, key=lambda x: (x['points'], x['rate']), reverse=True)
    algocountboard = sorted(board, key=lambda x: (x['algopoints'], x['points']),
                            reverse=True)
    algoboard = sorted(board, key=lambda x: (x['rate'] if x['category'] == 1 else 0,
                                             x['points']),
                       reverse=True)
    return template('index.html', locals())

@route('/users/<uid>')
def user(uid):
    board = map(readable, col.find({'uid': int(uid)}).limit(1))
    return template('user.html', locals())

@route('/users/<uid>', method="POST")
def refresh(uid):
    try:
        sprout.refresh(int(uid))
    except:
        return dumps({'status': False})
    else:
        return dumps({'status': True})

run(app=bottleapp(), port=8787, host="127.0.0.1", debug=False, server='meinheld')