本文整理匯總了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()
示例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)
示例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)
示例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)
示例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)