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


Python Post.topic方法代码示例

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


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

示例1: post_reply

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

示例2: showtopic

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

示例3: _topic_create_POST

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

示例4: save

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

示例5: post_reply

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

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

        if form.is_valid():

            post = Post()
            post.topic = topic
            post.title = form.cleaned_data['title']
            post.body = form.cleaned_data['body']

            post.creator = request.user

            userToUpdate = UserProfile.objects.get(user=request.user)

            nCredits = userToUpdate.credits
            userToUpdate.credits = int(float(nCredits + 100))

            # TODO: Change status (if points+100>threshold -> status changes) Alert???
            # Alert? Maybe return to page with status update info for user.
            # Make Gold/Platinum distinction

            if nCredits + 100 >= GOLD_THRESHOLD:
                newStatus = "Gold"
                userToUpdate.status = newStatus
                userToUpdate.save()
                post.user_ip = request.META['REMOTE_ADDR']
                post.save()
                return render_to_response("forum/status_change.html", {'status':  newStatus}, context_instance=RequestContext(request))
            elif nCredits + 100 >= PLATINUM_THRESHOLD:
                newStatus = "Platinum"
                userToUpdate.status = newStatus
                userToUpdate.save()
                post.user_ip = request.META['REMOTE_ADDR']
                post.save()
                return render_to_response("forum/status_change.html", {'status':  newStatus}, context_instance=RequestContext(request))
            else:
                userToUpdate.save()
                post.user_ip = request.META['REMOTE_ADDR']
                post.save()
                return HttpResponseRedirect(reverse('topic-detail', args=(topic.id, )))

    return render_to_response('forum/reply.html', {
        'form': form,
        'topic': topic,
    }, context_instance=RequestContext(request))
开发者ID:atirados,项目名称:CS425-Final-Project,代码行数:51,代码来源:views.py

示例6: post_reply

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

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

        if form.is_valid():

            post = Post()
            post.topic = topic
            post.title = form.cleaned_data['title']
            post.body = form.cleaned_data['body']
            post.creator = request.user
            post.user_ip = request.META['REMOTE_ADDR']

            post.save()

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

    return render_to_response('django_simple_forum/reply.html', {
            'form': form,
            'topic': topic,
        }, context_instance=RequestContext(request))
开发者ID:boyombo,项目名称:pharmrep,代码行数:26,代码来源:views.py

示例7: new_topic

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import topic [as 别名]
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)
    user = request.user
    
    if 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 = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = bleach_clean(form.cleaned_data['description'])
            topic.forum = forum
            topic.creator = user

            topic.save()

            tpkPost = Post()
            tpkPost.topic = topic
            tpkPost.title = topic.title
            tpkPost.body = bleach_clean(form.cleaned_data['description'])
            tpkPost.creator = user
            tpkPost.user_ip = get_client_ip(request)

            tpkPost.save()

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

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


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