@view_config(renderer="ban.mak", route_name="ban")
def ban(request):
    r = request
    s = request.session
    p = s['safe_post']

    if 'logged_in_admin' not in s or s['logged_in_admin'] == False:
        return HTTPNotFound()

    if p in 'ip':
        if p['ip'].strip() == '':
            ip = None
        else:
            ip = p['ip']

        if p['username'].strip() == '':
            username = None
            user_id = None
        else:
            username = p['username']

        if p['duration'].strip() == 'infinite':
            duration = None
        else:
            duration = "timedelta({0})".format(p['duration'])
            duration = eval(duration)

        if username:
            user_id = users.get_user_by_name(username).id

        b = Ban(ip = ip, username = username, duration = duration, user_id = user_id, added_by = s['users.id'])
        dbsession = DBSession()
        dbsession.add(b)

    bans = general.list_bans()
    return {'bans': bans}
dataset/ETHPy150Open sjuxax/raggregate/raggregate/views/user.py/ban/swapped operands of `in`