From 62bb3db8ada68a22c7a58f32b2e6bed63f19e53c Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 26 Oct 2012 17:36:12 -0500 Subject: Remove usages of 'django.contrib.markup' Switch to the news model being able to spit out the HTML version of the content, and don't use the markup contrib module. This is deprecated as of Django 1.5 so we can move off it now to save trouble down the road when it is fully removed. Signed-off-by: Dan McGee --- news/models.py | 7 +++++++ news/views.py | 2 +- settings.py | 1 - templates/feeds/news_description.html | 3 +-- templates/news/view.html | 3 +-- templates/public/index.html | 6 +++--- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/news/models.py b/news/models.py index 91232706..40238cde 100644 --- a/news/models.py +++ b/news/models.py @@ -1,6 +1,9 @@ +import markdown + from django.db import models from django.contrib.auth.models import User from django.contrib.sites.models import Site +from django.utils.safestring import mark_safe from django.utils.timezone import now @@ -17,6 +20,10 @@ class News(models.Model): def get_absolute_url(self): return '/news/%s/' % self.slug + def html(self): + return mark_safe(markdown.markdown( + self.content, safe_mode=True, enable_attributes=False)) + def __unicode__(self): return self.title diff --git a/news/views.py b/news/views.py index c0230f1e..74bec058 100644 --- a/news/views.py +++ b/news/views.py @@ -76,7 +76,7 @@ def view_redirect(request, object_id): @require_POST def preview(request): data = request.POST.get('data', '') - markup = markdown.markdown(data, safe_mode=True) + markup = markdown.markdown(data, safe_mode=True, enable_attributes=False) return HttpResponse(markup) # vim: set ts=4 sw=4 et: diff --git a/settings.py b/settings.py index 80df6f43..7038a71b 100644 --- a/settings.py +++ b/settings.py @@ -107,7 +107,6 @@ 'django.contrib.sites', 'django.contrib.sitemaps', 'django.contrib.admin', - 'django.contrib.markup', 'django.contrib.staticfiles', 'south', 'django_countries', diff --git a/templates/feeds/news_description.html b/templates/feeds/news_description.html index 77830367..d3cacebc 100644 --- a/templates/feeds/news_description.html +++ b/templates/feeds/news_description.html @@ -1,3 +1,2 @@ -{% load markup %}

{{obj.author.get_full_name}} wrote:

-{{ obj.content|markdown:'safe' }} +{{ obj.content.html }} diff --git a/templates/news/view.html b/templates/news/view.html index b6c06b28..8f49fb1f 100644 --- a/templates/news/view.html +++ b/templates/news/view.html @@ -1,5 +1,4 @@ {% extends "base.html" %} -{% load markup %} {% block title %}Arch Linux - News: {{ news.title }}{% endblock %} {% block content %} @@ -28,6 +27,6 @@

{{ news.title }}

-
{{ news.content|markdown:'safe' }}
+
{{ news.html }}
{% endblock %} diff --git a/templates/public/index.html b/templates/public/index.html index 762433a4..686fbdda 100644 --- a/templates/public/index.html +++ b/templates/public/index.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load markup cache %} +{% load cache %} {% load url from future %} {% load static from staticfiles %} @@ -53,8 +53,8 @@

{{ news.postdate|date }}

- {% if forloop.counter0 == 0 %}{{ news.content|markdown:'safe'|truncatewords_html:300 }} - {% else %}{{ news.content|markdown:'safe'|truncatewords_html:100 }}{% endif %} + {% if forloop.counter0 == 0 %}{{ news.html|truncatewords_html:300 }} + {% else %}{{ news.html|truncatewords_html:100 }}{% endif %}
{% else %} {% if forloop.counter0 == 5 %} -- cgit v1.2.3-54-g00ecf