aboutsummaryrefslogtreecommitdiffstats
path: root/notice
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-04-29 09:06:52 +0800
committerWeitian LI <liweitianux@gmail.com>2014-04-29 09:06:52 +0800
commita05186c6cbbd2fc434694d126cfdbe70e96be72b (patch)
tree2a2612d715b71cb554167a754f276f4e1524cc8a /notice
parent9177e7f60868a34a50da65d5dc7fe2aac17b2804 (diff)
downloaddjango-skaschool-a05186c6cbbd2fc434694d126cfdbe70e96be72b.tar.bz2
* implemented 'my_markdown' templatetag (requires python-markdown)
* updated 'list_notice.html' .notice-content with my_markdown tag * added help_text for notice/models.py/Notice contents field
Diffstat (limited to 'notice')
-rw-r--r--notice/models.py3
-rw-r--r--notice/templates/notice/list_notice.html3
-rw-r--r--notice/templatetags/__init__.py0
-rw-r--r--notice/templatetags/my_markdown.py26
4 files changed, 30 insertions, 2 deletions
diff --git a/notice/models.py b/notice/models.py
index e2b9533..63b17b2 100644
--- a/notice/models.py
+++ b/notice/models.py
@@ -15,7 +15,8 @@ class Notice(models.Model):
pubtime = models.DateTimeField(_("Publish time"), auto_now_add=True)
category = models.ForeignKey('NoticeCategory', verbose_name=_("Category"))
is_important = models.BooleanField(_("Is important"), default=False)
- contents = models.TextField(_("Contents"))
+ contents = models.TextField(_("Contents"),
+ help_text=_("Markdown syntax supported"))
# NoticeAttachment to deal with attachments
attachments = generic.GenericRelation('NoticeAttachment')
diff --git a/notice/templates/notice/list_notice.html b/notice/templates/notice/list_notice.html
index 14355f0..e0f2011 100644
--- a/notice/templates/notice/list_notice.html
+++ b/notice/templates/notice/list_notice.html
@@ -3,6 +3,7 @@
{% load url from future %}
{% load i18n %}
{% load bootstrap3 %}
+{% load my_markdown %}
{# template to show notice list #}
@@ -24,7 +25,7 @@
<p>{{ notice.show_pubtime }}, {{ notice.category.category_name }}</p>
</div>
<div class="notice-content">
- {{ notice.contents }}
+ {{ notice.contents|my_markdown }}
</div>
{% if notice.attachments.all %}
<div class="notice-attachment">
diff --git a/notice/templatetags/__init__.py b/notice/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/notice/templatetags/__init__.py
diff --git a/notice/templatetags/my_markdown.py b/notice/templatetags/my_markdown.py
new file mode 100644
index 0000000..6b25146
--- /dev/null
+++ b/notice/templatetags/my_markdown.py
@@ -0,0 +1,26 @@
+# -*- coding: utf8 -*-
+
+"""
+implement my own 'markdown' template tag
+requires 'python-markdown' (pip install markdown)
+"""
+# ref: http://www.dominicrodger.com/django-markdown.html
+
+import markdown
+
+from django import template
+from django.template.defaultfilters import stringfilter
+from django.utils.encoding import force_unicode
+from django.utils.safestring import mark_safe
+
+register = template.Library()
+
+@register.filter(is_safe=True)
+@stringfilter
+def my_markdown(value):
+ extensions = ["nl2br", ]
+
+ return mark_safe(markdown.markdown(force_unicode(value),
+ extensions,
+ safe_mode=True,
+ enable_attributes=False))