本文整理汇总了Python中forms.TopicForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python TopicForm.save方法的具体用法?Python TopicForm.save怎么用?Python TopicForm.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.TopicForm
的用法示例。
在下文中一共展示了TopicForm.save方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: newtopic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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 save [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: post
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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)
示例4: post
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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: add_topic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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)
示例6: new
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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))
示例7: create_topic
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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,
})
示例8: forum_topics
# 需要导入模块: from forms import TopicForm [as 别名]
# 或者: from forms.TopicForm import save [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,
})