def GET(self):
session.user = None
del session.user
return web.seeother("/")
#-----------------------------------------------------------------------
python类seeother()的实例源码
def __init__(self, url, absolute=False):
status = '303 See Other'
newloc = url
home = web.ctx.environ['HTTP_ORIGIN']
newloc = urlparse.urljoin(home, url)
logger.info('seeother: %s', newloc)
headers = {
'Content-Type': 'text/html',
'Location': newloc
}
web.webapi.HTTPError.__init__(self, status, headers, "")
pass
def GET(self, account):
""" get account information for given account name.
HTTP Success:
200 OK
HTTP Error:
401 Unauthorized
404 Not Found
500 InternalError
:param Rucio-Account: Account identifier.
:param Rucio-Auth-Token: as an 32 character hex string.
:returns: JSON dict containing informations about the requested user.
"""
header('Content-Type', 'application/json')
if account == 'whoami':
# Redirect to the account uri
frontend = ctx.env.get('HTTP_X_REQUESTED_HOST')
if frontend:
raise redirect(frontend + "/accounts/%s" % (ctx.env.get('issuer')))
raise seeother(ctx.env.get('issuer'))
acc = None
try:
acc = get_account_info(account)
except AccountNotFound, e:
raise generate_http_error(404, 'AccountNotFound', e.args[0][0])
except AccessDenied, e:
raise generate_http_error(401, 'AccessDenied', e.args[0][0])
except RucioException, e:
raise generate_http_error(500, e.__class__.__name__, e.args[0][0])
except Exception, e:
print format_exc()
raise InternalError(e)
dict = acc.to_dict()
for key, value in dict.items():
if isinstance(value, datetime):
dict[key] = value.strftime('%Y-%m-%dT%H:%M:%S')
del dict['_sa_instance_state']
return render_json(**dict)
def GET(self, app = None):
usestale = True
# Until dedicated main homepage is done
if not app:
app = random.choice(valid_modes)
app = models.app_aliases.get(app, app)
query = web.input()
user = query.get("user")
# TODO: Won't be much use in the big restructuring, for now try to extract app from path
appfrom = query.get("from", '')[len(markup.virtual_root):].strip('/').split('/')[0]
if appfrom not in valid_modes:
appfrom = valid_modes[0]
profile = profile_search(user)
if profile:
raise web.seeother(markup.generate_root_url("user/" + str(profile[0]["id64"]), appfrom))
ckey = "scrender"
showcase = models.cache.get(ckey)
showcase_cell = None
try:
if not showcase:
sitems = models.schema(scope = app).processed_items.values()
if len(sitems) > 0:
showcase = random.choice(sitems)
showcase["app"] = app
# May want to add an option for showcase expiration to config later
models.cache.set(ckey, showcase, time=60)
app = showcase.get("app", app)
showcase_cell = markup.generate_item_cell(app, showcase, user=showcase.get("user"))
except Exception as E:
pass
markup.init_theme(app)
web.ctx.notopsearch = True
# Last packs
packs = models.recent_inventories(scope = app)
return template.index(app, (packs or []), showcase_cell)