Example #1
0
def delete_post(request, postid):
    """
    Delete the nth post where n = postId entered from the user url
    """
    global cnt_delete
    context = {}

    if Post.exists(postid):
        try:
            fetch = Post.getPostByID(postid)
            if fetch:
                message = 'Post %d Deleted!' %(int(postid))
                fetch.delete()

                request.session['delete'] = True
                cnt_delete = count_session(request, 'delete', cnt_delete)
        except ValueError:
            raise Http404()

        return HttpResponseRedirect('/myblog/')
    else:
        msg = 'Nothing to delete!'
        ss_start = session_start_date(request)
        context = {}
        context.update(csrf(request))
        context = {'message': msg,
                   'sessionStartTime' : ss_start,
                   'sessionStat' : get_sessions(),
                   }

    res = render_to_response('../../Pythonidae/templates/index.html',
                             context,
                             context_instance=RequestContext(request))
    return res
Example #2
0
def delete_post(request, postid):
    """
    Delete the nth post where n = postId entered from the user url
    """
    context = {}
    if Post.exists(postid):
        queryset = Post.getPostByID(postid)
        if queryset:
            if queryset.author == request.user:
                message = 'Post %d Deleted!' %(int(postid))
                queryset.delete()
                return HttpResponseRedirect('/myblog/')
            else:
                return render_to_response('index.html',
                              {'message':  "You can only delete your blog posts."},
                              context_instance=RequestContext(request))
    else:
        context = {}
        context.update(csrf(request))
        context = {'message': "Nothing to delete!"}

    return render_to_response('index.html',
                             context,
                             context_instance=RequestContext(request))