本文整理汇总了Python中shinken.webui.bottle.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_user
def post_user():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/user/login")
return
# Take the user that send the post and not the
# form value for secutiry reason of course :)
username = user.get('username')
email = app.request.forms.get('email')
password = app.request.forms.get('password')
password2 = app.request.forms.get('password2')
password_hash = None
if password:
password_hash = hashlib.sha512(password).hexdigest()
if password != password2:
abort(400, 'Wrong password')
print "Get a user %s update with email %s and hash %s" % (username, email, password_hash)
app.update_user(username, password_hash, email)
return
示例2: do_register
def do_register():
username = app.request.forms.get("username")
email = app.request.forms.get("email")
password = app.request.forms.get("password")
password_hash = hashlib.sha512(password).hexdigest()
cli_mode = app.request.forms.get("cli_mode", "0")
print "Get a new user %s with email %s and hash %s" % (username, email, password_hash)
if not app.is_name_available(username):
if cli_mode == "1":
app.response.content_type = "application/json"
return json.dumps({"state": 400, "text": "Sorry, this username is not available"})
redirect("/register?error=Sorry, this username is not available")
app.register_user(username, password_hash, email)
if cli_mode == "1":
app.response.content_type = "application/json"
return json.dumps(
{
"state": 200,
"text": "Registering success, please look at your email and click in the link in it to validate your account",
}
)
redirect(
"/register?success=Registering success, please look at your email and click in the link in it to validate your account"
)
示例3: get_launch
def get_launch():
user = app.get_user_auth()
if not user:
redirect("/user/login")
print "Got forms in /newhosts/launch page"
names = app.request.forms.get('names', '')
runners = []
for (k,v) in app.request.forms.iteritems():
print "DUMP OF K, V FOR LAUNCH", k, v
print k.startswith('enable-runner-')
if k.startswith('enable-runner-'):
r_name = k[len('enable-runner-'):]
print "NAME", r_name, v, to_bool(v)
if to_bool(v):
runners.append(r_name)
print "Selected runners", runners
print "Got in request form"
print names
# We are putting a ask ask in the database
i = random.randint(1, 65535)
scan_ask = {'_id': i, 'names': names, 'runners': runners, 'state': 'pending', 'creation': int(time.time())}
print "Saving", scan_ask, "in", app.db.scans
r = app.db.scans.save(scan_ask)
# We just want the id as string, not the object
print "We create the scan", i
app.ask_new_scan(i)
return {'app': app, 'user': user}
示例4: get_last_errors_widget
def get_last_errors_widget():
user = app.get_user_auth()
if not user:
redirect("/user/login")
# We want to limit the number of elements, The user will be able to increase it
nb_elements = max(0, int(app.request.GET.get("nb_elements", "10")))
pbs = app.datamgr.get_problems_time_sorted()
# Filter with the user interests
pbs = only_related_to(pbs, user)
# Keep only nb_elements
pbs = pbs[:nb_elements]
wid = app.request.GET.get("wid", "widget_last_problems_" + str(int(time.time())))
collapsed = app.request.GET.get("collapsed", "False") == "True"
options = {"nb_elements": {"value": nb_elements, "type": "int", "label": "Max number of elements to show"}}
title = "Last IT problems"
return {
"app": app,
"pbs": pbs,
"user": user,
"page": "problems",
"wid": wid,
"collapsed": collapsed,
"options": options,
"base_url": "/widget/last_problems",
"title": title,
}
示例5: get_page
def get_page(username):
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/user/login")
return
#uname = user.get('username')
view_user = app.get_user_by_name(username)
cur = app.db.packs.find({'user': username, 'state': 'ok'})
validated_packs = [p for p in cur]
# Only show pending and refused packs if YOU are the user
pending_packs = []
refused_packs = []
if user == view_user:
cur = app.db.packs.find({'user': username, 'state': 'pending'})
pending_packs = [p for p in cur]
cur = app.db.packs.find({'user': username, 'state': 'refused'})
refused_packs = [p for p in cur]
return {'app': app, 'user': user, 'view_user': view_user, 'validated_packs': validated_packs, 'pending_packs': pending_packs,
'refused_packs': refused_packs}
示例6: get_page
def get_page():
# First we look for the user sid
# so we bail out if it's a false one
# sid = app.request.get_cookie("sid")
user = app.get_user_auth()
if not user:
redirect("/user/login")
# return {'app' : app, 'pbs' : [], 'valid_user' : False, 'user' : None, 'navi' : None}
#We want to limit the number of elements
start = int(app.request.GET.get('start', '0'))
end = int(app.request.GET.get('end', '30'))
search = app.request.GET.get('search', '')
pbs = app.datamgr.get_all_problems()
# Filter with the user interests
pbs = only_related_to(pbs, user)
# Ok, if need, appli the search filter
if search:
print "SEARCHING FOR", search
print "Before filtering", len(pbs)
# We compile the patern
pat = re.compile(search, re.IGNORECASE)
new_pbs = []
for p in pbs:
if pat.search(p.get_full_name()):
new_pbs.append(p)
continue
to_add = False
for imp in p.impacts:
if pat.search(imp.get_full_name()):
to_add = True
for src in p.source_problems:
if pat.search(src.get_full_name()):
to_add = True
if to_add:
new_pbs.append(p)
pbs = new_pbs
print "After filtering", len(pbs)
total = len(pbs)
# If we overflow, came back as normal
if start > total:
start = 0
end = 30
navi = app.helper.get_navi(total, start, step=30)
pbs = pbs[start:end]
# print "get all problems:", pbs
# for pb in pbs :
# print pb.get_name()
return {'app' : app, 'pbs' : pbs, 'valid_user' : True, 'user' : user, 'navi' : navi, 'search' : search, 'page' : 'problems'}
示例7: get_graphs_widget
def get_graphs_widget():
user = app.get_user_auth()
if not user:
redirect("/user/login")
search = app.request.GET.get('search', '')
if not search:
search = 'localhost'
# Look for an host or a service?
elt = None
if not '/' in search:
elt = app.datamgr.get_host(search)
else:
parts = search.split('/', 1)
elt = app.datamgr.get_service(parts[0], parts[1])
wid = app.request.GET.get('wid', 'widget_graphs_'+str(int(time.time())))
collapsed = (app.request.GET.get('collapsed', 'False') == 'True')
options = {'search' : {'value' : search, 'type' : 'hst_srv', 'label' : 'Element name'},}
title = 'Element graphs for %s' % search
return {'app' : app, 'elt' : elt, 'user' : user,
'wid' : wid, 'collapsed' : collapsed, 'options' : options, 'base_url' : '/widget/graphs', 'title' : title,
}
示例8: impacts
def impacts():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/mobile/")
return
# We want to limit the number of elements
start = int(app.request.GET.get('start', '0'))
end = int(app.request.GET.get('end', '5'))
all_imp_impacts = app.datamgr.get_important_elements()
all_imp_impacts.sort(worse_first)
total = len(all_imp_impacts)
# If we overflow, came back as normal
if start > total:
start = 0
end = 5
navi = app.helper.get_navi(total, start, step=5)
all_imp_impacts = all_imp_impacts[start:end]
return {'app' : app, 'user' : user, 'navi' : navi, 'impacts' : all_imp_impacts}
示例9: problems
def problems():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/mobile/")
return
# We want to limit the number of elements
start = int(app.request.GET.get('start', '0'))
end = int(app.request.GET.get('end', '5'))
all_pbs = app.datamgr.get_all_problems()
# Now sort it!
all_pbs.sort(hst_srv_sort)
total = len(all_pbs)
# If we overflow, came back as normal
if start > total:
start = 0
end = 5
navi = app.helper.get_navi(total, start, step=5)
all_pbs = all_pbs[start:end]
return {'app' : app, 'user' : user, 'navi' : navi, 'problems' : all_pbs, 'menu_part' : '/problems'}
示例10: get_page
def get_page():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/user/login")
all_imp_impacts = app.datamgr.get_important_elements()
all_imp_impacts.sort(hst_srv_sort)
# all_imp_impacts.sort(hst_srv_sort)
# all_imp_impacts = app.datamgr.get_services()#important_elements()
impacts = all_imp_impacts
# for imp in all_imp_impacts:
# safe_print("FIND A BAD SERVICE IN IMPACTS", imp.get_dbg_name())
# d = {'name' : imp.get_full_name().encode('utf8', 'ignore'),
# "title": "My Image 3", "thumb": "/static/images/state_flapping.png", "zoom": "/static/images/state_flapping.png",
# "html" : get_div(imp)}
# impacts.append(d)
# Got in json format
# j_impacts = json.dumps(impacts)
# print "Return impact in json", j_impacts
all_pbs = app.datamgr.get_all_problems()
now = time.time()
# Get only the last 10min errors
all_pbs = [pb for pb in all_pbs if pb.last_state_change > now - 600]
# And sort it
all_pbs.sort(hst_srv_sort) # sort_by_last_state_change)
return {"app": app, "user": user, "impacts": impacts, "problems": all_pbs}
示例11: eue_widget
def eue_widget():
user = app.get_user_auth()
if not user:
redirect("/user/login")
wid = app.request.GET.get('wid', 'widget_system_' + str(int(time.time())))
collapsed = (app.request.GET.get('collapsed', 'False') == 'True')
got_childs = (app.request.GET.get('got_childs', 'False') == 'True')
key = app.request.GET.get('key', 1)
options = {}
problems = {}
message,db = getdb('shinken')
if not db:
return {
'app': app, 'user': user, 'wid': wid,
'collapsed': collapsed, 'options': options,
'base_url': '/widget/eue', 'title': 'Eue problems',
'problems':problems
}
return {'app': app, 'user': user, 'wid': wid,
'collapsed': collapsed, 'options': options,
'base_url': '/widget/eue', 'title': 'Eue problems',
'problems':problems
}
示例12: get_page
def get_page():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/user/login")
all_imp_impacts = app.datamgr.get_services()#important_elements()
#all_imp_impacts.sort(hst_srv_sort)
impacts = []
for imp in all_imp_impacts:
safe_print("FIND A BAD SERVICE IN IMPACTS", imp.get_dbg_name())
d = {'name' : imp.get_full_name().encode('utf8', 'ignore'),
"title": "My Image 3", "thumb": "/static/images/state_flapping.png", "zoom": "/static/images/state_flapping.png",
"html" : get_div(imp)}
impacts.append(d)
# Got in json format
#j_impacts = json.dumps(impacts)
# print "Return impact in json", j_impacts
return {'app' : app, 'user' : user, 'impacts' : impacts}
示例13: system_widget
def system_widget():
user = app.get_user_auth()
if not user:
redirect("/user/login")
schedulers = app.datamgr.get_schedulers()
brokers = app.datamgr.get_brokers()
reactionners = app.datamgr.get_reactionners()
receivers = app.datamgr.get_receivers()
pollers = app.datamgr.get_pollers()
wid = app.request.GET.get('wid', 'widget_system_' + str(int(time.time())))
collapsed = (app.request.GET.get('collapsed', 'False') == 'True')
print "SYSTEM COLLAPSED?", collapsed, type(collapsed)
got_childs = (app.request.GET.get('got_childs', 'False') == 'True')
key = app.request.GET.get('key', 1)
options = {}
return {'app': app, 'user': user, 'wid': wid,
'collapsed': collapsed, 'options': options,
'base_url': '/widget/system', 'title': 'System Information',
'schedulers': schedulers,
'brokers': brokers, 'reactionners': reactionners,
'receivers': receivers, 'pollers': pollers,
}
示例14: elements_generic
def elements_generic(cls, show_tpls=False):
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
if not user:
redirect("/user/login")
# Get all entries from db
#t = getattr(app.db, cls.my_type+'s')
#cur = t.find({})
#elts = [cls(i) for i in cur]
print "GENERIC", cls.my_type
t = cls.my_type + 's'
key = keys[t]
#if cls.my_type == 'host':
# print "HOOK HOSTS"
elts = [cls(i) for i in app.datamgr.get_generics(t, key)]
print "GOT elements", elts
# Look for removing or keeping templates
if not show_tpls:
print "REMOVING TEMPLATES"
elts = [e for e in elts if not e.is_tpl()]
return {'app': app, 'user': user, 'elts': elts, 'elt_type': cls.my_type}
示例15: checkauth
def checkauth():
user = app.get_user_auth()
if not user:
redirect("/user/login")
else:
return user