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

Python nereid.jsonify函数代码示例

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

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



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

示例1: add

    def add(cls):
        """
        Adds a contact mechanism to the party's contact mechanisms
        """
        form = cls.get_form()
        if form.validate_on_submit():
            cls.create(
                [
                    {
                        "party": request.nereid_user.party.id,
                        "type": form.type.data,
                        "value": form.value.data,
                        "comment": form.comment.data,
                    }
                ]
            )
            if request.is_xhr:
                return jsonify({"success": True})
            return redirect(request.referrer)

        if request.is_xhr:
            return jsonify({"success": False})
        else:
            for field, messages in form.errors:
                flash("<br>".join(messages), "Field %s" % field)
            return redirect(request.referrer)
开发者ID:GauravButola,项目名称:nereid,代码行数:26,代码来源:party.py


示例2: 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


示例3: 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


示例4: start_session

    def start_session(cls):
        '''
        POST: Start chat session with another user.
            :args user: User Id of nereid user.

        :return: JSON as
                {
                    thread_id: uuid,
                    members: Serialized members list.
                }
        '''
        NereidUser = Pool().get('nereid.user')
        form = NewChatForm()

        if not form.validate_on_submit():
            return jsonify(errors=form.errors), 400

        chat_with = NereidUser(form.user.data)
        if not request.nereid_user.can_chat(chat_with):
            abort(403, "You can only talk to friends")

        chat = cls.get_or_create_room(
            request.nereid_user.id, chat_with.id
        )
        return jsonify({
            'thread_id': chat.thread,
            'members': map(
                lambda m: m.user.serialize(), chat.members
            )
        })
开发者ID:openlabs,项目名称:nereid-chat,代码行数:30,代码来源:chat.py


示例5: 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


示例6: 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


示例7: registration

    def registration(cls):
        """
        Invokes registration of an user
        """
        Party = Pool().get('party.party')

        registration_form = cls.get_registration_form()

        if registration_form.validate_on_submit():
            with Transaction().set_context(active_test=False):
                existing = cls.search([
                    ('email', '=', registration_form.email.data),
                    ('company', '=', request.nereid_website.company.id),
                ])
            if existing:
                message = _(
                    'A registration already exists with this email. '
                    'Please contact customer care'
                )
                if request.is_xhr or request.is_json:
                    return jsonify(message=unicode(message)), 400
                else:
                    flash(message)
            else:
                party = Party(name=registration_form.name.data)
                party.addresses = []
                party.save()
                nereid_user = cls(**{
                    'party': party.id,
                    'display_name': registration_form.name.data,
                    'email': registration_form.email.data,
                    'password': registration_form.password.data,
                    'company': request.nereid_website.company.id,
                }
                )
                nereid_user.save()
                registration.send(nereid_user)
                nereid_user.send_activation_email()
                message = _(
                    'Registration Complete. Check your email for activation'
                )
                if request.is_xhr or request.is_json:
                    return jsonify(message=unicode(message)), 201
                else:
                    flash(message)
                return redirect(
                    request.args.get('next', url_for('nereid.website.home'))
                )

        if registration_form.errors and (request.is_xhr or request.is_json):
            return jsonify({
                'message': unicode(_('Form has errors')),
                'errors': registration_form.errors,
            }), 400

        return render_template('registration.jinja', form=registration_form)
开发者ID:sharoonthomas,项目名称:nereid,代码行数:56,代码来源:user.py


示例8: login

    def login(cls):
        """
        Simple login based on the email and password

        Required post data see :class:LoginForm
        """
        login_form = LoginForm(request.form)

        if not current_user.is_anonymous() and request.args.get('next'):
            return redirect(request.args['next'])

        if request.method == 'POST' and login_form.validate():
            NereidUser = Pool().get('nereid.user')
            user = NereidUser.authenticate(
                login_form.email.data, login_form.password.data
            )
            # Result can be the following:
            # 1 - Browse record of User (successful login)
            # 2 - None - Login failure without message
            # 3 - Any other false value (no message is shown. useful if you
            #       want to handle the message shown to user)
            if user:
                # NOTE: Translators leave %s as such
                flash(_("You are now logged in. Welcome %(name)s",
                        name=user.display_name))
                if login_user(user, remember=login_form.remember.data):
                    if request.is_xhr:
                        return jsonify({
                            'success': True,
                            'user': user.serialize(),
                        })
                    else:
                        return redirect(
                            request.values.get(
                                'next', url_for('nereid.website.home')
                            )
                        )
                else:
                    flash(_("Your account has not been activated yet!"))
            elif user is None:
                flash(_("Invalid login credentials"))

            failed_login.send(form=login_form)

            if request.is_xhr:
                rv = jsonify(message="Bad credentials")
                rv.status_code = 401
                return rv

        return render_template('login.jinja', login_form=login_form)
开发者ID:priyankajain18,项目名称:nereid,代码行数:50,代码来源:website.py


示例9: registration

    def registration(cls):
        """
        Invokes registration of an user
        """
        Party = Pool().get("party.party")
        ContactMechanism = Pool().get("party.contact_mechanism")

        registration_form = cls.get_registration_form()

        if registration_form.validate_on_submit():
            with Transaction().set_context(active_test=False):
                existing = cls.search(
                    [("email", "=", registration_form.email.data.lower()), ("company", "=", current_website.company.id)]
                )
            if existing:
                message = _("A registration already exists with this email. " "Please contact customer care")
                if request.is_xhr or request.is_json:
                    return jsonify(message=unicode(message)), 400
                else:
                    flash(message)
            else:
                party = Party(name=registration_form.name.data)
                party.addresses = []
                party.contact_mechanisms = [ContactMechanism(type="email", value=registration_form.email.data)]
                party.save()
                nereid_user = cls(
                    **{
                        "party": party.id,
                        "display_name": registration_form.name.data,
                        "email": registration_form.email.data,
                        "password": registration_form.password.data,
                        "company": current_website.company.id,
                    }
                )
                nereid_user.save()
                registration.send(nereid_user)
                nereid_user.send_activation_email()
                message = _("Registration Complete. Check your email for activation")
                if request.is_xhr or request.is_json:
                    return jsonify(message=unicode(message)), 201
                else:
                    flash(message)
                return redirect(request.args.get("next", url_for("nereid.website.home")))

        if registration_form.errors and (request.is_xhr or request.is_json):
            return jsonify({"message": unicode(_("Form has errors")), "errors": registration_form.errors}), 400

        return render_template("registration.jinja", form=registration_form)
开发者ID:fulfilio,项目名称:nereid,代码行数:48,代码来源:user.py


示例10: edit_task

    def edit_task(self):
        """
        Edit the task
        """
        Activity = Pool().get("nereid.activity")
        Work = Pool().get("timesheet.work")

        task = self.get_task(self.id)

        Work.write([task.work], {"name": request.form.get("name")})
        self.write([task], {"comment": request.form.get("comment")})
        Activity.create(
            [
                {
                    "actor": request.nereid_user.id,
                    "object_": "project.work, %d" % task.id,
                    "verb": "edited_task",
                    "target": "project.work, %d" % task.parent.id,
                    "project": task.parent.id,
                }
            ]
        )
        if request.is_xhr:
            return jsonify({"success": True, "name": self.rec_name, "comment": self.comment})
        return redirect(request.referrer)
开发者ID:GauravButola,项目名称:nereid-project,代码行数:25,代码来源:task.py


示例11: change_password

    def change_password(cls):
        """
        Changes the password

        .. tip::
            On changing the password, the user is logged out and the login page
            is thrown at the user
        """
        form = ChangePasswordForm()

        if request.method == "POST" and form.validate():
            if current_user.match_password(form.old_password.data):
                cls.write([current_user], {"password": form.password.data})
                logout_user()
                return cls.build_response(
                    "Your password has been successfully changed! " "Please login again",
                    redirect(url_for("nereid.website.login")),
                    200,
                )
            else:
                return cls.build_response(
                    "The current password you entered is invalid",
                    render_template("change-password.jinja", change_password_form=form),
                    400,
                )

        if form.errors and (request.is_xhr or request.is_json):
            return jsonify(errors=form.errors), 400

        return render_template("change-password.jinja", change_password_form=form)
开发者ID:fulfilio,项目名称:nereid,代码行数:30,代码来源:user.py


示例12: 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()
        if form.validate_on_submit():
            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'))
            cart._add_or_update(
                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:aroraumang,项目名称:nereid-cart-b2c,代码行数:34,代码来源:cart.py


示例13: get_all_countries

 def get_all_countries(cls):
     """
     Returns serialized list of all countries
     """
     return jsonify(countries=[
         country.serialize() for country in cls.search([])
     ])
开发者ID:2cadz,项目名称:nereid,代码行数:7,代码来源:country.py


示例14: delete_task

    def delete_task(cls, task_id):
        """
        Delete the task from project

        Tasks can be deleted only if
            1. The user is project admin
            2. The user is an admin member in the project

        :param task_id: Id of the task to be deleted
        """
        task = cls.get_task(task_id)

        # Check if user is among the project admins
        if not request.nereid_user.is_admin_of_project(task.parent):
            flash(
                "Sorry! You are not allowed to delete tasks. \
                Contact your project admin for the same."
            )
            return redirect(request.referrer)

        cls.write([task], {"active": False})

        if request.is_xhr:
            return jsonify({"success": True})

        flash("The task has been deleted")
        return redirect(url_for("project.work.render_project", project_id=task.parent.id))
开发者ID:GauravButola,项目名称:nereid-project,代码行数:27,代码来源:task.py


示例15: 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:shalabhaggarwal,项目名称:nereid-cart-b2c,代码行数:30,代码来源:cart.py


示例16: change_constraint_dates

    def change_constraint_dates(cls, task_id):
        """
        Change the constraint dates
        """
        Activity = Pool().get("nereid.activity")

        task = cls.get_task(task_id)

        data = {"constraint_start_time": False, "constraint_finish_time": False}

        constraint_start = request.form.get("constraint_start_time", None)
        constraint_finish = request.form.get("constraint_finish_time", None)

        if constraint_start:
            data["constraint_start_time"] = datetime.strptime(constraint_start, "%m/%d/%Y")
        if constraint_finish:
            data["constraint_finish_time"] = datetime.strptime(constraint_finish, "%m/%d/%Y")

        cls.write([task], data)
        Activity.create(
            [
                {
                    "actor": request.nereid_user.id,
                    "object_": "project.work, %d" % task.id,
                    "verb": "changed_date",
                    "project": task.parent.id,
                }
            ]
        )

        if request.is_xhr:
            return jsonify({"success": True})

        flash("The constraint dates have been changed for this task.")
        return redirect(request.referrer)
开发者ID:GauravButola,项目名称:nereid-project,代码行数:35,代码来源:task.py


示例17: edit_task

    def edit_task(self):
        """
        Edit the task
        """
        Activity = Pool().get('nereid.activity')
        Work = Pool().get('timesheet.work')

        task = self.get_task(self.id)

        Work.write([task.work], {
            'name': request.form.get('name'),
        })
        self.write([task], {
            'comment': request.form.get('comment')
        })
        Activity.create([{
            'actor': request.nereid_user.id,
            'object_': 'project.work, %d' % task.id,
            'verb': 'edited_task',
            'target': 'project.work, %d' % task.parent.id,
            'project': task.parent.id,
        }])
        if request.is_xhr:
            return jsonify({
                'success': True,
                'name': self.rec_name,
                'comment': self.comment,
            })
        return redirect(request.referrer)
开发者ID:openlabs,项目名称:nereid-project,代码行数:29,代码来源:task.py


示例18: update_comment

    def update_comment(self, task_id, comment_id):
        """
        Update a specific comment.
        """
        project_obj = Pool().get('project.work')
        nereid_user_obj = Pool().get('nereid.user')

        # allow modification only if the user is an admin or the author of
        # this ticket
        task = project_obj.browse(task_id)
        comment = self.browse(comment_id)
        assert task.type == "task"
        assert comment.project.id == task.id

        # Allow only admins and author of this comment to edit it
        if nereid_user_obj.is_project_admin(request.nereid_user) or \
                comment.updated_by == request.nereid_user:
            self.write(comment_id, {'comment': request.form['comment']})
        else:
            abort(403)

        if request.is_xhr:
            comment_record = self.browse(comment_id)
            html = render_template('comment.jinja', comment=comment_record)
            return jsonify({
                'success': True,
                'html': html,
                'state': project_obj.browse(task.id).state,
            })
        return redirect(request.referrer)
开发者ID:Anoopsmohan,项目名称:nereid-project,代码行数:30,代码来源:project.py


示例19: search_auto_complete

 def search_auto_complete(cls):
     """
     Handler for auto-completing search.
     """
     return jsonify(results=cls.auto_complete(
         request.args.get('q', '')
     ))
开发者ID:priyankarani,项目名称:nereid-webshop,代码行数:7,代码来源:webshop.py


示例20: assign_task

    def assign_task(self, task_id):
        """Assign task to a user

        :param task_id: Id of Task
        """
        nereid_user_obj = Pool().get('nereid.user')

        task = self.get_task(task_id)

        new_assignee = nereid_user_obj.browse(int(request.form['user']))

        if self.can_write(task.parent, new_assignee):
            self.write(task.id, {
                'assigned_to': new_assignee.id
            })

            if request.is_xhr:
                return jsonify({
                    'success': True,
                })

            flash("Task assigned to %s" % new_assignee.name)
            return redirect(request.referrer)

        flash("Only employees can be assigned to tasks.")
        return redirect(request.referrer)
开发者ID:Anoopsmohan,项目名称:nereid-project,代码行数:26,代码来源:project.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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