Esempio n. 1
0
def view_post(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    sent =  False

    if request.method == 'POST':
        if request.user == post.contact:
            if 'fulfilled' in request.POST:
                return toggle_post(request, post=post)
            else:
                form = PostForm(request.POST, instance=post)
                if form.is_valid():
                    form.save()
                    request.user.message_set.create(
                        message='Your post was updated.')
        elif request.user.is_authenticated():
            form = ReplyForm(request.POST)
            if form.is_valid():
                Reply.objects.create(post=post,
                                     sender=request.user,
                                     content=form.cleaned_data['content'])
                send_reply_email(request, post, form)
                request.user.message_set.create(
                    message='Your reply was sent.')
        else:
            raise Http404()

        if 'next' in request.POST:
            next = request.POST['next']
        else:
            next = reverse('home')
        return HttpResponseRedirect(next)


    if request.user == post.contact:
        p = post.__dict__.copy()
        p['category'] = post.category.pk
        form = PostForm(p)
    elif request.user.is_authenticated():
        form = ReplyForm()
    else:
        form = None

    return render_to_response('view_post.html',
                              RequestContext(request,
                                             {'post': post,
                                              'form': form,
                                              'sent': sent}))
Esempio n. 2
0
def view_post(request, id):
    post = get_object_or_404(Post, pk=id)
    sent =  False
    if request.user.is_authenticated():
        form_class = ReplyForm
    else:
        form_class = UnauthenticatedReplyForm
    if request.method == 'POST':
        form = form_class(request.POST)
        if form.is_valid():
            send_reply_email(request, post, form)
            sent = True
    else:
        form = form_class()
    return render_to_response('view_post.html',
                              RequestContext(request,
                                             {'post': post,
                                              'form': form,
                                              'sent': sent}))