Code

Ticket #12871: auth_comments.diff

File auth_comments.diff, 2.0 KB (added by shacker, 4 years ago)

Docs for authenticated comment form

Line 
1Index: docs/ref/contrib/comments/index.txt
2===================================================================
3--- docs/ref/contrib/comments/index.txt (revision 12437)
4+++ docs/ref/contrib/comments/index.txt (working copy)
5@@ -288,6 +288,47 @@
6 
7 .. _honeypot: http://en.wikipedia.org/wiki/Honeypot_(computing)
8 
9+
10+Providing a comment form for authenticated users
11+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12+
13+If a user is already authenticated, it makes little sense to display name, email,
14+and URL fields, since these can already be retrieved from their login data and
15+profile. In addition, some sites will only accept comments from authenticated users.
16+
17+To provide a comment form for authenticated users, build the form manually in your
18+template as above, but manually provide the additional fields expected by the
19+Django comments framework. For example, assuming comments are attached to the model
20+"item"::
21+
22+    {% if user.is_authenticated %}
23+        {% get_comment_form for item as form %}
24+        <form action="{% comment_form_target %}" method="POST">
25+        {% csrf_token %}
26+        {{ form.comment }}
27+        {{ form.honeypot }}
28+        {{ form.content_type }}
29+        {{ form.object_pk }}
30+        {{ form.timestamp }}
31+        {{ form.security_hash }}
32+        <input type="hidden" name="next" value="{% url item_view item.id %}" />
33+        <input type="submit" value="Add comment" id="id_submit" />
34+        </form>
35+    {% else %}
36+        <p>Please <a href="{% url auth_login %}">log in</a> to leave a comment.</p>
37+    {% endif %}
38+
39+In this example, the honeypot field will still be visible to the user; you'll need
40+to hide that field in your CSS::
41+
42+    #id_honeypot {
43+        visibility:hidden;
44+    }
45+
46+If you want to accept either anonymous or authenticated comments, replace the
47+auth_login line above with a standard comment form, and the right thing will happen
48+whether a user is logged in or not.
49+
50 More information
51 ================
52