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


Python TopicForm.validate方法代码示例

本文整理汇总了Python中forms.TopicForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python TopicForm.validate方法的具体用法?Python TopicForm.validate怎么用?Python TopicForm.validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.TopicForm的用法示例。


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

示例1: create

# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import validate [as 别名]
def create():
    data = request.get_json()
    
    form = TopicForm(**data)
    if form.validate():
        form_data = form.data
        form_data['ip'] = request.remote_addr

        try:
            topic = g.user.create_topic(**form_data)
            alert = dict(
                type='success',
                messages=_("Your topic has been created successfully. You will be redirected to it shortly")
            )

            redirect = topic.get_url('view')
            cache.update_sorted_topics(topic, 'date_created')
            return jsonify({"data": topic.json_data(), "alert": alert, "redirect": redirect})
        except ModelException, me:
            db_session.rollback()
            return json_error(type=me.type, messages=me.message)
        except Exception, e:
            logging.error(e)
            db_session.rollback()
            return json_error_database()
开发者ID:laoshanlung,项目名称:flask-demo,代码行数:27,代码来源:api_topics.py

示例2: post

# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import validate [as 别名]
 def post(self):
     node_id = force_int(self.get_argument('node_id', 0), 0)
     node = Node.get(id=node_id)
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user)
         topic.put_notifier()
         result = {'status': 'success', 'message': '主题创建成功',
                   'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=node)
开发者ID:ljtyzhr,项目名称:collipa,代码行数:19,代码来源:topic.py

示例3: chat

# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import validate [as 别名]
def chat(user):
    # Creating new topics.
    if request.method == 'POST':
        if user.topics_full():
            return render_template('/index.html', topics=get_topics(), full=True,
                    user=user.user)
        form = TopicForm(request.form)
        if form.validate():
            form.add(user.user)
        return render_template('/index.html', topics=get_topics(), form=form,
                user=user.user)
    
    # Deleting topics.
    if request.method == 'GET' and request.args.get('del_topic', False):
        user.del_topic(request.args['del_topic'])
    form = TopicForm()
    return render_template('/index.html', topics=get_topics(), form=form,
            user=user.user)
开发者ID:claudiay,项目名称:slothchat,代码行数:20,代码来源:views.py

示例4: post

# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import validate [as 别名]
 def post(self, topic_id):
     if not self.has_permission:
         return
     topic = Topic.get(id=topic_id)
     if not topic:
         return self.redirect_next_url()
     user = self.current_user
     form = TopicForm(self.request.arguments)
     if form.validate():
         topic = form.save(user=user, topic=topic)
         result = {'status': 'success', 'message': '主题修改成功',
                 'topic_url': topic.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(topic.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("topic/create.html", form=form, node=topic.node)
开发者ID:SunnyKale,项目名称:collipa,代码行数:21,代码来源:topic.py

示例5: bbs_add_topic

# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import validate [as 别名]
def bbs_add_topic():
    node_str = urllib.unquote(request.args.get('node', "").strip())
    node = None
    if node_str:
        node = Node.query.filter(Node.name==node_str).first()
        if not node:
            return render_template("node_not_found.html", next=url_for('.bbs_add_topic'), name=node_str)

    form = TopicForm(request.form)
    form.node.choices = Section.query.get_all_nodes()
    if node_str:
        form.node.data=node.title
    if request.method == 'POST' and form.validate():
        if not node:
            node = Node.query.filter(Node.title==form.data["node"].strip()).first()
            if not node:
                form.node.errors.append(u"节点不存在!")
                return render_template("add_topic.html", form=form)
        section = node.section
        topic = Topic(user=current_user, title=form.data['title'].strip(), content=form.data["content"],
                    tags=form.data["tags"], created=datetime.now(), last_modified=datetime.now(),
                    last_reply_at=datetime.now())
        topic.section = section
        topic.node = node

        #db.session.add(topic)
        node.topic_count += 1
        #db.session.add(node)
        section.topic_count += 1
        #db.session.add(section)
        current_user.profile.topics += 1
        db.session.add_all([topic, node, section, current_user.profile])
        db.session.commit()
        return redirect(url_for(".bbs_topic", id=topic.id))
    if node_str:
        action_url = url_for(".bbs_add_topic", node=node_str)
    else:
        action_url = url_for(".bbs_add_topic")
    return render_template("add_topic.html", form=form, action_url=action_url)
开发者ID:FashtimeDotCom,项目名称:flaskbbs,代码行数:41,代码来源:views.py


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