Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 1a9adacf616269b937a9e8a4fb4894c4dd6c8752
Author: Richard Marko <rmarko(a)fedoraproject.org>
Date: Mon Jan 27 15:14:30 2014 +0100
[frontend] use markdown template filter
Signed-off-by: Richard Marko <rmarko(a)fedoraproject.org>
---------------------------------------------------------------
coprs_frontend/coprs/filters.py | 17 +++++++++++++++++
coprs_frontend/coprs/models.py | 13 ++-----------
.../coprs/templates/coprs/detail/overview.html | 4 ++--
coprs_frontend/coprs/templates/coprs/show.html | 10 +++++-----
4 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/coprs_frontend/coprs/filters.py b/coprs_frontend/coprs/filters.py
index bbc1df0..6a3432e 100644
--- a/coprs_frontend/coprs/filters.py
+++ b/coprs_frontend/coprs/filters.py
@@ -1,6 +1,10 @@
import datetime
import pytz
import time
+import markdown
+
+from flask import Markup
+
from coprs import app
from coprs import helpers
@@ -30,6 +34,7 @@ def os_name_short(os_name, os_version):
return "el{0}".format(os_version)
return os_name
+
@app.template_filter('localized_time')
def localized_time(time_in, timezone):
""" return time shifted into timezone (and printed in ISO format)
@@ -47,3 +52,15 @@ def localized_time(time_in, timezone):
dt_aware = datetime.datetime.fromtimestamp(time_in).replace(tzinfo=utc_tz)
dt_my_tz = dt_aware.astimezone(user_tz)
return dt_my_tz.strftime(format_tz)
+
+
+(a)app.template_filter("markdown")
+def markdown_filter(data):
+ if not data:
+ return ''
+
+ md = markdown.Markdown(
+ safe_mode="replace",
+ html_replacement_text="--RAW HTML NOT ALLOWED--")
+
+ return Markup(md.convert(data))
diff --git a/coprs_frontend/coprs/models.py b/coprs_frontend/coprs/models.py
index a342c20..a299518 100644
--- a/coprs_frontend/coprs/models.py
+++ b/coprs_frontend/coprs/models.py
@@ -1,5 +1,4 @@
import datetime
-import markdown
from sqlalchemy.ext.associationproxy import association_proxy
from libravatar import libravatar_url
@@ -163,19 +162,11 @@ class Copr(db.Model, helpers.Serializer):
@property
def description_or_not_filled(self):
- md = markdown.Markdown(
- safe_mode="replace",
- html_replacement_text="--RAW HTML NOT ALLOWED--")
-
- return md.convert(self.description) or "Description not filled in by author.
Very likely personal repository for testing purpose, which you should not use."
+ return self.description or "Description not filled in by author. Very likely
personal repository for testing purpose, which you should not use."
@property
def instructions_or_not_filled(self):
- md = markdown.Markdown(
- safe_mode="replace",
- html_replacement_text="--RAW HTML NOT ALLOWED--")
-
- return md.convert(self.instructions) or "Instructions not filled in by
author. Author knows what to do. Everybody else should avoid this repo."
+ return self.instructions or "Instructions not filled in by author. Author
knows what to do. Everybody else should avoid this repo."
@property
def active_chroots(self):
diff --git a/coprs_frontend/coprs/templates/coprs/detail/overview.html
b/coprs_frontend/coprs/templates/coprs/detail/overview.html
index d3bca61..7bebca0 100644
--- a/coprs_frontend/coprs/templates/coprs/detail/overview.html
+++ b/coprs_frontend/coprs/templates/coprs/detail/overview.html
@@ -6,9 +6,9 @@
{% block detail_body %}
<h2>Description</h2>
- <div class="shift-right">{{ copr.description_or_not_filled|safe
}}</div>
+ <div class="shift-right">{{ copr.description_or_not_filled|markdown
}}</div>
<h2>Installation Instructions</h2>
- <div class="shift-right">{{ copr.instructions_or_not_filled|safe
}}</div>
+ <div class="shift-right">{{ copr.instructions_or_not_filled|markdown
}}</div>
<h2>Active Releases</h2>
<div class="disclaimer">
The following unofficial repositories are provided as-is by owner of this project.
diff --git a/coprs_frontend/coprs/templates/coprs/show.html
b/coprs_frontend/coprs/templates/coprs/show.html
index 2533171..4a25617 100644
--- a/coprs_frontend/coprs/templates/coprs/show.html
+++ b/coprs_frontend/coprs/templates/coprs/show.html
@@ -29,12 +29,12 @@
{% for copr in coprs %}
<div class="copr">
<a class="coprs-list" href="{{
url_for('coprs_ns.copr_detail', username = copr.owner.name, coprname = copr.name)
}}">{{ copr.owner.name }}/{{ copr.name }}</a>
- <p>{{ copr.description_or_not_filled|safe }}</p>
- <p class="repos">
- {% for mock_chroot in copr.active_chroots %}
+ <p>{{ copr.description_or_not_filled|markdown }}</p>
+ <p class="repos">
+ {% for mock_chroot in copr.active_chroots %}
{{ mock_chroot.os_release|os_name_short(mock_chroot.os_version) }}.{{
mock_chroot.arch }}{% if not loop.last %}, {% endif %}
- {% endfor %}
- </p>
+ {% endfor %}
+ </p>
</div>
{% else %}
<p>No projects...</p>