本文整理汇总了Python中forms.TopicForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python TopicForm.is_valid方法的具体用法?Python TopicForm.is_valid怎么用?Python TopicForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TopicForm
的用法示例。
在下文中一共展示了TopicForm.is_valid方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newtopic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def newtopic(request):
user = request.user
form = None
if request.method == 'POST':
form = TopicForm(request.POST)
if form.is_valid() and form.save():
return redirect('/topics/')
elif form.is_valid():
form.non_field_errors = "Failed to save"
else:
form.non_field_errors = 'form is not valid'
else:
form = TopicForm()
return render(request, 'forum/form.html', {"form": form})
示例2: add_topic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def add_topic(request):
'''Add a new topic'''
tform = None
if request.method == 'POST':
tform = TopicForm(request.POST)
if tform.is_valid():
t = tform.save()
'If topic was added successfully, send them to that topic page'
return goto_topic(t, 'Now you can start adding options')
if not tform:
tform = TopicForm()
return render_to_response('dovote/add_topic.html',
dict(tform=tform),
context_instance=RequestContext(request))
示例3: add_topic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def add_topic(request, event_id):
e = Event.objects.get(id=event_id)
if request.method == 'POST':
f = TopicForm(request.POST)
if f.is_valid():
t = f.save(commit=false)#not push yet.
#more values... to event yes.
t.event = e
t.save()
return HttpResponseRedirect('/event/get/%s' % event_id)
else:
f=TopicForm()
args ={}
args.update(csrf(request))
args['article']=a
args['form']=f
return render_to_response('add_topic.html',args)
示例4: new
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def new(request):
if request.method == 'POST':
topic_form = TopicForm(request.POST)
post_form = PostForm(request.POST)
if topic_form.is_valid() and post_form.is_valid():
topic = topic_form.save()
post = post_form.save(commit=False)
post.topic = topic
post.author = request.user
post.save()
return redirect('/forum/%d' % topic.id)
else:
topic_form = TopicForm()
post_form = PostForm()
return render_to_response('forum/new.html',
{
'topic_form': topic_form,
'post_form': post_form
},
context_instance=RequestContext(request))
示例5: create_topic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def create_topic(request, forum):
forum = Forum.objects.select_related('Moderator').get(slug=forum)
if request.method == "POST":
topic_form = TopicForm(request.POST, instance=Topic())
message_form = MessageForm(request.POST, instance=Message())
if topic_form.is_valid():
if message_form.is_valid():
topic = topic_form.save(commit=False)
topic.category = forum.category
topic.forum = forum
topic.user = request.user
topic.last_user = request.user
topic.save()
message = message_form.save(commit=False)
message.category = forum.category
message.forum = forum
message.topic = topic
message.user = request.user
message.save()
topic.message = message
topic.last_message = message
topic.save()
action.send(request.user, verb='created a topic', target=topic)
return HttpResponseRedirect(reverse('djero.views.topic', kwargs={
'category' : forum.category.slug,
'forum' : forum.slug,
'topic' : topic.slug,
}))
else:
return HttpResponse(topic_form.errors)
else:
topic_form = TopicForm()
message_form = MessageForm()
return render(request, "forum/create_topic.html", {
"forum" : forum,
"topic_form" : topic_form,
"message_form" : message_form,
})
示例6: new
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def new(request):
"""Creates a new topic in a forum."""
try:
forum_pk = request.GET["forum"]
except KeyError:
raise Http404
forum = get_object_or_404(Forum, pk=forum_pk)
if not forum.can_read(request.user):
raise PermissionDenied
if request.method == "POST":
# If the client is using the "preview" button
if "preview" in request.POST:
form = TopicForm(initial={"title": request.POST["title"],
"subtitle": request.POST["subtitle"],
"text": request.POST["text"]})
return render_template("forum/topic/new.html",
{"forum": forum,
"form": form,
"text": request.POST["text"]})
form = TopicForm(request.POST)
data = form.data
if form.is_valid():
# Treat title
(tags, title) = get_tag_by_title(data["title"])
# Creating the thread
n_topic = Topic()
n_topic.forum = forum
n_topic.title = title
n_topic.subtitle = data["subtitle"]
n_topic.pubdate = datetime.now()
n_topic.author = request.user
n_topic.save()
# add tags
n_topic.add_tags(tags)
n_topic.save()
# Adding the first message
post = Post()
post.topic = n_topic
post.author = request.user
post.text = data["text"]
post.text_html = emarkdown(request.POST["text"])
post.pubdate = datetime.now()
post.position = 1
post.ip_address = get_client_ip(request)
post.save()
n_topic.last_message = post
n_topic.save()
# Follow the topic
follow(n_topic)
return redirect(n_topic.get_absolute_url())
else:
form = TopicForm()
return render_template("forum/topic/new.html", {"forum": forum, "form": form})
示例7: forum_topics
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import is_valid [as 别名]
def forum_topics(request, slug):
forum = get_object_or_404(Forum, slug=slug)
if not request.user.has_perm("can_view_topics", forum):
return HttpResponseForbidden()
topics_qs = Topic.objects.filter(forum=forum)
# пагинация сообщений в топике форума
paginator = Paginator(topics_qs, 20)
page_num = request.GET.get('page', '1')
if page_num == 'last':
page_num = paginator.num_pages
try:
page = paginator.page(int(page_num))
except (InvalidPage, ValueError):
raise Http404()
# topics = paginator.object_list
if request.method == 'POST':
if forum.closed:
return HttpResponseForbidden()
topic_form = TopicForm(request.POST, prefix='topic')
article_form = ArticleForm(request.POST, prefix='article')
if topic_form.is_valid() and article_form.is_valid():
if not request.user.has_perm("can_create_topics", forum):
return HttpResponseForbidden()
topic = topic_form.save(commit=False)
if request.user.has_perm('can_hide_topics', forum):
topic.public = True
else:
topic.public = False
topic.forum = forum
topic.save()
article = article_form.save(commit=False)
article.public = True
article.author = request.user
article.topic = topic
article.save()
groups = get_groups_with_perms(forum, attach_perms=True)
for group in groups:
if u"can_create_topics" in groups[group]:
assign(u"can_add_articles", group, topic)
# assign(u"can_view_articles", group, topic)
if u"can_view_topics" in groups[group]:
assign(u"can_view_articles", group, topic)
if request.user.has_perm('can_hide_topics', forum):
return redirect('forum:frontend:articles', slug=forum.slug, id=topic.id)
else:
return redirect('forum:frontend:topics', slug=forum.slug)
else:
topic_form = TopicForm(prefix='topic')
article_form = ArticleForm(prefix='article')
return render(request, 'forum/frontend/topics.html', {
'forum': forum,
# 'topics': topics,
'topic_form': topic_form,
'article_form': article_form,
'page': page,
})