def add_user(user):
"""Trace back the user's repositories to their origins.
Submit all found organizations.
"""
redirect("/organization/" + user)
python类redirect()的实例源码
def get_user(user, ending):
"""Return the status of this github user.
- what are the first-timer repositories?
"""
redirect("/organization/" + user + "." + ending)
def get_all_users(ending):
"""All the users and their statuses."""
redirect("/organizations." + ending)
def get_source_redirect():
"""Get the source code as a zip file."""
redirect(ZIP_PATH)
def slashify():
bottle.redirect(bottle.request.path + "/", 301)
def enter():
"""
??????????
????????cookie??????????????????????
:return:
"""
# POST??????
username = request.POST.get("username")
print("POST username is ", username)
# cookie????
response.set_cookie("username", username)
return redirect("/chat_room")
def get_load_apps():
root.load_apps()
redirect('/myapps')
def removeapp():
user = root.authorized()
uid = users(user=user).id
app = request.forms.app
appid = apps(name=app).id
auid = app_user(uid=uid, appid=appid).id
del app_user[auid]
print "removing user", user, uid, "access to app", app, appid
db.commit()
redirect('/myapps')
def post_login():
if not config.auth:
return "ERROR: authorization disabled. Change auth setting in config.py to enable"
s = request.environ.get('beaker.session')
row = users(user=request.forms.get('user').lower())
pw = request.forms.passwd
err = "<p>Login failed: wrong username or password</p>"
# if password matches, set the USER_ID_SESSION_KEY
hashpw = hashlib.sha256(pw).hexdigest()
try:
if hashpw == row.passwd:
# set session key
s[USER_ID_SESSION_KEY] = row.user.lower()
s.save()
else:
return err
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
print traceback.print_exception(exc_type, exc_value, exc_traceback)
return err
# if referred to login from another page redirect to referring page
referrer = request.forms.referrer
if referrer: redirect('/'+referrer)
else: redirect('/myapps')
def logout():
s = request.environ.get('beaker.session')
s.delete()
try:
return template('logout', {'oauth_client_id': config.oauth_client_id})
except:
redirect('/login')
def create_container(id):
print "creating container:", id
cli = docker.Client(base_url=base_url)
host_port_number = int(request.forms.host_port_number)
container_port_number = int(request.forms.container_port_number)
try:
cli.create_container(image=id, ports=[host_port_number], host_config=cli.create_host_config(port_bindings={host_port_number:container_port_number}))
alert = "SUCCESS: container created " + id
except Exception as e:
alert = "ERROR: failed to start container " + str(e)
redirect("/docker?alert="+alert)
# don't think we want to have this option
# @dockerMod.route('/docker/remove_image/<id:path>', method='GET')
# def remove_image(id):
# print "removing image:", id
# cli = docker.Client(base_url=base_url)
# try:
# msg = cli.remove_image(image=id)
# alert = "SUCCESS: image removed " + id
# except:
# alert = "ERROR: unable to remove image " + id + \
# " Either has dependent child images, or a container is running." + \
# " Remove the container and retry."
# redirect("/docker?alert="+alert)
def start_container(id):
print "starting container:", id
cli = docker.Client(base_url=base_url)
try:
cli.start(container=id)
alert = "SUCCESS: started container " + id
except:
alert = "ERROR: failed to start container " + id
redirect("/docker?alert="+alert)
def stop_container(id):
cli = docker.Client(base_url=base_url)
try:
cli.stop(container=id)
alert = "SUCCESS: stopped container " + id
except:
alert = "ERROR stopping container " + id
redirect("/docker?alert="+alert)
def remove_container(id):
print "removing container:", id
cli = docker.Client(base_url=base_url)
try:
cli.remove_container(id)
alert = "SUCCESS: removed container " + id
except:
alert = "ERROR: problem removing container " + id
redirect("/docker?alert="+alert)
def star_case():
root.authorized()
jid = request.forms.jid
jobs(id=jid).update_record(starred="True")
db.commit()
redirect('/jobs')
def unstar_case():
root.authorized()
jid = request.forms.jid
jobs(id=jid).update_record(starred="False")
db.commit()
redirect('/jobs')
def share_case():
root.authorized()
jid = request.forms.jid
jobs(id=jid).update_record(shared="True")
db.commit()
# increase count in database for every user
for u in db().select(users.ALL):
nmsg = users(user=u.user).new_shared_jobs or 0
users(user=u.user).update_record(new_shared_jobs=nmsg+1)
db.commit()
redirect('/jobs')
def unshare_case():
root.authorized()
jid = request.forms.jid
jobs(id=jid).update_record(shared="False")
db.commit()
redirect('/jobs')
def stop_job():
root.authorized()
app = request.forms.app
cid = request.forms.cid
jid = request.forms.jid
if re.search("/", cid):
return template("error", err="only possible to stop cases that you own")
root.sched.stop(jid)
time.sleep(0.1)
jobs(jid).update_record(state="X")
db.commit()
redirect("/case?app="+app+"&cid="+cid+"&jid="+jid)
def editplotdefs():
user = root.authorized()
if user != 'admin':
return template('error', err="must be admin to edit plots")
app = request.query.app
if config.auth and not root.authorized(): redirect('/login')
if app not in root.myapps: redirect('/apps')
query = (root.apps.id==plots.appid) & (root.apps.name==app)
result = db(query).select()
params = { 'app': app, 'user': user }
return template('plots/plotdefs', params, rows=result)