当前位置: 首页>>代码示例>>Python>>正文


Python nereid.url_for函数代码示例

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


在下文中一共展示了url_for函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: linkedin_authorized_login

    def linkedin_authorized_login(cls):
        """Authorized handler to which linkedin will redirect the user to
        after the login attempt is made.
        """
        Party = Pool().get('party.party')

        linkedin = request.nereid_website.get_linkedin_oauth_client()
        if linkedin is None:
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )

        try:
            if 'oauth_verifier' in request.args:
                data = linkedin.handle_oauth1_response()
            elif 'code' in request.args:
                data = linkedin.handle_oauth2_response()
            else:
                data = linkedin.handle_unknown_response()
            linkedin.free_request_token()
        except Exception, exc:
            current_app.logger.error("LinkedIn login failed %s" % exc)
            flash(_(
                "We cannot talk to linkedin at this time. Please try again"
            ))
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )
开发者ID:openlabs,项目名称:nereid-auth-linkedin,代码行数:28,代码来源:user.py

示例2: checkout

    def checkout(self):
        '''Submit of default checkout

        A GET to the method will result in passing of control to begin as
        that is basically the entry point to the checkout

        A POST to the method will result in the confirmation of the order and
        subsequent handling of data.
        '''
        cart_obj = Pool().get('nereid.cart')
        sale_obj = Pool().get('sale.sale')

        cart = cart_obj.open_cart()
        if not cart.sale:
            # This case is possible if the user changes his currency at
            # the point of checkout and the cart gets cleared.
            return redirect(url_for('nereid.cart.view_cart'))

        sale = cart.sale
        if not sale.lines:
            flash(_("Add some items to your cart before you checkout!"))
            return redirect(url_for('nereid.website.home'))
        if request.method == 'GET':
            return (self._begin_guest() if request.is_guest_user \
                else self._begin_registered())

        elif request.method == 'POST':
            form, do_process = self._submit_guest() if request.is_guest_user \
                else self._submit_registered()
            if do_process:
                # Process Shipping
                self._process_shipment(sale, form)

                # Process Payment, if the returned value from the payment
                # is a response object (isinstance) then return that instead
                # of the success page. This will allow reidrects to a third 
                # party gateway or service to collect payment.
                response = self._process_payment(sale, form)
                if isinstance(response, BaseResponse):
                    return response

                if sale.state == 'draft':
                    # Ensure that the order date is that of today
                    cart_obj.check_update_date(cart)
                    # Confirm the order
                    sale_obj.quote([sale.id])
                    sale_obj.confirm([sale.id])

                flash(_("Your order #%(sale)s has been processed", sale=sale.reference))
                if request.is_guest_user:
                    return redirect(url_for('nereid.website.home'))
                else:
                    return redirect(
                        url_for(
                            'sale.sale.render', sale=sale.id, 
                            confirmation=True
                        )
                    )

            return render_template('checkout.jinja', form=form, cart=cart)
开发者ID:shalabhaggarwal,项目名称:nereid-checkout,代码行数:60,代码来源:checkout.py

示例3: verify_email

 def verify_email(self, sign, max_age=24 * 60 * 60):
     """
     Verifies the email and redirects to home page. This is a method in
     addition to the activate method which activates the account in addition
     to verifying the email.
     """
     try:
         unsigned = self._serializer.loads(
             self._signer.unsign(sign, max_age=max_age),
             salt='verification'
         )
     except SignatureExpired:
         return self.build_response(
             'The verification link has expired',
             redirect(url_for('nereid.website.home')), 400
         )
     except BadSignature:
         return self.build_response(
             'The verification token is invalid!',
             redirect(url_for('nereid.website.home')), 400
         )
     else:
         if self.id == unsigned:
             self.email_verified = True
             self.save()
             return self.build_response(
                 'Your email has been verified!',
                 redirect(url_for('nereid.website.home')), 200
             )
         else:
             return self.build_response(
                 'The verification token is invalid!',
                 redirect(url_for('nereid.website.home')), 400
             )
开发者ID:2cadz,项目名称:nereid,代码行数:34,代码来源:user.py

示例4: render_comments

    def render_comments(self):
        """
        Render comments

        GET: Return json of all the comments of this post.
        POST: Create new comment for this post.
        """
        if self.state != 'Published':
            abort(404)

        # Add re_captcha if the configuration has such an option and user
        # is guest
        if 're_captcha_public' in CONFIG.options and request.is_guest_user:
            comment_form = GuestCommentForm(
                request.form, captcha={'ip_address': request.remote_addr}
            )
        else:
            comment_form = PostCommentForm(request.form)

        if request.method == 'GET':
            if self.nereid_user == request.nereid_user:
                return jsonify(comments=[
                    comment.serialize() for comment in self.comments
                ])
            return jsonify(comments=[
                comment.serialize() for comment in self.comments
                if not comment.is_spam
            ])

        # If post does not allow guest comments,
        # then dont allow guest user to comment
        if not self.allow_guest_comments and request.is_guest_user:
            flash('Guests are not allowed to write comments')
            if request.is_xhr:
                return jsonify(
                    success=False,
                    errors=['Guests are not allowed to write comments']
                )
            return redirect(url_for(
                'blog.post.render', user_id=self.nereid_user.id, uri=self.uri
            ))

        if request.method == 'POST' and comment_form.validate():
            self.write([self], {
                'comments': [('create', [{
                    'nereid_user': current_user.id
                        if not current_user.is_anonymous() else None,
                    'name': current_user.display_name
                        if not current_user.is_anonymous()
                            else comment_form.name.data,
                    'content': comment_form.content.data,
                }])]
            })

        if request.is_xhr:
            return jsonify(success=True) if comment_form.validate() \
                else jsonify(success=False, errors=comment_form.errors)
        return redirect(url_for(
            'blog.post.render', user_id=self.nereid_user.id, uri=self.uri
        ))
开发者ID:openlabs,项目名称:nereid-blog,代码行数:60,代码来源:blog.py

示例5: add_to_cart

    def add_to_cart(cls):
        """
        Adds the given item to the cart if it exists or to a new cart

        The form is expected to have the following data is post

            quantity    : decimal
            product     : integer ID
            action      : set (default), add

        Response:
            'OK' if X-HTTPRequest
            Redirect to shopping cart if normal request
        """
        form = AddtoCartForm(request.form)
        if request.method == 'POST' and form.validate():
            cart = cls.open_cart(create_order=True)
            action = request.values.get('action', 'set')
            if form.quantity.data <= 0:
                flash(
                    _('Be sensible! You can only add real quantities to cart')
                )
                return redirect(url_for('nereid.cart.view_cart'))
            cls._add_or_update(
                cart.sale.id, form.product.data, form.quantity.data, action
            )
            if action == 'add':
                flash(_('The product has been added to your cart'), 'info')
            else:
                flash(_('Your cart has been updated with the product'), 'info')
            if request.is_xhr:
                return jsonify(message='OK')

        return redirect(url_for('nereid.cart.view_cart'))
开发者ID:rahulsukla,项目名称:nereid-cart-b2c,代码行数:34,代码来源:cart.py

示例6: github_authorized_login

    def github_authorized_login(cls):
        """
        Authorized handler to which github will redirect the user to
        after the login attempt is made.
        """
        github = request.nereid_website.get_github_oauth_client()
        if github is None:
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )

        try:
            # The response is an oauth2 response with code. But Github API
            # requires the
            if 'oauth_verifier' in request.args:
                data = github.handle_oauth1_response()
            elif 'code' in request.args:
                data = github.handle_oauth2_response()
            else:
                data = github.handle_unknown_response()
            github.free_request_token()
        except Exception, exc:
            current_app.logger.error("Github login failed %s" % exc)
            flash(_("We cannot talk to github at this time. Please try again"))
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )
开发者ID:openlabs,项目名称:nereid-auth-github,代码行数:27,代码来源:user.py

示例7: facebook_authorized_login

    def facebook_authorized_login(self):
        """Authorized handler to which facebook will redirect the user to
        after the login attempt is made.
        """
        website_obj = Pool().get('nereid.website')

        facebook = website_obj.get_facebook_oauth_client()
        if facebook is None:
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )

        try:
            if 'oauth_verifier' in request.args:
                data = facebook.handle_oauth1_response()
            elif 'code' in request.args:
                data = facebook.handle_oauth2_response()
            else:
                data = facebook.handle_unknown_response()
            facebook.free_request_token()
        except Exception, exc:
            current_app.logger.error("Facebook login failed", exc)
            flash(_("We cannot talk to facebook at this time. Please try again"))
            return redirect(
                request.referrer or url_for('nereid.website.login')
            )
开发者ID:prakashpp,项目名称:nereid-auth-facebook,代码行数:26,代码来源:user.py

示例8: add_to_cart

    def add_to_cart(cls):
        """
        Adds the given item to the cart if it exists or to a new cart

        The form is expected to have the following data is post

            quantity    : decimal
            product     : integer ID
            action      : set (default), add

        Response:
            'OK' if X-HTTPRequest
            Redirect to shopping cart if normal request
        """
        Product = Pool().get('product.product')

        form = AddtoCartForm()
        if form.validate_on_submit():
            cart = cls.open_cart(create_order=True)
            action = request.values.get('action', 'set')
            if form.quantity.data <= 0:
                message = _(
                    'Be sensible! You can only add real quantities to cart')
                if request.is_xhr:
                    return jsonify(message=unicode(message)), 400
                flash(message)
                return redirect(url_for('nereid.cart.view_cart'))

            if not Product(form.product.data).template.salable:
                message = _("This product is not for sale")
                if request.is_xhr:
                    return jsonify(message=unicode(message)), 400
                flash(message)
                return redirect(request.referrer)

            sale_line = cart.sale._add_or_update(
                form.product.data, form.quantity.data, action
            )

            # Validate that product availability in inventory is not less than
            # warehouse quantity
            sale_line.validate_for_product_inventory()

            sale_line.save()

            if action == 'add':
                message = _('The product has been added to your cart')
            else:
                message = _('Your cart has been updated with the product')
            if request.is_xhr:
                return jsonify(
                    message=unicode(message),
                    line=sale_line.serialize(purpose='cart')
                ), 200
            flash(message, 'info')

        return redirect(url_for('nereid.cart.view_cart'))
开发者ID:2cadz,项目名称:nereid-cart-b2c,代码行数:57,代码来源:cart.py

示例9: facebook_login

 def facebook_login(cls):
     """The URL to which a new request to authenticate to facebook begins
     Usually issues a redirect.
     """
     facebook = request.nereid_website.get_facebook_oauth_client()
     if facebook is None:
         return redirect(request.referrer or url_for("nereid.website.login"))
     return facebook.authorize(
         callback=url_for(
             "nereid.user.facebook_authorized_login",
             next=request.args.get("next") or request.referrer or None,
             _external=True,
         )
     )
开发者ID:openlabs,项目名称:nereid-auth-facebook,代码行数:14,代码来源:user.py

示例10: linkedin_login

 def linkedin_login(cls):
     """The URL to which a new request to authenticate to linedin begins
     Usually issues a redirect.
     """
     linkedin = request.nereid_website.get_linkedin_oauth_client()
     if linkedin is None:
         return redirect(request.referrer or url_for("nereid.website.login"))
     return linkedin.authorize(
         callback=url_for(
             "nereid.user.linkedin_authorized_login",
             next=request.args.get("next") or request.referrer or None,
             _external=True,
         )
     )
开发者ID:param107,项目名称:nereid-auth-linkedin,代码行数:14,代码来源:user.py

示例11: github_login

 def github_login(cls):
     """The URL to which a new request to authenticate to github begins
     Usually issues a redirect.
     """
     github = request.nereid_website.get_github_oauth_client()
     if github is None:
         return redirect(
             request.referrer or url_for('nereid.website.login')
         )
     return github.authorize(
         callback = url_for('nereid.user.github_authorized_login',
             next = request.args.get('next') or request.referrer or None,
             _external = True
         )
     )
开发者ID:priyankarani,项目名称:nereid-auth-github,代码行数:15,代码来源:user.py

示例12: edit_post

    def edit_post(self):
        """
            Edit an existing post
        """
        if self.nereid_user != request.nereid_user:
            abort(404)

        # Search for a post with same uri
        post_form = BlogPostForm(request.form, obj=self)

        with Transaction().set_context(blog_id=self.id):
            if request.method == 'POST' and post_form.validate():
                self.title = post_form.title.data
                self.content = post_form.content.data
                self.allow_guest_comments = post_form.allow_guest_comments.data
                self.save()
                flash('Your post has been updated.')
                if request.is_xhr:
                    return jsonify(success=True, item=self.serialize())
                return redirect(url_for(
                    'blog.post.render', user_id=self.nereid_user.id,
                    uri=self.uri
                ))
        if request.is_xhr:
            return jsonify(
                success=request.method != 'POST',  # False for POST, else True
                errors=post_form.errors or None,
            )
        return render_template(
            'blog_post_edit.jinja', form=post_form, post=self
        )
开发者ID:openlabs,项目名称:nereid-blog,代码行数:31,代码来源:blog.py

示例13: new_post

    def new_post(cls):
        """Create a new post
        """
        post_form = BlogPostForm(request.form)

        if request.method == 'POST' and post_form.validate():
            post, = cls.create([{
                'title': post_form.title.data,
                'uri': post_form.uri.data,
                'content': post_form.content.data,
                'nereid_user': request.nereid_user.id,
                'allow_guest_comments': post_form.allow_guest_comments.data,
            }])
            if post_form.publish.data:
                cls.publish([post])
                flash('Your post has been published.')
            else:
                flash('Your post has been saved.')

            if request.is_xhr:
                return jsonify(success=True, item=post.serialize())
            return redirect(url_for(
                'blog.post.render', user_id=post.nereid_user.id,
                uri=post.uri
            ))
        if request.is_xhr:
            return jsonify(
                success=request.method != 'POST',  # False for POST, else True
                errors=post_form.errors or None,
            )
        return render_template('blog_post_form.jinja', form=post_form)
开发者ID:openlabs,项目名称:nereid-blog,代码行数:31,代码来源:blog.py

示例14: serialize

    def serialize(self, purpose=None):
        '''
        Serialize timesheet line and returns a dictionary.
        '''
        nereid_user_obj = Pool().get('nereid.user')

        try:
            nereid_user, = nereid_user_obj.search([
                ('employee', '=', self.employee.id)
            ], limit=1)
        except ValueError:
            nereid_user = {}
        else:
            nereid_user = nereid_user.serialize('listing')

        # Render url for timesheet line is task on which this time is marked
        return {
            'create_date': self.create_date.isoformat(),
            "url": url_for(
                'project.work.render_task', project_id=self.work.parent.id,
                task_id=self.work.id,
            ),
            "objectType": self.__name__,
            "id": self.id,
            "displayName": "%dh %dm" % (self.hours, (self.hours * 60) % 60),
            "updatedBy": nereid_user,
        }
开发者ID:GauravButola,项目名称:nereid-project,代码行数:27,代码来源:timesheet.py

示例15: delete_from_cart

    def delete_from_cart(cls, line):
        """
        Delete a line from the cart. The required argument in POST is:

            line_id : ID of the line

        Response: 'OK' if X-HTTPRequest else redirect to shopping cart
        """
        SaleLine = Pool().get('sale.line')

        cart = cls.open_cart()
        if not cart.sale:
            abort(404)

        try:
            sale_line, = SaleLine.search([
                ('id', '=', line),
                ('sale', '=', cart.sale.id),
            ])
        except ValueError:
            message = 'Looks like the item is already deleted.'
        else:
            SaleLine.delete([sale_line])
            message = 'The order item has been successfully removed.'

        flash(_(message))

        if request.is_xhr:
            return jsonify(message=message)

        return redirect(url_for('nereid.cart.view_cart'))
开发者ID:2cadz,项目名称:nereid-cart-b2c,代码行数:31,代码来源:cart.py


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