This app had been on my todo list for a long time. Today, no matter how much I tried to procrastinate, I could not ignore it and hence decided to scratch my itch and get it done. I swore I wouldn't even get up for a glass of water until it was done. Luckily, this took lesser time than I anticipated and I was spared of breaking my resolve!
There are certain sites that require only authenticated users to post comments, this app specifically targets such cases.
It builds on my previous posts sans the javascript hack. To make the code very condense and easy to use, it uses "Two-phased template rendering" that I saw in Ella via Adrian Holovaty's post. From a security point, it auto-escapes django template code injected in through the comments in the middleware.
TEMPLATE_CONTEXT_PROCESSORS=(
"django.core.context_processors.auth",
"django.core.context_processors.request",
"django.core.context_processors.media"
)
(r'^comment/', include('django.contrib.comments.urls')),
{% load auth_comments %}
...
{% render_auth_comment_form for app.model object_pk %}
This code is equivalent to
{% if request.user.is_authenticated %}
{% render_comment_form for app.model object_pk %}
{% else %}
Some standard message to be shown if user not logged in.
{% endif %}
The standard message is picked up from the DEFAULT_UNAUTH_COMMENT_MESSAGE attribute of settings.py which you can set to override the default message.
If you liked the app, do let me know. Also please fork and improve the code if you wish to improve it.
Great, exactly what I was looking for ! I only wonder if this can used in conjunction with threaded_comments somehow ? Boris
Theju to the rescue! (hey, I wouldn't know how to write a wrapper either :) Note: This app throws : Invalid block tag: 'csrf_token' with Django 1.1.1. Guess this is a good time to try out 1.2 beta. Yep, that works after adding 'django.middleware.csrf.CsrfViewMiddleware', to MIDDLEWARE_CLASSES. Might want to mention the 1.2 requirement in the docs. Question: How can we control the redirect URL (return to the original view) with this app? The Django docs say to insert a hidden field but that doesn't seem possible here. Thanks.
Yashh commented on 7th August 2009 09:44
You rock man. You have a great will power. Looking forward to your admin-integration for coucdb and other things... :)