當前位置: 首頁>>代碼示例>>Python>>正文


Python Post.get_absolute_url方法代碼示例

本文整理匯總了Python中forums.models.Post.get_absolute_url方法的典型用法代碼示例。如果您正苦於以下問題:Python Post.get_absolute_url方法的具體用法?Python Post.get_absolute_url怎麽用?Python Post.get_absolute_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在forums.models.Post的用法示例。


在下文中一共展示了Post.get_absolute_url方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post_new

# 需要導入模塊: from forums.models import Post [as 別名]
# 或者: from forums.models.Post import get_absolute_url [as 別名]
def post_new(request, topic_id, quoted_post_id=None):
	topic = get_object_or_404(Topic.objects.select_related(), pk=topic_id)
	if topic.is_closed:
		if not request.user.is_staff:
			messages.error(request, "You are not allowed to post in closed topics.")
			return redirect(topic.get_absolute_url())
		else:
			messages.info(request, "Note: This topic is closed.")
	if not can_post_reply(request.user, topic.forum):
		messages.error(request, "You are not allowed to reply on this forum.")
		return redirect(topic.get_absolute_url())
	if request.method == 'POST':
		form = PostForm(request.POST)
		if form.is_valid():
			content = form.cleaned_data['content']
			post = Post(topic=topic, author=request.user,
				author_ip=request.META['REMOTE_ADDR'], content=content)
			post.save()
			messages.success(request, "Your reply has been saved.")
			return redirect(post.get_absolute_url())
	else:
		form = PostForm()
		if quoted_post_id:
			try:
				quoted_post = Post.objects.get(pk=quoted_post_id, topic=topic)
				form.initial = {'content': "[quote=%s]%s[/quote]" %
					(quoted_post.author, quoted_post.content)}
			except Post.DoesNotExist:
				messages.warning(request, "You tried to quote a post which "
					"doesn't exist or it doesn't belong to topic you are "
					"replying to. Nice try, Kevin.")
	return {'topic': topic, 'form': form}
開發者ID:chi1,項目名稱:trinitee,代碼行數:34,代碼來源:views.py


注:本文中的forums.models.Post.get_absolute_url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。