Пример #1
0
    def post(self,request,*args,**kwargs):
        form = commentForm(request.POST or None)
        self.object=self.get_object()
        if request.method == "POST":
             if form.is_valid():
                temp = form.save(commit=False)
                temp.post=self.object
                parent = form['parent'].value()

                if parent == '':
                    #Set a blank path then save it to get an ID
                    temp.path = []
                    temp.save()
                    temp.path = [temp.id]
                else:
                    #Get the parent node
                    node = comment.objects.get(id=parent)
                    temp.depth = node.depth + 1
                    temp.path = node.path

                    #Store parents path then apply comment ID
                    temp.save()
                    temp.path.append(temp.id)

                #Final save for parents and children
                temp.save()
        ##comment_tree = comment.objects.all().order_by('path')
        return super(PostWithComment, self).post(request, *args, **kwargs)
Пример #2
0
 def get_context_data(self, **kwargs):
     context = super(PostDetail, self).get_context_data(**kwargs)
     context['form'] = commentForm()
     post=self.object
     comment_tree = post.comment_set.all().order_by('path')
     context['comment_tree']=comment_tree
     return context
Пример #3
0
def init():
    posts = Post.objects.all()
    tag_data = create_tag_data(posts)
    archive_data = create_archive_data(posts)
    form = commentForm()
    pagedata = {
        "version": "1.0",
        "post_list": posts,
        "tag_counts": tag_data,
        "archive_counts": archive_data,
        "form": form,
    }
    return posts, pagedata
Пример #4
0
def custom_pro(request):
    posts = Post.objects.all()
    tag_data = create_tag_data(posts)
    archive_data = create_archive_data(posts)
    form = commentForm()
    user = request.user
    return {
        "version": "1.0",
        "post_list": posts,
        "tag_counts": tag_data,
        "archive_counts": archive_data,
        "form": form,
        "user": user,
    }