From: Brett Parker Date: Sat, 12 Sep 2009 14:27:08 +0000 (+0100) Subject: Actually add comments to blog, tidy up rst handling to make sure we get xhtml1.1... X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/commitdiff_plain/bba5754a7f6971f4eedd2d4faa74e7ad89de8586 Actually add comments to blog, tidy up rst handling to make sure we get xhtml1.1 complaint bits... --- diff --git a/media/style/main.css b/media/style/main.css index 56ecd36..c3bf811 100644 --- a/media/style/main.css +++ b/media/style/main.css @@ -190,3 +190,42 @@ dl dt { #content ul li p.first { margin: 0; } + +div.comments { + border-top: 1px solid #afafaf; +} + +div.comments h3 { + margin-top: 0.2em; + padding-top: 0; +} + +div.comments div.comment { + border-bottom: 1px solid #afafaf; +} + +div.comment_new p label { + width: 25%; + padding-right: 0.7em; + text-align: right; + display: block; + float: left; + vertical-align: top; +} + +div.comment_new p label:after { + content: ":"; +} + +div.comment_new p input[type="text"] { + width: 30em; +} + +div.comment_new p textarea { + width: 25em; +} + +div.comments a[name="comments"] { + text-decoration: none; + display: none; +} diff --git a/sommitrealweird/blog/templates/blog/blog_index.html b/sommitrealweird/blog/templates/blog/blog_index.html index f7f3ab0..6727804 100644 --- a/sommitrealweird/blog/templates/blog/blog_index.html +++ b/sommitrealweird/blog/templates/blog/blog_index.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load xhtml11rst %} +{% load comments %} {% block extrahead %} @@ -25,7 +26,8 @@ {% endif %} {% endif %} {% endfor %} - permalink

+ {% get_comment_count for entry as comment_count %} + permalink | Comments: {{ comment_count }}

{% endfor %} {% if paginated and has_more_than_one_page %}

Pages: diff --git a/sommitrealweird/blog/templates/blog/single_entry_rst.html b/sommitrealweird/blog/templates/blog/single_entry_rst.html index 9b49f55..0d99d90 100644 --- a/sommitrealweird/blog/templates/blog/single_entry_rst.html +++ b/sommitrealweird/blog/templates/blog/single_entry_rst.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load xhtml11rst %} +{% load comments %} {% block content %}

{{ entry.title }}

@@ -22,6 +23,22 @@ {% endif %} {% endfor %} {% endif %} - permalink + {% get_comment_count for entry as comment_count %} + permalink | Comments: {{ comment_count }}

+{% if comment_count %} +
+ + {% get_comment_list for entry as comment_list %} + {% for comment in comment_list %} +
+

{{ comment.user_name }} - {{ comment.submit_date|date:"Y-m-d H:i" }}

+ {{ comment.comment }} +
+ {% endfor %} +
+{% endif %} +
+ {% render_comment_form for entry %} +
{% endblock %} diff --git a/sommitrealweird/bpcms/templates/bpcms/bpcms.html b/sommitrealweird/bpcms/templates/bpcms/bpcms.html new file mode 100644 index 0000000..7b96bb9 --- /dev/null +++ b/sommitrealweird/bpcms/templates/bpcms/bpcms.html @@ -0,0 +1,9 @@ +{% extends "base.html" %} + +{% block extrahead %} +{% if extracss %} +{% for css in extracss %} + +{% endfor %} +{% endif %} +{% endblock %} diff --git a/sommitrealweird/generic/docutils_xhtml11.py b/sommitrealweird/generic/docutils_xhtml11.py new file mode 100644 index 0000000..4b7d9b9 --- /dev/null +++ b/sommitrealweird/generic/docutils_xhtml11.py @@ -0,0 +1,32 @@ +# Author: Brett Parker + +""" +HTML1.1 Writer. +""" + +__docformat__ = 'reStructuredText' + +import sys +import os +import os.path +import codecs +import docutils +from docutils import frontend, nodes, utils, writers +from docutils.writers import html4css1 + +class Writer(html4css1.Writer): + + config_section = 'xhtml11 writer' + config_section_dependencies = ('writers', 'html4css1 writer') + + def __init__(self): + html4css1.Writer.__init__(self) + self.translator_class = HTMLTranslator + +class HTMLTranslator(html4css1.HTMLTranslator): + + def is_compactable(self, node): + return False + + def should_be_compact_paragraph(self, node): + return False diff --git a/sommitrealweird/generic/templatetags/xhtml11rst.py b/sommitrealweird/generic/templatetags/xhtml11rst.py new file mode 100644 index 0000000..3bc212a --- /dev/null +++ b/sommitrealweird/generic/templatetags/xhtml11rst.py @@ -0,0 +1,22 @@ +from django import template +from django.conf import settings +from django.utils.encoding import smart_str, force_unicode +from django.utils.safestring import mark_safe +from generic import docutils_xhtml11 + +register = template.Library() + +def restructuredtext(value): + try: + from docutils.core import publish_parts + except ImportError: + if settings.DEBUG: + raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed." + return force_unicode(value) + else: + docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {}) + parts = publish_parts(source=smart_str(value), writer=docutils_xhtml11.Writer(), settings_overrides=docutils_settings) + return mark_safe(force_unicode(parts["fragment"])) +restructuredtext.is_safe = True + +register.filter(restructuredtext) diff --git a/sommitrealweird/settings.py b/sommitrealweird/settings.py index f0a5725..73ea9ce 100644 --- a/sommitrealweird/settings.py +++ b/sommitrealweird/settings.py @@ -67,6 +67,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.markup', + 'django.contrib.comments', 'bpcms', 'generic', 'blog', diff --git a/sommitrealweird/urls.py b/sommitrealweird/urls.py index dc24d72..6106b9f 100644 --- a/sommitrealweird/urls.py +++ b/sommitrealweird/urls.py @@ -26,7 +26,9 @@ urlpatterns = patterns('', (r'^blog/', include('blog.urls')), (r'^photo/', include('photo.urls')), (r'^photos/', include('photo.urls')), + (r'^css-doc/(?P.*)$', 'bpcms.views.css_view'), (r'^feeds/rss/(?P.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': rssfeeds_dict}), (r'^feeds/(?P.*)/', 'django.contrib.syndication.views.feed', {'feed_dict': feeds_dict}), + (r'^comments/', include('django.contrib.comments.urls')), (r'^(?:content/|)', include('bpcms.urls')) )