• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.redirect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pylons.controllers.util.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了redirect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'))
开发者ID:nous-consulting,项目名称:ututi,代码行数:28,代码来源:registration.py


示例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")
开发者ID:asuffield,项目名称:openspending,代码行数:7,代码来源:account.py


示例3: index

    def index(self):
        """ Index page

            Redirect to prefix list.
        """

        redirect(url(controller = 'prefix', action = 'list'))
开发者ID:Dhyrule,项目名称:NIPAP,代码行数:7,代码来源:prefix.py


示例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)
开发者ID:TetraAsh,项目名称:baruwa2,代码行数:30,代码来源:accounts.py


示例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"))
开发者ID:feilaoda,项目名称:kd,代码行数:7,代码来源:mobile.py


示例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))
开发者ID:TetraAsh,项目名称:baruwa2,代码行数:7,代码来源:accounts.py


示例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')
开发者ID:TetraAsh,项目名称:baruwa2,代码行数:33,代码来源:accounts.py


示例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))
开发者ID:benosteen,项目名称:RDFDatabank,代码行数:26,代码来源:account.py


示例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})
开发者ID:nous-consulting,项目名称:ututi,代码行数:29,代码来源:home.py


示例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/')
开发者ID:Ethanlord300,项目名称:Saloon.tf,代码行数:27,代码来源:manage.py


示例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("/")
开发者ID:Ethanlord300,项目名称:Saloon.tf,代码行数:32,代码来源:manage.py


示例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("/")
开发者ID:Ethanlord300,项目名称:Saloon.tf,代码行数:27,代码来源:manage.py


示例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
开发者ID:drmalex07,项目名称:pylons-helloworld,代码行数:34,代码来源:poll.py


示例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))
开发者ID:jrwdunham,项目名称:old-webapp,代码行数:28,代码来源:memory.py


示例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())
开发者ID:nous-consulting,项目名称:ututi,代码行数:7,代码来源:location.py


示例16: register

    def register(self):
        name = request.POST.get('name')
        email = request.POST.get('email')
        location_id = request.POST.get('location_id')
        accept_terms = request.POST.get('accept_terms')
        person = request.POST.get('person')

        c.universities = self._universities(limit=12)
        c.all_universities = self._universities()

        # checks if email, name, person are not empty
        if not email or not name or not person or accept_terms != '1':
            redirect(url('frontpage'))

        # redirect to login if user is already registered
        if User.get_all(email):
            redirect(url(controller='home', action='login', email=email))

        # otherwise we validate the form properly
        try:
            self.form_result = RegistrationForm().to_python(request.POST)
        except validators.Invalid, e:
            return htmlfill.render(self._sign_up_form(),
                                   defaults=request.POST,
                                   errors=e.error_dict,
                                   error_formatters=u_error_formatters)
开发者ID:nous-consulting,项目名称:ututi,代码行数:26,代码来源:home.py


示例17: login

    def login(self):
        "login"
        if request.remote_addr in session:
            if session[request.remote_addr] > now():
                abort(409, _('You have been banned after'
                            ' several failed logins'))
            else:
                del session[request.remote_addr]
                session.save()

        identity = request.environ.get('repoze.who.identity')
        came_from = unquote(str(request.GET.get('came_from', '')))
        if not came_from or ' ' in came_from:
            came_from = url('home')
        if '://' in came_from:
            from_url = urlparse(came_from)
            came_from = from_url[2]

        if identity:
            redirect(url(came_from))
        else:
            c.came_from = came_from
            c.login_counter = request.environ['repoze.who.logins']
            if c.login_counter >= 3:
                ban_until = now() + timedelta(minutes=5)
                if request.remote_addr not in session:
                    session[request.remote_addr] = ban_until
                    session.save()
                else:
                    if now() > session[request.remote_addr]:
                        del session[request.remote_addr]
                        session.save()
            c.form = ResetPwForm(request.POST, csrf_context=session)
            return render('/accounts/login.html')
开发者ID:TetraAsh,项目名称:baruwa2,代码行数:34,代码来源:accounts.py


示例18: checkid_submit

    def checkid_submit(self):
        '''
        This is called when the user accepts - hit the submit button - that he will login to the consumer
        '''
        param = request.params
        log.debug("[checkid_submit] params: %s" % param)
        redirect_token = getParam(param, "redirect_token", required)
        verify_always = getParam(param, "verify_always", optional)
        r_url, site, handle = self.storage.get_redirect(redirect_token)
        self.storage.add_site(site, handle)

        # The user checked the box, that he wants not be bothered again in the future
        # the relying party will be added to the trusted root
        login, token = self._split_cookie()
        user = self.storage.get_user_by_token(token)
        c.audit['user'], c.audit['realm'] = user.split('@', 2)
        c.audit['success'] = True
        c.audit['action_detail'] = site

        if "always" == verify_always:
            log.debug("[checkid_submit] putting into trusted root: %s, %s" % (site, handle))
            if "" != user:
                self.storage.add_trusted_root(user, site)

        log.debug("[checkid_submit] redirecting to %s" % r_url)
        redirect(r_url)
开发者ID:MuhamadYULIANTO,项目名称:LinOTP,代码行数:26,代码来源:openid.py


示例19: pwchange

 def pwchange(self, userid):
     """Reset a user password"""
     user = self._get_user(userid)
     if not user:
         abort(404)
     c.form = ChangePasswordForm(request.POST, csrf_context=session)
     if request.POST and c.form.validate():
         if user.local and not user.is_superadmin:
             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:
             if user.is_superadmin:
                 flash(_('Admin accounts can not be modified via the web'))
             else:
                 flash(_('This is an external account, use'
                     ' external system to reset the password'))
         redirect(url('account-detail', userid=user.id))
     c.id = userid
     c.username = user.username
     c.posturl = 'accounts-pw-change'
     return render('/accounts/pwchange.html')
开发者ID:TetraAsh,项目名称:baruwa2,代码行数:28,代码来源:accounts.py


示例20: logout

    def logout(self):
        '''
        This action deletes the cookie and redirects to the
        /openid/status to show the login status

        If the logout is called in the context of an openid authentication,
        the user is already logged in as a different user. In this case we
        forward to the /openid/login page after the logout was made.

        Another option for the openid authentication context would be to
        redirect to the return_to url by setting
            redirect_to = params["openid.return_to"]
            p["openid.mode"] = "setup_needed"
        which advises the openid relying party to restart the login process.
        '''

        response.delete_cookie(COOKIE_NAME)

        params = {}
        params.update(request.params)
        p = {}

        ## are we are called during an openid auth request?
        if "openid.return_to" in params:
            redirect_to = "/openid/login"
            p.update(params)
            do_redirect = url(str("%s?%s" % (redirect_to, urlencode(p))))

        else:
            redirect_to = "/openid/status"
            do_redirect = url(str("%s?%s" % (redirect_to, urlencode(p))))

        redirect(do_redirect)
开发者ID:MuhamadYULIANTO,项目名称:LinOTP,代码行数:33,代码来源:openid.py



注:本文中的pylons.controllers.util.redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.redirect_to函数代码示例发布时间:2022-05-25
下一篇:
Python util.forward函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap