From d7f07bdf7b05bc28a149174a15c4eb8d9503b6cf Mon Sep 17 00:00:00 2001 From: Ben Adida <ben@adida.net> Date: Mon, 10 Mar 2014 20:02:43 -0700 Subject: [PATCH] added ability to include safe HTML in the election description --- helios/models.py | 5 +++++ helios/templates/election_view.html | 3 +-- requirements.txt | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/helios/models.py b/helios/models.py index 869f1fa..bb516a9 100644 --- a/helios/models.py +++ b/helios/models.py @@ -12,6 +12,7 @@ from django.conf import settings from django.core.mail import send_mail import datetime, logging, uuid, random, io +import bleach from crypto import electionalgs, algs, utils from helios import utils as heliosutils @@ -189,6 +190,10 @@ class Election(HeliosModel): def is_archived(self): return self.archived_at != None + @property + def description_bleached(self): + return bleach.clean(self.description) + @classmethod def get_featured(cls): return cls.objects.filter(featured_p = True).order_by('short_name') diff --git a/helios/templates/election_view.html b/helios/templates/election_view.html index e486ddb..92c6b2e 100644 --- a/helios/templates/election_view.html +++ b/helios/templates/election_view.html @@ -1,5 +1,4 @@ {% extends TEMPLATE_BASE %} - {% block title %}{{election.name}}{% endblock %} {% block content %} <div style="float: left; margin-right: 50px;"> @@ -47,7 +46,7 @@ this {{election.election_type}} is <u>not</u> featured on the front page. <br clear="left" /> <div style="margin-bottom: 25px;margin-left: 15px; border-left: 1px solid #aaa; padding-left: 5px; font-size:1.3em; "> -{{election.description}} +{{election.description_bleached|safe}} </div> {% if election.election_info_url %} diff --git a/requirements.txt b/requirements.txt index 49dcfd0..02d47dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ django_webtest==1.7.5 webtest==2.0.7 django-db-pool==0.0.10 django-secure==0.1.2 +bleach==1.4 -- GitLab