summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sublab_project/news/models.py2
-rw-r--r--sublab_project/projects/models.py3
-rw-r--r--sublab_project/utils.py11
3 files changed, 16 insertions, 0 deletions
diff --git a/sublab_project/news/models.py b/sublab_project/news/models.py
index c0b54f7..b1a0acc 100644
--- a/sublab_project/news/models.py
+++ b/sublab_project/news/models.py
@@ -4,6 +4,7 @@ from django.contrib.auth.models import User
from django.db import models
from projects.models import Project
+from utils import render_creole
class News(models.Model):
@@ -26,4 +27,5 @@ class News(models.Model):
if not self.id:
self.date_created = datetime.datetime.now()
self.date_updated = datetime.datetime.now()
+ self.content_html = render_creole(self.content)
super(News, self).save(*args, **kwargs)
diff --git a/sublab_project/projects/models.py b/sublab_project/projects/models.py
index f164956..b343f98 100644
--- a/sublab_project/projects/models.py
+++ b/sublab_project/projects/models.py
@@ -3,6 +3,8 @@ import datetime
from django.contrib.auth.models import User
from django.db import models
+from utils import render_creole
+
class Project(models.Model):
"""A project.
@@ -24,4 +26,5 @@ class Project(models.Model):
if not self.id:
self.date_created = datetime.datetime.now()
self.date_updated = datetime.datetime.now()
+ self.description_html = render_creole(self.description)
return super(Project, self).save(*args, **kwargs)
diff --git a/sublab_project/utils.py b/sublab_project/utils.py
new file mode 100644
index 0000000..6be4950
--- /dev/null
+++ b/sublab_project/utils.py
@@ -0,0 +1,11 @@
+"""General utilities module.
+"""
+from creole import Parser
+from creole.html_emitter import HtmlEmitter
+
+
+def render_creole(content):
+ """Returns Creole content rendered as HTML.
+ """
+ parsed = Parser(content).parse()
+ return HtmlEmitter(parsed).emit().encode('utf-8', 'ignore')