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


Python Post.body方法代码示例

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


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

示例1: post_reply

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

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

示例3: reply

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import body [as 别名]
def reply(request, thread, extra_context=None):
    """
    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.
    """
    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()

    preview = False
    p = None

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

            if not preview:
                return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()
    
    return render_to_response('forum/reply.html',
        RequestContext(request, {
            'form': form,
            'forum': t.forum,
            'post': p,
            'preview': preview,
            'thread': t,
        }))
开发者ID:funkbit,项目名称:django-forum-simple,代码行数:43,代码来源:views.py

示例4: post_reply

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

示例5: new_topic

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

示例6: reply

# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import body [as 别名]
def reply(request, thread, extra_context=None):
    """
    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.
    """
    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()

    preview = False
    p = None

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

                sub = Subscription.objects.filter(thread=t, author=request.user)
                if form.cleaned_data.get('subscribe',False):
                    if not sub:
                        s = Subscription(
                            author=request.user,
                            thread=t
                            )
                        s.save()
                else:
                    if sub:
                        sub.delete()

            # this needs refactorings

            if not preview and t.subscription_set.count() > 0:
                # Subscriptions are updated now send mail to all the authors subscribed in
                # this thread.
                mail_subject = ''
                try:
                    mail_subject = settings.FORUM_MAIL_PREFIX 
                except AttributeError:
                    mail_subject = '[Forum]'

                mail_from = ''
                try:
                    mail_from = settings.FORUM_MAIL_FROM
                except AttributeError:
                    mail_from = settings.DEFAULT_FROM_EMAIL

                mail_tpl = loader.get_template('forum/notify.txt')
                c = Context({
                    'body': wordwrap(striptags(p.body), 72),
                    'site' : Site.objects.get_current(),
                    'thread': t,
                    })

                email = EmailMessage(
                        subject=mail_subject+' '+striptags(t.title),
                        body= mail_tpl.render(c),
                        from_email=mail_from,
                        bcc=[s.author.email for s in t.subscription_set.all()],)
                email.send(fail_silently=True)

            if not preview:
                return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()
    
    return render_to_response('forum/reply.html',
        RequestContext(request, {
            'form': form,
            'forum': t.forum,
            'post': p,
            'preview': preview,
            'thread': t,
        }))
开发者ID:pavanmishra,项目名称:django-forum,代码行数:85,代码来源:views.py


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