Esempio n. 1
0
def admin():
    # convert to dict
    user = dict((name, convert.to_dict(y)) for name, y in API.get_all_user_data().iteritems())
    perms = permlist()

    for data in user.itervalues():
        data['perms'] = {}
        get_permission(data['perms'], data['permission'])
        data['perms']['admin'] = data['role'] is 0

    s = bottle.request.environ.get('beaker.session')
    if bottle.request.environ.get('REQUEST_METHOD', "GET") == "POST":
        for name in user:
            if bottle.request.POST.get("%s|admin" % name, False):
                user[name]['role'] = 0
                user[name]['perms']['admin'] = True
            elif name != s['name']:
                user[name]['role'] = 1
                user[name]['perms']['admin'] = False

            # set all perms to false
            for perm in perms:
                user[name]['perms'][perm] = False

            for perm in bottle.request.POST.getall("%s|perms" % name):
                user[name]['perms'][perm] = True

            user[name]['permission'] = set_permission(user[name]['perms'])

            API.set_user_permission(name, user[name]['permission'], user[name]['role'])

    return render_to_response("admin.html", {"users": user, "permlist": perms}, [pre_processor])
Esempio n. 2
0
def home():
    try:
        res = [convert.to_dict(x) for x in API.status_downloads()]
    except Exception:
        s = bottle.request.environ.get('beaker.session')
        s.delete()
        return bottle.redirect("/login")

    for link in res:
        if link['status'] == 12:
            link['information'] = "%s kB @ %s kB/s" % (link['size'] - link['bleft'], link['speed'])

    return render_to_response("home.html", {"res": res}, [pre_processor])