Beispiel #1
0
def user_settings():
    if g.user is None or 'openid' not in session:
        return redirect(url_for('login'))
    if request.method == 'POST':
        names = request.form.getlist('script-name')
        scripts = request.form.getlist('script-content')
        data = {x[0]: {'content': x[1]} for x in zip(names, scripts)}
        u = users.get_user_by_openid(g.user.openid)
        defined = set([x for x in u.initscripts.list()])
        for remove in defined - set(names):
            u.initscripts.get(remove).delete()
        for add in set(names) - defined:
            u.initscripts.create(add, data[add])
        for update in set(names) & defined:
            u.initscripts.get(update).update(data[update])
        g.user = users.get(u.name)
        return redirect(url_for('user_settings'))

    u = [users.get(x) for x in users.list()]
    scripts = g.user.to_dict().get('initscripts', [])
    ss = [shared_storage.get(x) for x in shared_storage.list()]
    return render_template('settings.html',
                           settings=settings,
                           users=u,
                           user_scripts=scripts,
                           shared_storage=ss)
Beispiel #2
0
def user_admin():
    if g.user is None or 'openid' not in session:
        return redirect(url_for('login'))
    if not g.user.admin:
        flash('you must be an admin to try and edit users')
        return redirect(url_for('login'))

    for u in users.list():
        u = users.get(u)
        data = {'approved': False, 'admin': False}
        data['approved'] = request.form.get('approved-' + u.openid) == 'on'
        data['admin'] = request.form.get('admin-' + u.openid) == 'on'
        u.update(data)

    return redirect(url_for('user_settings'))
Beispiel #3
0
Datei: ui.py Projekt: doanac/cya
def user_admin():
    if g.user is None or 'openid' not in session:
        return redirect(url_for('login'))
    if not g.user.admin:
        flash('you must be an admin to try and edit users')
        return redirect(url_for('login'))

    for u in users.list():
        u = users.get(u)
        data = {'approved': False, 'admin': False}
        data['approved'] = request.form.get('approved-' + u.openid) == 'on'
        data['admin'] = request.form.get('admin-' + u.openid) == 'on'
        u.update(data)

    return redirect(url_for('user_settings'))
Beispiel #4
0
Datei: ui.py Projekt: doanac/cya
def user_settings():
    if g.user is None or 'openid' not in session:
        return redirect(url_for('login'))
    if request.method == 'POST':
        names = request.form.getlist('script-name')
        scripts = request.form.getlist('script-content')
        data = {x[0]: {'content': x[1]} for x in zip(names, scripts)}
        u = users.get_user_by_openid(g.user.openid)
        defined = set([x for x in u.initscripts.list()])
        for remove in defined - set(names):
            u.initscripts.get(remove).delete()
        for add in set(names) - defined:
            u.initscripts.create(add, data[add])
        for update in set(names) & defined:
            u.initscripts.get(update).update(data[update])
        g.user = users.get(u.name)
        return redirect(url_for('user_settings'))

    u = [users.get(x) for x in users.list()]
    scripts = g.user.to_dict().get('initscripts', [])
    ss = [shared_storage.get(x) for x in shared_storage.list()]
    return render_template(
        'settings.html', settings=settings, users=u, user_scripts=scripts,
        shared_storage=ss)