本文整理汇总了Python中pylons.controllers.util.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: finish
def finish(self, registration):
from ututi.lib.security import sign_in_user
if not registration.location:
# if there is a university with same title we will use it.
existing = LocationTag.get_by_title(registration.university_title)
if existing is not None:
registration.location = existing
else:
registration.location = registration.create_university()
user = registration.create_user()
bind_group_invitations(user)
# TODO: integrity checks here
meta.Session.add(user)
registration.completed = True
# flush before sending any emails
meta.Session.flush()
process_registration_invitations(registration)
meta.Session.commit()
if user.is_teacher:
teacher_registered_email(user)
sign_in_user(user)
redirect(url(controller='profile', action='register_welcome'))
示例2: after_login
def after_login(self):
if c.account is not None:
h.flash_success(_("Welcome back, %s!") % c.account.name)
redirect("/")
else:
h.flash_error(_("Incorrect user name or password!"))
redirect("/login")
示例3: index
def index(self):
""" Index page
Redirect to prefix list.
"""
redirect(url(controller = 'prefix', action = 'list'))
示例4: set_language
def set_language(self):
"Set the language"
nextpage = request.params.get('next', None)
if not nextpage:
nextpage = request.headers.get('Referer', None)
if not nextpage:
nextpage = '/'
if '://' in nextpage:
from_url = urlparse(nextpage)
nextpage = from_url[2]
lang_code = request.params.get('language', None)
if lang_code and check_language(lang_code):
session['lang'] = lang_code
session.save()
params = []
for param in request.params:
if not param in ['language', 'amp']:
value = request.params[param]
if value:
if (param == 'came_from' and
'://' in urllib2.unquote(value)):
urlparts = urlparse(urllib2.unquote(value))
value = urlparts[2] or '/'
params.append('%s=%s' % (urllib2.quote(param),
urllib2.quote(value)))
if 'lc=1' not in params:
params.append('lc=1')
if params:
nextpage = "%s?%s" % (nextpage, '&'.join(params))
redirect(nextpage)
示例5: doadd
def doadd(self):
soft = Software()
soft.name = self.form_result.get('software_name')
soft.download_url = self.form_result.get('download_url')
Session.add(soft)
Session.commit()
redirect(url(controller="mobile", action="index"))
示例6: loggedout
def loggedout(self):
"Logged out page"
session.clear()
session.save()
came_from = (unquote(str(request.params.get('came_from', '')))
or url('/accounts/login'))
redirect(url(came_from))
示例7: upwchange
def upwchange(self, userid):
"""User change own password"""
user = self._get_user(userid)
if not user:
abort(404)
if user.id != c.user.id or c.user.is_superadmin:
abort(403)
c.form = UserPasswordForm(request.POST, csrf_context=session)
if (request.POST and c.form.validate() and
user.validate_password(c.form.password3.data)):
if user.local:
user.set_password(c.form.password1.data)
Session.add(user)
Session.commit()
flash(_('The account password for %(name)s has been reset')
% dict(name=user.username))
info = PASSWORDCHANGE_MSG % dict(u=user.username)
audit_log(c.user.username,
2, unicode(info), request.host,
request.remote_addr, now())
else:
flash(_('This is an external account, use'
' external system to reset the password'))
redirect(url('account-detail', userid=user.id))
elif (request.POST and not
user.validate_password(c.form.password3.data)
and not c.form.password3.errors):
flash_alert(_('The old password supplied does'
' not match our records'))
c.id = userid
c.username = user.username
c.posturl = 'accounts-pw-uchange'
return render('/accounts/pwchange.html')
示例8: welcome
def welcome(self):
identity = request.environ.get("repoze.who.identity")
came_from = request.params.get('came_from') or "/"
came_from = unquote(came_from)
came_from = unquote(came_from)
came_from = unquote(came_from)
came_from = str(came_from)
if identity:
# Login succeeded
userid = identity['repoze.who.userid']
#user_det = get_mediator_details(userid)
#if user_det['name']:
# session['user_name'] = user_det['name']
#if user_det['uri']:
# session['user_uri'] = str(user_det['uri'])
session['user_id'] = userid
session.save()
return redirect(url(came_from))
else:
# Login failed
try:
login_counter = request.environ['repoze.who.logins'] + 1
except:
login_counter = 0
destination = "/login?came_from=%s&logins=%s" % (came_from, login_counter)
return redirect(url(destination))
示例9: login
def login(self):
# Here below email get parameter may be used for convenience
# i.e. when redirecting from sign-up form.
# POST and GET params are accepted for external javascript logins
# to work via JSONP (see _js_login above).
username = request.params.get('username') or request.params.get('email')
password = request.params.get('password')
location = request.params.get('location')
location = int(location) if location else None
remember = bool(request.params.get('remember'))
if 'js' in request.params:
return self._js_login(username, password, location, remember)
errors = None
if username and password:
# form was posted
errors = self._try_sign_in(username, password, location, remember)
if errors is None:
redirect(c.came_from or url(controller='profile', action='home'))
# show the form, possibly with errors.
return htmlfill.render(render('login.mako'),
errors=errors,
error_formatters=u_error_formatters,
defaults={'username': username,
'location': location,
'came_from': c.came_from})
示例10: matchesLeagues
def matchesLeagues(self):
# Returns a rendered template
user = User()
if user:
RUser = user[0]
if RUser.Permissions[0].bets:
c.user = user[1]
c.current = "manage"
c.managePage = "matches"
RLeagues = db.Session.query(db.Leagues).order_by(db.Leagues.id).limit(10).all()
c.leagues = []
for RLeague in RLeagues:
league = {}
league["id"] = RLeague.id
league["name"] = RLeague.name
league["type"] = RLeague.type
league["region"] = RLeague.region
league["colour"] = RLeague.colour
league["json"] = json.dumps(league)
c.leagues.append(league)
return render('/manage/matches/index.mako')
else:
return redirect('/home/')
else:
return redirect('/home/')
示例11: bots
def bots(self):
user = User()
if user:
RUser = user[0]
if RUser.Permissions[0].bots:
c.current = "manage"
c.managePage = "bots"
c.user = user[1]
c.bots = []
RBots = db.Session.query(db.Bots).order_by(db.Bots.id).limit(10).all()
for RBot in RBots:
bot = {}
bot["id"] = RBot.id
bot["name"] = RBot.name
bot["emailAddress"] = RBot.emailAddress
bot["steamLogin"] = RBot.steamLogin
bot["steamID"] = RBot.steamID
bot["steamAPI"] = RBot.steamAPI
bot["tradeoffers"] = "http://steamcommunity.com/tradeoffer/new/?partner=%d&token=%s" % (int(RBot.steamID) - 76561197960265728, RBot.token)
bot["slots"] = RBot.slots
bot["slotsEmpty"] = RBot.slotsEmpty
bot["backpackAPI"] = RBot.backpackAPI
bot["json"] = json.dumps(bot)
c.bots.append(bot)
return render('/manage/bots.mako')
else:
return redirect("/manage/")
else:
return redirect("/")
示例12: addTeam
def addTeam(self, leagueID):
# Returns a redirection to /manage/teams/{leagueID}
user = User()
if user:
RUser = user[0]
if RUser.Permissions[0].teams:
RTeam = db.Teams(name=request.params["name"], short=request.params["short"], country=request.params["country"], league=leagueID, leagueID=request.params["leagueID"])
db.Session.add(RTeam)
db.Session.commit()
avatar = request.params["avatar"].file
avatar_path = os.path.join('website/public/images/teams', str(RTeam.id) + '.jpg')
temp_path = avatar_path + '~'
output_file = open(temp_path, 'wb')
avatar.seek(0)
while True:
data = avatar.read(2<<16)
if not data:
break
output_file.write(data)
output_file.close()
os.rename(temp_path, avatar_path)
return redirect("/manage/teams/" + leagueID)
else:
return redirect("/")
else:
return redirect("/")
示例13: _vote_save
def _vote_save(self):
post = request.POST
# Fetch POST data
vote = post.get(u'vote')
email = post.get(u'email')
op = post.get(u'op')
attachment = post.get(u'vote-attachment')
comment = post.get(u'vote-comment')
fp = attachment.file if isinstance(attachment, cgi.FieldStorage) else None
attachment_data = fp.read(256).decode('utf-8') if fp else '<None>' # Note: assume plain text utf-8 file
#raise Exception('Inspect POST data')
# Validate request
if not (post.get(secure_form.token_key, None) == secure_form.authentication_token()):
abort (403, detail=u'Not permitted (possible CSRF attack)')
# Validate POST data: in practice we should not abort but rather redirect to the form
# with all the errors highlighted
vote = int(vote)
if not (vote >= 0 and vote <= 10):
abort (400, detail=u'Bad value for vote')
# Done with validation, now just log this and store the (vote,email) in the underlying model
log.info ('Saving vote for poll (%r)' %(dict(vote=vote, email=email, op=op, attachment_data=attachment_data)))
db_session = model.Session()
v = model.Vote (vote=vote, email=email, created_at=None, description=comment);
db_session.add(v)
db_session.commit()
# Done with form processing, redirect to a normal (GET) request ...
h.flash('Your vote is saved!')
redirect (url(controller='poll', action='results'))
return
示例14: forget
def forget(self, id=None):
"""Remove 0 or more Forms from the User's Memory.
If id is None, remove all Forms from Memory;
otherwise, remove Form with provided id."""
if id is None:
user = meta.Session.query(model.User).filter(
model.User.id==session['user_id']).first()
user.rememberedForms = []
meta.Session.commit()
msg = u'All Forms in Memory have been removed.'
else:
form_q = meta.Session.query(model.Form)
form = form_q.get(int(id))
if form is None:
msg = u'There is no Form with ID %s' % id
else:
user = meta.Session.query(model.User).filter(
model.User.id==session['user_id']).first()
if form in user.rememberedForms:
user.rememberedForms.remove(form)
meta.Session.commit()
msg = u'Form %s has been removed from your memory' % id
else:
msg = u'Form %s was never in your memory to begin with!' % id
session['flash'] = msg
session.save()
redirect(url(controller='memory', action='index', id=None))
示例15: switch_language
def switch_language(self, location):
# This is a general language switcher, but is placed here to
# have a separate route for use in external university pages.
language = request.params.get('language', 'en')
# TODO validate
switch_language(language)
redirect(c.came_from or location.url())