开发者

Django threaded comments - one level only

I'm looking at implementing django-threadedcomments and am wondering if it is able to restrict threading to replies made by a moderator/owner, similar to how Yelp handles user reviews and business owner replies.

For example the comments would look like:

"Comment 1" by User1

"Comment 2" by User2

          "Reply 1" by Owner

"Comment 3" by User3

          "Reply 2" by Owner

"Comment 4" by User4

"Comment 5" by User5

Ho开发者_JS百科w would you do this in django-threadedcomments? Alternatively if you've done this using the built-in comments framework I'm open to doing it that way as well.


I'm currently working on a small CMF based on Django and I've implemented threaded comments there which seems to work fine. You can grab the latest source at http://github.com/kovshenin/Juice The module you're interested in is juice.comments. The threading is illustrated in the news-single.html template which is called from the juice.front.views.single view. Note the level and indent parameters which are passed to the template:

# comments
p.comments = Comment.tree.filter(content_type__pk=ctype.id, object_id=p.id)

for c in p.comments:
    c.indent = c.level * 50

The p object is of type Post which is passed on to the template.

Now, regarding restricting threading to other people than the admin/owner. In that same view I illustrate how to process the commenting form, where you can clearly see that I'm looking for the parent comment if one is supplied. You'll have to add some logics there and check for current user login and his privileges, and if they're not set, use parent = NULL. In the template just hide the reply link ;)

Hope that helps, and beware that I'm constantly working on this project, 5-10 commits every day, so keep an eye on what source you download. The documentation currently contains only the way posts are handled (already partly outdated), but I'll be updating that constantly.

Cheers.


In case anyone else is looking for this, I was able to do this in django-threadedcomments by using the PARENT_ID in the

{% render_comment_form for [object] with [parent_id] %}

template tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜