当前位置: 首页>>代码示例>>Python>>正文


Python Post.save方法代码示例

本文整理汇总了Python中forums.models.Post.save方法的典型用法代码示例。如果您正苦于以下问题:Python Post.save方法的具体用法?Python Post.save怎么用?Python Post.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forums.models.Post的用法示例。


在下文中一共展示了Post.save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_new

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [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

示例2: add_thread

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
def add_thread(request, forum_id):
    # First try finding the (sub)forum
    forum = get_object_or_404(Subforum, pk=forum_id)

    # Load template
    template = loader.get_template('forums/add_thread.html')

    # We do different things for POST and GET
    if request.method == 'POST':
        # Grab the info from the post thingy
        try:
            title   = request.POST['title']
            content = request.POST['content']
        # If something goes wrong...
        except (KeyError):
            return render(request, 'forums/add_thread.html', {
                'forum': forum,
                'error_message': "You didn't provide needed data!",
                })
        # If we get both info out well?
        else:
            # If content is empty, error out
            if not content or not title:
                return render(request, 'forums/add_thread.html', {
                    'forum': forum,
                    'error_message': "Please do not leave content or title empty :< !",
                    })

            # Create and write post into the database, wee
            t = Thread(subforum=Subforum.objects.get(pk=forum.id),
                       creator=request.user, title=title, creation_date=timezone.now(),
                       sticky=False)
            if not t:
                return render(request, 'forums/add_thread.html', {
                    'forum': forum,
                    'error_message': "Gooby please... I have no idea what just happened, but you errored out (thread object creation).",
                    })

            t.save()

            p = Post(thread=t, poster=request.user, title=title, content=content,
                    is_op=True, pub_date=timezone.now())
            if not p:
                t.delete()
                return render(request, 'forums/add_thread.html', {
                    'forum': forum,
                    'error_message': "Gooby please... I have no idea what just happened, but you errored out (post object creation).",
                    })

            p.save()

            # For good measure, do a HttpResponseRedirect
            return HttpResponseRedirect(reverse(show_thread, args=(t.id,)))
    else:
        return render(request, 'forums/add_thread.html', {
            'forum': forum
            })
开发者ID:jeeb,项目名称:tsoha,代码行数:59,代码来源:views.py

示例3: test_save_new_post_timestamps

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
 def test_save_new_post_timestamps(self):
     # Saving a new post should allow you to override auto_add_now-
     # and auto_now-like functionality.
     created_ = datetime(1992, 1, 12, 10, 12, 32)
     p = Post(thread=self.thread, content='bar', author=self.user,
              created=created_, updated=created_)
     p.save()
     eq_(created_, p.created)
     eq_(created_, p.updated)
开发者ID:DWDRAEGER,项目名称:kitsune,代码行数:11,代码来源:test_models.py

示例4: test_with_activity

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
 def test_with_activity(self):
     """Test the page with some activity."""
     # Add a reply
     post = Post(thread_id=4, content='lorem ipsum', author_id=118577)
     post.save()
     # Verify activity on the page
     response = self.client.get(reverse('dashboards.review'), follow=True)
     eq_(200, response.status_code)
     doc = pq(response.content)
     eq_(1, len(doc('ol.actions li')))
开发者ID:Sancus,项目名称:kitsune,代码行数:12,代码来源:test_templates.py

示例5: test_save_new_post_no_timestamps

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
 def test_save_new_post_no_timestamps(self):
     """
     Saving a new post should behave as if auto_add_now was set on
     created and auto_now set on updated.
     """
     p = Post(thread=self.thread, content='bar', author=self.user)
     p.save()
     now = datetime.datetime.now()
     self.assertDateTimeAlmostEqual(now, p.created, self.delta)
     self.assertDateTimeAlmostEqual(now, p.updated, self.delta)
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:12,代码来源:test_models.py

示例6: test_delete_last_and_only_post_in_thread

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
 def test_delete_last_and_only_post_in_thread(self):
     """Deleting the only post in a thread should delete the thread"""
     forum = Forum.objects.get(pk=1)
     thread = Thread(title="test", forum=forum, creator_id=118533)
     thread.save()
     post = Post(thread=thread, content="test", author=thread.creator)
     post.save()
     eq_(1, thread.post_set.count())
     post.delete()
     eq_(0, Thread.uncached.filter(pk=thread.id).count())
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:12,代码来源:test_models.py

示例7: form_valid

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
    def form_valid(self, form):
        body = form.cleaned_data['message']
        user = self.request.user
        post = Post(topic=self.topic, body=body, user=user)
        post.save()
        post.topic.last_post = post
        post.topic.save()

        self.success_url = reverse('forums:topic', args=[self.topic.id])

        return super(PostCreateView, self).form_valid(form)
开发者ID:inteljack,项目名称:ForumServer,代码行数:13,代码来源:views.py

示例8: save_model

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
	def save_model(self, request, obj, form, change):
		if change:
			obj.modified_by = request.user
			obj.first_post.modified_by = request.user
			obj.first_post.content = form.cleaned_data['content']
			obj.first_post.save()
			obj.save()
		else:
			obj.author = request.user
			obj.author_ip = request.META['REMOTE_ADDR']
			obj.save()
			post = Post(topic=obj, author=request.user,
				author_ip=request.META['REMOTE_ADDR'],
				content=form.cleaned_data['content'])
			post.save()
开发者ID:chi1,项目名称:trinitee,代码行数:17,代码来源:admin.py

示例9: form_valid

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
    def form_valid(self, form):
        body = form.cleaned_data['message']
        user = UserProfile.objects.get(user=User.objects.get(username=self.request.user.username))

        post = Post(topic=self.topic, body=body, user=user)
        post.save()
        post.topic.last_post = post
        post.topic.save()

        view = View.objects.filter(topic=self.topic)
        for v in view:
            v.visited = False
            v.save()
        topic_page = self.topic.posts_range()[-1]
        self.success_url = ('/forums/topic/' + str(self.topic.id) + '/page' + str(topic_page))

        return super(PostCreateView, self).form_valid(form)
开发者ID:SebastianLasisz,项目名称:midnight-order,代码行数:19,代码来源:views.py

示例10: add_post

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
def add_post(request, thread_id):
    # First try finding the thread
    thread = get_object_or_404(Thread, pk=thread_id)

    # Load template
    template = loader.get_template('forums/add_post.html')

    # We do different things for POST and GET
    if request.method == 'POST':
        # Grab the info from the post thingy
        try:
            title   = request.POST['title']
            content = request.POST['content']
        # If something goes wrong...
        except (KeyError):
            return render(request, 'forums/add_post.html', {
                'thread': thread,
                'error_message': "You didn't provide needed data!",
                })
        # If we get both info out well?
        else:
            # If content is empty, error out
            if not content:
                return render(request, 'forums/add_post.html', {
                    'thread': thread,
                    'error_message': "Please do not leave content empty :< !",
                    })

            # If title is empty we just use Re: <thread title>
            if not title:
                title = "Re: " + thread.title

            # Create and write post into the database, wee
            p = Post(thread=thread, poster=request.user, title=title,
                     content=content, pub_date=timezone.now())
            p.save()

            # For good measure, do a HttpResponseRedirect
            return HttpResponseRedirect(reverse(show_thread, args=(thread.id,)))
    # And here is what GET n' shit does
    else:
        return render(request, 'forums/add_post.html', {
            'thread': thread,
            })
开发者ID:jeeb,项目名称:tsoha,代码行数:46,代码来源:views.py

示例11: test_delete_thread_with_last_forum_post

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
    def test_delete_thread_with_last_forum_post(self):
        """Deleting the thread with a forum's last post should
        update the last_post field on the forum
        """
        forum = Forum.objects.get(pk=1)
        last_post = forum.last_post

        # add a new thread and post, verify last_post updated
        thread = Thread(title="test", forum=forum, creator_id=118533)
        thread.save()
        post = Post(thread=thread, content="test", author=thread.creator)
        post.save()
        forum = Forum.objects.get(pk=1)
        eq_(forum.last_post.id, post.id)

        # delete the post, verify last_post updated
        thread.delete()
        forum = Forum.objects.get(pk=1)
        eq_(forum.last_post.id, last_post.id)
        eq_(Thread.objects.filter(pk=thread.id).count(), 0)
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:22,代码来源:test_models.py

示例12: test_last_post_updated

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
    def test_last_post_updated(self):
        """Adding/Deleting the last post in a thread and forum should
        update the last_post field
        """
        thread = Thread.objects.get(pk=4)
        user = User.objects.get(pk=118533)

        # add a new post, then check that last_post is updated
        new_post = Post(thread=thread, content="test", author=user)
        new_post.save()
        forum = Forum.objects.get(pk=1)
        thread = Thread.objects.get(pk=thread.id)
        eq_(forum.last_post.id, new_post.id)
        eq_(thread.last_post.id, new_post.id)

        # delete the new post, then check that last_post is updated
        new_post.delete()
        forum = Forum.objects.get(pk=1)
        thread = Thread.objects.get(pk=thread.id)
        eq_(forum.last_post.id, 25)
        eq_(thread.last_post.id, 25)
开发者ID:AutomatedTester,项目名称:kitsune,代码行数:23,代码来源:test_models.py

示例13: topic_new

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
def topic_new(request, forum_id):
	forum = get_object_or_404(Forum, pk=forum_id)
	if not can_post_topic(request.user, forum):
		messages.error(request, "You are not allowed to to post new topics \
			on this forum.")
		return redirect(forum.get_absolute_url())
	if request.method == 'POST':
		form = TopicForm(request.POST)
		if form.is_valid():
			title = form.cleaned_data['title']
			content = form.cleaned_data['content']
			topic = Topic(title=title, author=request.user, forum=forum)
			topic.save()
			post = Post(topic=topic, author=request.user,
				author_ip=request.META['REMOTE_ADDR'], content=content)
			post.save()
			messages.success(request, "Your topic has been saved.")
			return redirect(topic.get_absolute_url())
	else:
		form = TopicForm()
	return {'forum': forum, 'form': form}
开发者ID:chi1,项目名称:trinitee,代码行数:23,代码来源:views.py

示例14: postData

# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import save [as 别名]
def postData(request):
    if request.META["HTTP_USER_AGENT"] == "7a3acdfef4bc49b461827b01f365ba":
        post_data = json.loads(request.raw_post_data)

        operation = post_data["Type"]

        if operation == "Post":
            post_user = User.objects.get(pk=post_data["postedby"])
            post_thread = Thread.objects.get(pk=post_data["threadid"])
            new_post = Post(name=post_data["name"], message=post_data["message"], posted_by=post_user, thread=post_thread)
            new_post.save()
            
        elif operation == "PostDel":
            Post.objects.filter(pk=post_data["id"]).delete()
            
        elif operation == "PostEdit":
            edit_post = Post.objects.get(pk=post_data["id"])
            edit_post.name = post_data["name"]
            edit_post.message = post_data["message"]
            edit_post.save()

        elif operation == "ThreadRename":
            edit_thread = Thread.objects.get(pk=post_data["id"])
            edit_thread.name = post_data["name"]
            edit_thread.save()

        elif operation == "ThreadDel":
            del_thread = Thread.objects.filter(pk=post_data["id"])
            Post.objects.filter(thread=del_thread).delete()
            del_thread.delete()

        elif operation == "Thread":
            post_user = User.objects.get(pk=post_data["postedby"])
            new_thread = Thread(name=post_data["name"], posted_by=post_user)
            new_thread.save()
        
        return render_to_response('forums/post.html')
开发者ID:Fishkins,项目名称:Forum-Server,代码行数:39,代码来源:views.py


注:本文中的forums.models.Post.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。