예제 #1
0
    def change_view(self, request, object_id, extra_context=None):
        """Deal with custom editing
        """

        from django_mises import comments

        data = request.POST.copy() or None

        obj = models.Post.objects.get(id=object_id)

        internal_comments = comments.get_model().objects.for_model(obj).select_related(depth=1).filter(comment_type='internal').order_by('id')

        ## Handle our data, let the rest flow over
        comment_form = comments.get_internal_form()(obj, data)
        context = {
            'comments': internal_comments,
            'comment_form': comment_form,
        }

        if data is not None:
            if data.has_key('internal_comment'):

                if comment_form.is_bound:
                    if comment_form.is_valid():
                        ## Do not allow tampering
                        comment_form.cleaned_data['user'] = request.user

                        comment = comment_form.save()

        ## Maybe redirect out, maybe complain
        return super(PostAdmin, self).change_view(request, object_id, extra_context=context)
예제 #2
0
def post(request, post_id, slug=None, preview=False):
    """Index view
    """

    data = request.POST.copy() or None

    import datetime

    now = datetime.datetime.now()

    if preview:
        post = get_object_or_404(blog_models.Post, id=post_id, slug=slug)
    else:
        post = get_object_or_404(blog_models.Post, id=post_id, publish_at__lte=now)

    comments_ = comments.get_model().objects.for_model(post).select_related(depth=1).filter(comment_type='external').order_by('id')

    comment_form = comments.get_external_form()(post, data)

    if comment_form.is_bound:
        if comment_form.is_valid():
            ## Ensure the correct user
            comment_form.cleaned_data['user'] = request.user
            comment_form.save()

            return HttpResponseRedirect(request.META['PATH_INFO'])

    context = {
        'post': post,
        'title': post.title,
        'comments': comments_,
        'comment_form': comment_form,
    }
    req_ctx = RequestContext(request, context)

    return render_to_response('post.html', req_ctx)