David Chambers avatar David Chambers committed bb78677

Comments withheld for moderation are now displayed to their authors. Unfortunately the Disqus API appears to return `"shown": true` for all comments, even those awaiting moderation. >.<

Comments (0)

Files changed (3)

templates/comment.dhtml

+{% load mango_extras %}
+					<article>
+						<div>
+							{{ post.message|html|safe }}
+						</div>
+						<footer>
+						{% if post.is_anonymous %}
+							<img alt="" src="{{ post.anonymous_author.email_hash|gravatar }}" />
+							{% if post.anonymous_author.url %}
+							<strong><a href="{{ post.anonymous_author.url }}">{{ post.anonymous_author.name }}</a></strong>
+							{% else %}
+							<strong>{{ post.anonymous_author.name }}</strong>
+							{% endif %}
+						{% else %}
+							<img alt="" src="{{ post.author.email_hash|gravatar }}" />
+							{% if post.author.url %}
+							<strong><a href="{{ post.author.url }}">{% firstof post.author.display_name post.author.username %}</a></strong>
+							{% else %}
+							<strong>{{ post.author.name }}</strong>
+							{% endif %}
+						{% endif %}
+							<time datetime="{{ post.created_at|isoformat }}">
+								<span>{{ post.created_at|display_date }}</span>
+								<span>{{ post.created_at|display_time }}</span>
+							</time>
+						</footer>
+					</article>

templates/post.dhtml

 						{% endfor %}
 						</ol>
 					</footer>
-					{% endif %}{% if num_visible_posts %}
+					{% endif %}{% if num_visible_posts or comment %}
 					<h2 id="comments">Comments</h2>
-					{% for post in thread.posts %}{% if post.shown %}
-					<article>
-						<div>
-							{{ post.message|html|safe }}
-						</div>
-						<footer>
-						{% if post.is_anonymous %}
-							<img alt="" src="{{ post.anonymous_author.email_hash|gravatar }}" />
-							{% if post.anonymous_author.url %}
-							<strong><a href="{{ post.anonymous_author.url }}">{{ post.anonymous_author.name }}</a></strong>
-							{% else %}
-							<strong>{{ post.anonymous_author.name }}</strong>
-							{% endif %}
-						{% else %}
-							<img alt="" src="{{ post.author.email_hash|gravatar }}" />
-							{% if post.author.url %}
-							<strong><a href="{{ post.author.url }}">{% firstof post.author.display_name post.author.username %}</a></strong>
-							{% else %}
-							<strong>{{ post.author.name }}</strong>
-							{% endif %}
-						{% endif %}
-							<time datetime="{{ post.created_at|isoformat }}">
-								<span>{{ post.created_at|display_date }}</span>
-								<span>{{ post.created_at|display_time }}</span>
-							</time>
-						</footer>
-					</article>
-					{% endif %}{% endfor %}{% endif %}{% if thread.allow_comments %}
+					{% for post in thread.posts %}{% if post.shown %}{% include 'comment.dhtml' %}{% endif %}{% endfor %}{% if comment %}{{ comment }}
+					<p>Your comment is awaiting moderation.</p>
+					{% endif %}{% endif %}{% if thread.allow_comments %}
 					<h3 id="respond">Respond</h3>
 					<form method="post">
 						<fieldset id="author-details">
 from django.core.mail import send_mail
 from django.http import Http404, HttpResponse, HttpResponseRedirect
 from django.shortcuts import render_to_response
+from django.template import Context, loader
 from django.template.loader import render_to_string
 from django.core.urlresolvers import reverse
 from mango import settings, utils
         thread = None
         num_total_posts = 0
         num_visible_posts = 0
+        comment = request.session.get('comment')
+        if comment:
+            del request.session['comment']
+            t = loader.get_template('comment.dhtml')
+            comment = t.render(Context({'post': comment}))
 
         def get_forum(forums):
             shortname = DISQUS['shortname']
                         subscribe = form.cleaned_data['subscribe']
 
                         # send request to Disqus
-                        dsq.create_post(forum=forum, thread=thread, message=message,
+                        comment = dsq.create_post(forum=forum, thread=thread, message=message,
                                 author_name=author_name, author_email=author_email, author_url=author_url)
 
+                        if DISQUS.get('pre-moderation'):
+                            # store comment so that it can be displayed to the author even if withheld for moderation
+                            request.session['comment'] = comment
+
                         # send e-mail notification
                         author = u'%s <%s>' % (author_name, author_email)
                         subject = u'[%s] Comment: "%s"' % (SITE_TITLE.decode('utf-8'), context['meta']['title'])
                     pass 
 
         return render_to_string('post.dhtml', dict(context, **dict({
+                    'comment': comment,
                     'form': form,
                     'num_visible_posts': num_visible_posts,
                     'short_url': short_url,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.