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


Python Post.save方法代码示例

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


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

示例1: add_post

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def add_post(request, post_id=None):
    if post_id:
        post = get_object_or_404(Post, pk=post_id)
        if post.author != request.user:
            return HttpResponseForbidden("Only owner of this post is allowed to edit")
    else:
        post = Post(author=request.user)

    if request.method == 'POST':  # If the form has been submitted...
        form = PostForm(request.POST, instance=post)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            text = form.cleaned_data['content']
            html = markdown(text)
            post.title = form.cleaned_data['title']
            post.content = html
            post.tagnames = form.cleaned_data['tagnames']
            post.save()
            return HttpResponseRedirect('/')
    else:
        # An unbound form
        form = PostForm(instance=post)

    return render(request, 'new_post.html', {
        'form': form,
        'post_id': post_id,
    })
开发者ID:caogecym,项目名称:muer,代码行数:28,代码来源:views.py

示例2: newthread

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (LOGIN_URL, request.path))

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(forum=f, title=form.cleaned_data["title"])
            t.save()

            p = Post(thread=t, author=request.user, body=form.cleaned_data["body"], time=datetime.now())
            p.save()

            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response("forum/newthread.html", RequestContext(request, {"form": form, "forum": f}))
开发者ID:incuna,项目名称:django-forum-pinax,代码行数:32,代码来源:views.py

示例3: reply

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (LOGIN_URL, request.path))
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data["body"]
            p = Post(thread=t, author=request.user, body=body, time=datetime.now())
            p.save()

            # Send notifications (if installed)
            if notification:
                notification.send(
                    User.objects.filter(forum_post_set__thread=t).distinct(),
                    "forum_new_reply",
                    {"post": p, "thread": t, "site": Site.objects.get_current()},
                )

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response(
        "forum/reply.html", RequestContext(request, {"form": form, "forum": t.forum, "thread": t})
    )
开发者ID:incuna,项目名称:django-forum-pinax,代码行数:37,代码来源:views.py

示例4: showtopic

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def showtopic(request, gurl_number, turl_number):
    group = Group.objects(url_number=gurl_number).get()
    topic = Topic.objects(url_number=turl_number).get()
    topic.clicks += 1
    topic.save()
    if request.method == "POST":
        form = NewPostForm(request.POST)
        if form.is_valid():
            content = form.cleaned_data["content"]
            post = Post(content=content)
            post.author = request.user
            post.creat_time = datetime.datetime.now()
            post.floor = Post.objects(topic=topic).count() + 1
            post.topic = topic
            post.is_active = True
            post.save()
            topic.update_author = request.user
            topic.update_time = datetime.datetime.now()
            topic.save()
            return HttpResponseRedirect("/group/" + str(gurl_number) + "/topic/" + str(turl_number) + "/")

    else:
        form = NewPostForm()
        return render_to_response(
            "group/group_topic.html",
            {"group": group, "current_user": request.user, "form": form, "topic": topic, "STATIC_URL": STATIC_URL},
            context_instance=RequestContext(request),
        )
开发者ID:pgwt,项目名称:COC,代码行数:30,代码来源:views.py

示例5: new_topic

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def new_topic(request):
    user = request.user
    if request.method == 'POST':
        form = NewTopicForm(request.POST)

        if form.is_valid():
            category = form.cleaned_data['category']
            topic = Topic(title=form.cleaned_data['title'],
                          author=user,
                          category=category
            )
            topic.save()

            first_post = Post(topic=topic,
                              author=user,
                              date_published=topic.date_published,
                              content=form.cleaned_data['content'])
            first_post.save()
            return HttpResponseRedirect(topic.get_absolute_url())
    else:
        form = NewTopicForm()

    return render(request, 'xadmin/new_topic.html', {
        'form': form
    })
开发者ID:csimstu,项目名称:cornucopia,代码行数:27,代码来源:views.py

示例6: post_reply

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def post_reply(request, topic_id):
    form = PostForm()
    topic = Topic.objects.get(pk=topic_id)
    user = request.user

    if topic.closed:
        return render(request, 'personal/basic.html', {'content':['This topic is closed.']})

    if topic.forum.closed and not user.has_perm('forum.can_post_lock_forum'):
        return render(request, 'personal/basic.html', {'content':['This forum is locked.']})

    if request.method == 'POST':
        form = PostForm(request.POST)

        if form.is_valid():

            post = Post()
            post.topic = topic
            post.title = 'RE: '+topic.title
            post.body = bleach_clean(form.cleaned_data['body'])
            post.creator = request.user
            post.user_ip = get_client_ip(request)

            post.save()

            return HttpResponseRedirect(reverse('topic-detail', args=(topic.id, topic.slug, )))

    return render_to_response('forum/reply.html', {
            'form': form,
            'topic': topic,
            'forum': topic.forum,
            'editing': False,
        }, context_instance=RequestContext(request))
开发者ID:LunaSquee,项目名称:lunasqu.ee-django,代码行数:35,代码来源:views.py

示例7: save

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
    def save(self, commit=True):
        if not self.topic:
            # if this post create new topic, create this corresponding topic
            topic = Topic(forum=self.forum,
                          title=escape(self.cleaned_data['title']),
                          created_by=self.user,
                          updated_by=self.user)
            topic.save()
            self.topic = topic
            topic_post = True
        else:
            topic = self.topic
            topic_post = False

        post = Post(topic=topic,
                    created_by=self.user,
                    updated_by=self.user,
                    topic_post=topic_post,
                    content=self.cleaned_data['content'],
                    reply_on=self.parent)
        post.topic = topic
        if commit:
            post.save()
            if topic_post:
                topic.post = post
                topic.content = post.content
                topic.save()

        return post
开发者ID:chequochuu,项目名称:vnoiwebsite,代码行数:31,代码来源:forms.py

示例8: _topic_create_POST

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def _topic_create_POST(request):
    commit = True
    try:
        post = Post(author=request.forum_user)
        post_form = PostForm(request.POST, instance=post)
        if post_form.is_valid():
            post = post_form.save()
            topic = Topic(author=request.forum_user, first_post=post,
                    last_post=post)
            topic_form = TopicForm(request.POST, instance=topic)
            if topic_form.is_valid():
                topic = topic_form.save()
                post.topic = topic
                post.save()
                for category in topic.categories.all():
                    category.topic_count = category.topic_set.all().count()
                    category.post_count = Post.objects\
                            .filter(topic__in=category.topic_set.all()).count()
                    category.save()
                return redirect(post.get_absolute_url())
        else:
            post_form = PostForm(request.POST)
        ctx = {
            'forum_user': request.forum_user,
            'topic_form': topic_form,
            'post_form': post_form,
        }
        return render(request, 'forum/topic/create.html', ctx)

    finally:
        if commit:
            transaction.commit()
        else:
            transaction.rollback()
开发者ID:archlinuxpl,项目名称:2.archlinux.pl,代码行数:36,代码来源:views.py

示例9: newthread

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    f = get_object_or_404(Forum, slug=forum)
    t = Thread(
        forum=f,
        title=request.POST.get('title'),
    )
    t.save()
    p = Post(
        thread=t,
        author=request.user,
        body=request.POST.get('body'),
        time=datetime.now(),
    )
    p.save()
    if request.POST.get('subscribe',False):
        s = Subscription(
            author=request.user,
            thread=t
            )
        s.save()
    return HttpResponseRedirect(t.get_absolute_url())
开发者ID:tristan,项目名称:hydrant,代码行数:32,代码来源:views.py

示例10: addPost

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def addPost(request):
	if request.user.is_authenticated():
		#Gets all the userinput data. And the hidden input fields that contains the ID's of the forum and thread the user is located in.
		postContent = request.GET['postContent']
		forum_key = request.GET['forum_key']
		thread_key = request.GET['thread_key']
		
		#A cleaner that scans trough the thread description the users typed in and replaces the \n line breakers with html linebreakers (<br>)
		cleanPost = ""
		for a in postContent:
			if a in '\n':
				a += r'<br>'
			cleanPost += a
		#Creates a instance of a user so the Thred is bound to a creator.
		user = User.objects.get(username__exact=request.user.username)	
		key_forum = Forum.objects.get(id=forum_key)
		key_thread = Thread.objects.get(id=thread_key, key_forum=forum_key)
		
		#creates a new insance of Post, inserts the values and finaly saves them.
		newPost = Post(content=cleanPost, displays=0, author= user, key_forum=key_forum, key_thread=key_thread )
		newPost.save()
		bool = True
		return HttpResponseRedirect(reverse('forum.views.viewPosts', args=(forum_key,thread_key)))	
	else:
		bool = False
		return HttpResponseRedirect(reverse('forum.views.viewForum'))
开发者ID:hellotheremike,项目名称:django-forum,代码行数:28,代码来源:add.py

示例11: newthread

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def newthread(request, forum):
    """
    新建帖子
    """
    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return Http404

    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(
                forum=f,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()

            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response('forum/newthread.html',
                              RequestContext(request, {'form': form,
                                                       'forum': f,
                                                       }))
开发者ID:lty1,项目名称:platform_django,代码行数:36,代码来源:views.py

示例12: reply

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def reply(request, thread):
    """
    回复帖子子
    条件:
    1、帖子允许回复,没有关闭
    2、当前用户登录
    """
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return Http404
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return Http404

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t, 
                author=request.user,
                body=body,
                time=datetime.now(),
                )
            p.save()

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response('forum/reply.html',
                              RequestContext(request, {'form': form,
                                                       'forum': t.forum,
                                                       'thread': t,
                                                       }))
开发者ID:lty1,项目名称:platform_django,代码行数:36,代码来源:views.py

示例13: setUp

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
 def setUp(self):
     self.setUpProfile()
     blog = Blog(active = True, owner = self.user, name = "Tester's blog")
     blog.save()
     tag = Tag(name = "test tag")
     tag.save()
     post = Post(owner = self.user, title = "Title", text = "This is test text", blog = blog)
     post.save()
     post.tags = [tag]
     post.save()
开发者ID:brezerk,项目名称:taverna,代码行数:12,代码来源:tests.py

示例14: create_post

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
 def create_post(self, author, thread):
     new_post = Post(
         content = self.cleaned_data.get('content'),
         thread = thread,
         author = author,
         created = datetime.datetime.now(),
     )
     new_post.save()
     thread.most_recent_post = new_post
     thread.save()
     return new_post
开发者ID:Oscarchase,项目名称:Intra-Django,代码行数:13,代码来源:forms.py

示例15: mkpost

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import save [as 别名]
def mkpost(content="Test post.",
           creation_date=datetime.datetime.now()):
    """Helper function for making posts."""
    p = Post()

    # _plain == _html, since the conversion happens in views.py,
    # which the object creation is not run through
    p.content_plain, p.content_html = content, content
    p.creation_date = creation_date
    p.author = mkuser()
    p.thread = mkthread()
    p.save()

    return p
开发者ID:FashtimeDotCom,项目名称:pony-forum,代码行数:16,代码来源:model_tests.py


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