当前位置: 首页>>代码示例>>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;未经允许,请勿转载。