summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-11-13 13:22:07 -0500
committerluxagraf <sng@luxagraf.net>2014-11-13 13:22:07 -0500
commite2f9e4ff3e3443a6875592d823e4e5739a3b7bd1 (patch)
tree8ef5055ae9ef49ffb15476838655c2f001ac50d8
parenta44f67ef290e120736cf881b326eb5145a3d66f7 (diff)
Turned comments back on. See how this goes.
-rw-r--r--app/blog/models.py17
-rw-r--r--app/lib/templatetags/templatetags/gravatar_local.py20
-rw-r--r--app/lib/templatetags/templatetags/markdown.py9
-rw-r--r--app/lib/templatetags/templatetags/nofollow.py15
-rw-r--r--design/sass/_writing_details.scss20
-rw-r--r--design/templates/comments/base.html18
-rw-r--r--design/templates/comments/comment.html32
-rw-r--r--design/templates/comments/comment_notification_email.txt23
-rw-r--r--design/templates/comments/deleted.html15
-rw-r--r--design/templates/comments/flagged.html15
-rw-r--r--design/templates/comments/form.html43
-rw-r--r--design/templates/comments/list.html36
-rw-r--r--design/templates/comments/posted.html46
-rw-r--r--design/templates/comments/preview.html52
-rw-r--r--design/templates/details/entry.html43
15 files changed, 222 insertions, 182 deletions
diff --git a/app/blog/models.py b/app/blog/models.py
index 4ad6022..1b828fe 100644
--- a/app/blog/models.py
+++ b/app/blog/models.py
@@ -194,12 +194,27 @@ from django_gravatar.helpers import get_gravatar_url, has_gravatar, get_gravatar
from django.dispatch import receiver
from django_comments.signals import comment_was_posted
from django_comments import Comment
+from django_comments.moderation import CommentModerator, moderator
+
+class EntryModerator(CommentModerator):
+ '''
+ Moderate everything except people with multiple approvals
+ '''
+ email_notification = True
+
+ def moderate(self, comment, content_object, request):
+ previous_approvals = Comment.objects.filter(user_email=comment.email, is_public=True).count()
+ if previous_approvals > 2:
+ return False
+ #do entry build right here so it goes to live site
+ return True
+
+moderator.register(Entry, EntryModerator)
@receiver(comment_was_posted, sender=Comment)
def cache_gravatar(sender, comment, **kwargs):
gravatar_exists = has_gravatar(comment.email)
grav_dir = settings.IMAGES_ROOT + '/gravcache/'
- print(gravatar_exists)
if gravatar_exists:
url = get_gravatar_url(comment.email, size=60)
if not os.path.isdir(grav_dir):
diff --git a/app/lib/templatetags/templatetags/gravatar_local.py b/app/lib/templatetags/templatetags/gravatar_local.py
new file mode 100644
index 0000000..985ed03
--- /dev/null
+++ b/app/lib/templatetags/templatetags/gravatar_local.py
@@ -0,0 +1,20 @@
+from django import template
+from django.utils.html import escape
+
+from django_gravatar.helpers import calculate_gravatar_hash
+
+# Get template.Library instance
+register = template.Library()
+
+def gravatar_hash(user_or_email):
+ if hasattr(user_or_email, 'email'):
+ email = user_or_email.email
+ else:
+ email = user_or_email
+ try:
+ #return get_gravatar_profile_url(email)
+ return calculate_gravatar_hash(email)
+ except:
+ return ''
+
+register.simple_tag(gravatar_hash)
diff --git a/app/lib/templatetags/templatetags/markdown.py b/app/lib/templatetags/templatetags/markdown.py
new file mode 100644
index 0000000..dca51f2
--- /dev/null
+++ b/app/lib/templatetags/templatetags/markdown.py
@@ -0,0 +1,9 @@
+from django import template
+import markdown2 as markdown
+
+register = template.Library()
+
+def do_markdown(text):
+ return markdown.markdown(text, safe_mode = False)
+
+register.filter('markdown', do_markdown) \ No newline at end of file
diff --git a/app/lib/templatetags/templatetags/nofollow.py b/app/lib/templatetags/templatetags/nofollow.py
new file mode 100644
index 0000000..85fc166
--- /dev/null
+++ b/app/lib/templatetags/templatetags/nofollow.py
@@ -0,0 +1,15 @@
+from django.template import Library
+import re
+
+register = Library()
+
+r_nofollow = re.compile('<a (?![^>]*nofollow)')
+s_nofollow = '<a rel="nofollow" '
+
+def nofollow(value):
+ return r_nofollow.sub(s_nofollow, value)
+
+register.filter(nofollow)
+
+
+re.compile('<a (?![^>]*rel=["\']nofollow[\'"])')
diff --git a/design/sass/_writing_details.scss b/design/sass/_writing_details.scss
index 09fc6bb..b327b19 100644
--- a/design/sass/_writing_details.scss
+++ b/design/sass/_writing_details.scss
@@ -329,8 +329,26 @@ display: block;
border-radius: .25em;
padding: 8px 12px 7px;
}
+ blockquote {
+ margin: 3em 0;
+ p {
+ @include fontsize(18);
+ }
+ }
+ h2, h3 { text-align: left}
+}
+.comment--form--header-h1 {
+ @include breakpoint(delta) {
+ text-align: left;
+ margin-left: 30%;
+ @include fontsize(24);
+ }
+}
+.cform-arc {
+ @include breakpoint(delta) {
+ margin-left: 30%;
+ }
}
-
// ##############################################
// On double and double-dark make the top wide
diff --git a/design/templates/comments/base.html b/design/templates/comments/base.html
index d4382ce..9828ff6 100644
--- a/design/templates/comments/base.html
+++ b/design/templates/comments/base.html
@@ -1,8 +1,10 @@
-{% extends 'base.html' %}
-{% block headtitle %}{% block title %}{% trans "Responses for page" %}{% endblock %}{% endblock %}
-
-{% block main %}
- <div id="comments-wrapper">
- {% block content %}{% endblock %}
- </div>
-{% endblock %}
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>{% block title %}{% endblock %}</title>
+</head>
+<body>
+ {% block content %}{% endblock %}
+</body>
+</html>
diff --git a/design/templates/comments/comment.html b/design/templates/comments/comment.html
deleted file mode 100644
index 475775d..0000000
--- a/design/templates/comments/comment.html
+++ /dev/null
@@ -1,32 +0,0 @@
-{% comment %}
- Something that django.contrib.comments does not provide:
- An individual template for a single comment, to easily be reused.
-
- This include is also used by the Ajax comments view.
- The div id should be "c{id}", because the comment.get_absolute_url() points to it.
-
- NOTE: to override the displayed date format, don't replace this template.
- Instead, define DATETIME_FORMAT in a locale file. Requires setting:
-
- FORMAT_MODULE_PATH = 'settings.locale'
-
- Then create 'settings/locale/XY/formats.py' with:
-
- DATETIME_FORMAT = '...'
-
- This should give you consistent dates across all views.
-{% endcomment %}
-{% load i18n %}
- <div {% if preview %} id="comment-preview"{% else %} id="comment{{ comment.id }}"{% endif %} class="p-comment h-cite u-in-reply-to comment--item {% if comment.url == "http://lux.me/" %}comment--me{%endif%}">
- {% if preview %}<h3>{% trans "Preview of your comment" %}</h3>{% endif %}
- <h6 class="p-author h-card comment--author">
- {% if comment.url %}{%if comment.url == "http://lux.me/"%}<a href="/">{%else%}<a href="{{ comment.url }}" rel="nofollow">{% endif %}{% endif %}
- {% if comment.name %}{{ comment.name }}{% else %}{% trans "Anonymous" %}{% endif %}{% comment %}
- {% endcomment %}{% if comment.url %}</a>{% endif %}
- {% if not comment.is_public %}<span class="comment-moderated-flag">({% trans "moderated" %})</span>{% endif %}
- {% if USE_THREADEDCOMMENTS and not preview %}<a href="#c{{ comment.id }}" data-comment-id="{{ comment.id }}" class="comment-reply-link">{% trans "reply" %}</a>{% endif %}
- </h6>
- <a class="comment--datelink" href="#comment{{comment.id}}"><time datetime="{{comment.submit_date|date:'c'}}" class="dt-updated">{% blocktrans with submit_date=comment.submit_date %}{{ submit_date }}{% endblocktrans %}</time></a>
-
- <div class="e-content comment--content">{{ comment.comment|linebreaks }}</div>
- </div>
diff --git a/design/templates/comments/comment_notification_email.txt b/design/templates/comments/comment_notification_email.txt
index 9dfb821..63f1493 100644
--- a/design/templates/comments/comment_notification_email.txt
+++ b/design/templates/comments/comment_notification_email.txt
@@ -1,20 +1,3 @@
-{% load url from future %}{% autoescape off %}{% comment %}
-{% endcomment %}A new comment has been posted on your site "{{ site }}, to the page entitled "{{ content_object }}".
-Link to the page: http://{{ site.domain }}{{ content_object.get_absolute_url }}
-
-IP-address: 95.97.240.121{% if comment.title %}
-Title: {{ comment.title }}{% endif %}
-Name: {{ comment.user_name|default:comment.user }}
-Email: {{ comment.user_email }}
-Homepage: {{ comment.user_url }}
-Moderated: {{ comment.is_public|yesno:'no,yes' }}
-
-Comment:
-{{ comment.comment }}
-
-----
-You have the following options available:
- View comment -- http://{{ site.domain }}{{ comment.get_absolute_url }}
- Flag comment -- http://{{ site.domain }}{% url 'comments-flag' comment.pk %}
- Delete comment -- http://{{ site.domain }}{% url 'comments-delete' comment.pk %}
-{% endautoescape %} \ No newline at end of file
+A comment has been posted on {{ content_object }}.
+The comment reads as follows:
+{{ comment }}
diff --git a/design/templates/comments/deleted.html b/design/templates/comments/deleted.html
index c62a1ff..e608481 100644
--- a/design/templates/comments/deleted.html
+++ b/design/templates/comments/deleted.html
@@ -3,19 +3,6 @@
{% block title %}{% trans "Thanks for removing" %}.{% endblock %}
-{% block extrahead %}
- {{ block.super }}
- <meta http-equiv="Refresh" content="5; url={{ comment.content_object.get_absolute_url }}#c{{ comment.id }}" />
-{% endblock %}
-
{% block content %}
- <h2>{% trans "Thanks for removing the comment" %}</h2>
- <p>
- {% blocktrans %}
- Thanks for taking the time to improve the quality of discussion on our site.<br/>
- You will be sent back to the article...
- {% endblocktrans %}
- </p>
-
- <p><a href="{{ comment.content_object.get_absolute_url }}#c{{ comment.id }}">{% trans "Back to the article" %}</a></p>
+ <h1>{% trans "Thanks for taking the time to improve the quality of discussion on our site" %}.</h1>
{% endblock %}
diff --git a/design/templates/comments/flagged.html b/design/templates/comments/flagged.html
index bebc151..e558019 100644
--- a/design/templates/comments/flagged.html
+++ b/design/templates/comments/flagged.html
@@ -3,19 +3,6 @@
{% block title %}{% trans "Thanks for flagging" %}.{% endblock %}
-{% block extrahead %}
- {{ block.super }}
- <meta http-equiv="Refresh" content="5; url={{ comment.content_object.get_absolute_url }}#c{{ comment.id }}" />
-{% endblock %}
-
{% block content %}
- <h2>{% trans "Thanks for flagging the comment" %}</h2>
- <p>
- {% blocktrans %}
- Thanks for taking the time to improve the quality of discussion on our site.<br/>
- You will be sent back to the article...
- {% endblocktrans %}
- </p>
-
- <p><a href="{{ comment.content_object.get_absolute_url }}#c{{ comment.id }}">{% trans "Back to the article" %}</a></p>
+ <h1>{% trans "Thanks for taking the time to improve the quality of discussion on our site" %}.</h1>
{% endblock %}
diff --git a/design/templates/comments/form.html b/design/templates/comments/form.html
index f8bb18d..776a543 100644
--- a/design/templates/comments/form.html
+++ b/design/templates/comments/form.html
@@ -1,18 +1,25 @@
-{% load comments i18n crispy_forms_tags fluent_comments_tags %}{% load url from future %}
-
-{% if not form.target_object|comments_are_open %}
- <p>{% trans "Comments are closed." %}</p>
-{% else %}
- <form action="{% comment_form_target %}" method="post" class="js-comments-form comments-form form-horizontal"
- data-ajax-action="{% url 'comments-post-comment-ajax' %}">{% csrf_token %}
- {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
-
- {{ form|crispy }}
-
- <div class="form-actions">
- <input type="submit" name="post" class="btn btn-primary" value="{% trans "Post" %}" />
- <input type="submit" name="preview" class="btn" value="{% trans "Preview" %}" />
- {% ajax_comment_tags %}
- </div>
- </form>
-{% endif %} \ No newline at end of file
+{% load comments i18n %}
+<div class="comment--form--wrapper">
+<p class="comment--form--header">Comments?</p>
+<form action="{% comment_form_target %}" method="post" class="comment--form">{% csrf_token %}
+ {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
+<input type="hidden" name="rder" value="{{ form.instance.content_object.get_absolute_url }}" />
+ {% for field in form %}
+ {% if field.is_hidden %}
+ <div>{{ field }}</div>
+ {% else %}
+ {% if field.errors %}{{ field.errors }}{% endif %}
+ <p
+ {% if field.errors %} class="error"{% endif %}
+ {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
+ {{ field.label_tag }} {{ field }}
+ </p>
+ {% endif %}
+ {% endfor %}
+ <p class="submit">
+ <input type="submit" name="post" class="submit-post" value="{% trans "Post" %}" />
+ <input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
+ </p>
+</form>
+<p style="font-size: 95%;"><strong>All comments are moderated</strong>, so you won&#8217;t see it right away. If we&#8217;re on the road sometimes it takes a few days, but we&#8217;ll get it up as soon as we can. You can use Markdown or HTML to format your comments. The allowed tags are <code>&lt;b&gt;, &lt;i&gt;, &lt;em&gt;, &lt;strong&gt;, &lt;a&gt;</code>. To create a new paragraph hit return twice. Remember Kurt Vonnegut's rule: &#8220;god damn it, you&#8217;ve got to be kind.&#8221;</p>
+</div>
diff --git a/design/templates/comments/list.html b/design/templates/comments/list.html
index c105279..378145e 100644
--- a/design/templates/comments/list.html
+++ b/design/templates/comments/list.html
@@ -1,14 +1,22 @@
-{% comment %}
-
- Since we support both flat comments, and threadedcomments,
- the 'fluent_comments_list' templatetag loads the proper template.
-
- It either loads:
- - fluent_comments/templatetags/flat_html.html
- - fluent_comments/templatetags/threaded_list.html
-
- Both reuse comments/comment.html eventually.
- To style comments, consider overwriting that template.
-
-{% endcomment %}
-{% load fluent_comments_tags %}{% fluent_comments_list %}
+{% load gravatar_local %}
+{% load markdown%}
+{% load bleach_tags %}
+{% load nofollow %}
+{% load comments %}
+ <div class="comments--wrapper">
+ {% for comment in comment_list %}
+ <div id="comment-{{ comment.id }}" class="comment">
+ <noscript class="datahashloader" data-hash="{%gravatar_hash comment.email %}">
+ <img class="gravatar" src="https://images.luxagraf.net/gravcache/{%gravatar_hash comment.email %}.jpg" alt="gravatar icon for {{comment.name}}" />
+ </noscript>
+ <div class="comment--head">
+ <span class="who"><b><a href="{{comment.url}}" rel="nofollow" target="_blank">{{comment.name}}</a></b></span>
+ <span class="when">{{comment.submit_date}}</span>
+ </div>
+
+ <div class="comment--body">
+ {{comment.comment|removetags:"p"|markdown|bleach|nofollow|safe}}
+ </div>
+ </div>
+ {% endfor %}
+ </div>
diff --git a/design/templates/comments/posted.html b/design/templates/comments/posted.html
index e13288d..f4aee46 100644
--- a/design/templates/comments/posted.html
+++ b/design/templates/comments/posted.html
@@ -1,25 +1,31 @@
-{% extends "comments/base.html" %}{% load i18n %}
+{% extends "base.html" %}
+{% load i18n %}
+{% block js %}
+<script type="text/javascript">
-{% block title %}{% trans "Thanks for commenting" %}{% endblock %}
+(function () {
+ var timeLeft = 5,
+ cinterval;
-{% block extrahead %}
-{{ block.super }}
- <meta http-equiv="Refresh" content="5; url={{ comment.content_object.get_absolute_url }}#c{{ comment.id }}" />
-{% endblock %}
-
-{% block content %}
- <h2>{% trans "Thanks for posting your comment" %}</h2>
- <p>
- {% blocktrans %}
- We have received your comment, and posted it on the web site.<br/>
- You will be sent back to the article...
- {% endblocktrans %}
- </p>
+ var timeDec = function (){
+ timeLeft--;
+ document.getElementById('countdown').innerHTML = timeLeft;
+ if(timeLeft === 0){
+ clearInterval(cinterval);
+ window.location="{{comment.content_object.get_absolute_url}}";
+ }
+ };
- {# Use identical formatting to normal comment list #}
- <div id="comments">
- {% include "comments/comment.html" %}
- </div>
+ cinterval = setInterval(timeDec, 1000);
+})();
- <p><a href="{{ comment.content_object.get_absolute_url }}#c{{ comment.id }}">{% trans "Back to the article" %}</a></p>
+</script>
+{% endblock %}
+{% block primary %}
+<main role="main">
+ <h1>Thank you for your comment</h1>
+ <p>Unless you've previously been approved a few times, your comment will be moderated. If we're on the road this can sometimes take a few days, so please be patient.</p>
+ <p><a href="{{comment.content_object.get_absolute_url}}">Return to the page you came from</a> Redirecting in <span id="countdown">5</span></p>
+
+ </main>
{% endblock %}
diff --git a/design/templates/comments/preview.html b/design/templates/comments/preview.html
index 663b5ca..58eba01 100644
--- a/design/templates/comments/preview.html
+++ b/design/templates/comments/preview.html
@@ -1,30 +1,38 @@
-{% extends "comments/base.html" %}{% load i18n crispy_forms_tags comments %}
+{% extends "base.html" %}
+{% load i18n %}
-{% block title %}{% trans "Preview your comment" %}{% endblock %}
-{% block content %}
- <form action="{% comment_form_target %}" method="post" class="form-horizontal">{% csrf_token %}
- {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
+{% block primary %}
+ <main role="main" class="archive">
+ <h1 class="comment--form--header-h1">{% trans "Preview your comment" %}</h1>
+ {% load comments %}
+ <form action="{% comment_form_target %}" method="post" class="cform-arc comment--form">{% csrf_token %}
+ {% if next %}<div><input type="hidden" name="next" value="{{ next }}" /></div>{% endif %}
{% if form.errors %}
- <h2>{% blocktrans count form.errors|length as counter %}Please correct the error below{% plural %}Please correct the errors below{% endblocktrans %}</h2>
+ <h1>{% if form.errors|length == 1 %}{% trans "Please correct the error below" %}{% else %}{% trans "Please correct the errors below" %}{% endif %}</h1>
{% else %}
- <h2>{% trans "Preview of your comment" %}</h2>
-
- <blockquote class="comment-preview">{{ comment|linebreaks }}</blockquote>
-
- <div class="form-actions">
- <input type="submit" name="submit" class="btn btn-primary" value="{% trans "Post your comment" %}" id="submit" />
- </div>
-
- <p>{% trans "Or make changes" %}:</p>
+ <blockquote>{{ comment|linebreaks }}</blockquote>
+ <p>
+ <input type="submit" name="submit" class="submit-post" value="{% trans "Post your comment" %}" id="submit" /> <h3>{% trans "Or make changes" %}:</h3>
+ </p>
{% endif %}
-
- {{ form|crispy }}
-
- <div class="form-actions">
- <input type="submit" name="post" class="btn btn-primary" value="{% trans "Post" %}" />
- <input type="submit" name="preview" class="btn" value="{% trans "Preview" %}" />
- </div>
+ {% for field in form %}
+ {% if field.is_hidden %}
+ <div>{{ field }}</div>
+ {% else %}
+ {% if field.errors %}{{ field.errors }}{% endif %}
+ <p
+ {% if field.errors %} class="error"{% endif %}
+ {% ifequal field.name "honeypot" %} style="display:none;"{% endifequal %}>
+ {{ field.label_tag }} {{ field }}
+ </p>
+ {% endif %}
+ {% endfor %}
+ <p class="submit">
+ <input type="submit" name="submit" class="submit-post" value="{% trans "Post" %}" />
+ <input type="submit" name="preview" class="submit-preview" value="{% trans "Preview" %}" />
+ </p>
</form>
+ </main>
{% endblock %}
diff --git a/design/templates/details/entry.html b/design/templates/details/entry.html
index b2be14d..948a9b8 100644
--- a/design/templates/details/entry.html
+++ b/design/templates/details/entry.html
@@ -1,5 +1,6 @@
{% extends 'base.html' %}
{% load typogrify_tags %}
+{% load comments %}
{% block pagetitle %}{{object.title|title|smartypants|safe}} - Luxagraf, Writing{%comment%}{% if object.country_name == "United States" %}{{object.location_name|smartypants|safe}}, {{object.state_name}}{%else%}{{object.location_name|smartypants|safe}}, {{object.country_name}}{%endif%}{%endcomment%}{% endblock %}
@@ -45,29 +46,35 @@ class="{%if t == 0 or t == 2 %}single{%endif%}{%if t == 1 or t == 3 %}double{%en
</li>{%endif%}
</ul>
</nav>{%endwith%}{%endwith%}
- {%comment%}
- {% load comments %}
-<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}fluent_comments/css/ajaxcomments.css" />
-<script src="{{MEDIA_URL}}js/jquery.js" type="text/javascript"></script>
-<script type="text/javascript" src="{{ STATIC_URL }}fluent_comments/js/ajaxcomments.js"></script>
-
-{% render_comment_list for object %}
-{% render_comment_form for object %}
- {%endcomment%}
- {%comment%}
- <section id="comments">
- <h4><a class="disqus-link-count" href="{{object.get_absolute_url}}#disqus_thread">Comments</a></h4>
- <div id="disqus_thread"></div><script type="text/javascript" src="http://disqus.com/forums/luxagraf/embed.js"></script><noscript><a href="http://luxagraf.disqus.com/?url=ref">View the discussion thread.</a></noscript><a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
- </section>
- {%endcomment%}
- </main>
- <div class="mailing-list--wrapper">
+ {% comment %} <div class="mailing-list--wrapper">
<h5>If you enjoyed this, you should join the mailing&nbsp;list&hellip;</h5>
{% include 'mailing_list.html' %}
- </div>
+ </div> {% endcomment %}
+ </main>
+
+{% get_comment_count for object as comment_count %}.
+{%if comment_count > 0%}
+<p class="comments--header">{{comment_count}} Comments</p>
+{% render_comment_list for object %}
+{%endif%}
+{% render_comment_form for object %}
{% endblock %}
{% block js %}
+ <script type="text/javascript">
+window.onload = function() {
+ //delay loading of gravatar images using nsoscript data-hash attribute
+ dataattr = document.getElementsByClassName("datahashloader");
+ for(var i=0; i<dataattr.length; i++) {
+ var c = dataattr[i].parentNode;
+ var img = document.createElement("img");
+ img.src = 'https://images.luxagraf.net/gravcache/' + dataattr[i].getAttribute('data-hash') + '.jpg';
+ img.className += "gravatar";
+ c.insertBefore(img, c.childNodes[3]);
+
+ }
+}
+ </script>
{% with object.template_name as t %}{%if t == 1 or t == 3 %}
<script src="{{MEDIA_URL}}js/hyphenate.min.js" type="text/javascript"></script>
{%endif%}{%endwith%}{%endblock%}