@app.route("/user/", defaults={'username': None})
@app.route("/user/<username>", methods=['GET', 'POST', 'DELETE'])
@login_required
def users(username):
    if not username:
        if request.method == 'DELETE':
            abort(400)  # don't allow deletes with out user
        if session.get('username', False):
            username = session.get('username')
        else:
            abort(400)
    if request.method == 'GET':
        q = list(r.table("users").filter({"username": username}).without("hash").run(rdb.conn))[0]
        if q:
            if 'theme' not in q:
                q['theme'] = 'cerulean'
            return jsonify(q)
        else:
            abort(404)
    elif request.method == 'DELETE':
        return jsonify({'success': remove_user(username)})
    elif request.method == 'POST':
        fields = {}
        if not request.json:
            abort(400)
        if 'theme' in request.json:
            if request.json['theme'] in app.config['THEMES']:
                fields['theme'] = request.json['theme']
            else:
                abort(400)
        if 'email' in request.json:
            fields['email'] = request.json['email']
        q = r.table("users").filter({"username": username}).update(fields).run(rdb.conn) 
        if q["replaced"] != 0 :
            if session and 'theme' in fields:
                session['theme'] = fields['theme']
            return jsonify({'success': True})
        else:
            return jsonify({'success': False})
dataset/ETHPy150Open pandemicsyn/stalker/stalkerweb/stalkerweb/views.py/users/original