Commit 8ebd6c64 authored by Skia's avatar Skia
Browse files

Add Markdown support and better url tolerance for pages

parent b35483d2
......@@ -2,7 +2,7 @@ import os
from import BaseCommand, CommandError
from import call_command
from django.conf import settings
from core.models import Group, User
from core.models import Group, User, Page, PageRev
class Command(BaseCommand):
help = "Set up a new instance of the Sith AE"
......@@ -26,16 +26,22 @@ class Command(BaseCommand):
Group(id=g['id'], name=g['name']).save()
if not options['prod']:
print("Dev mode, adding some test data")
u = User(username='skia', last_name="Kia", first_name="S'",
s = User(username='skia', last_name="Kia", first_name="S'",
is_superuser=True, is_staff=True)
u = User(username='guy', last_name="Carlier", first_name="Guy",
is_superuser=False, is_staff=False)
p = Page(name='aide_syntaxe')
PageRev(page=p, title="Aide sur la syntaxe", author=s, content="""
Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
{% extends "core/page.html" %}
{% load renderer %}
{% block page %}
......@@ -14,10 +15,10 @@
{% if rev %}
<h4>This may not be the last update, you are seeing revision {{ }}!</h4>
<h3>{{ rev.title }}</h3>
<p>{{ rev.content }}</p>
<p>{{ rev.content|markdown }}</p>
{% else %}
<h3>{{ page.revisions.last.title }}</h3>
<p>{{ page.revisions.last.content }}</p>
<p>{{ page.revisions.last.content|markdown }}</p>
{% endif %}
{% endblock %}
import mistune
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from django.utils.html import escape
register = template.Library()
def markdown(text):
md = mistune.Markdown()
return mark_safe(md(escape(text)))
......@@ -232,6 +232,36 @@ class PageHandlingTest(TestCase):
self.assertTrue(response.status_code == 200)
self.assertTrue('<a href="/page/swagg/prop">Create it?</a>' in str(response.content))
def test_create_page_markdown_safe(self):
Should format the markdown and escape html correctly
"""'core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
'name': 'guy',
'owner_group': '1',
r ='core:page_edit', kwargs={'page_name': 'guy'}),
'title': 'Bibou',
'''Guy *bibou*
# Swag
response = self.client.get(reverse('core:page', kwargs={'page_name': 'guy'}))
self.assertTrue(response.status_code == 200)
self.assertTrue('<p>Guy <em>bibou</em></p>\\n<p><a href=""></a></p>\\n' +
'<h1>Swag</h1>\\n<p>&lt;guy&gt;Bibou&lt;/guy&gt;</p>\\n' +
'<p>&lt;script&gt;alert(&#39;Guy&#39;);&lt;/script&gt;</p>' in str(response.content))
#TODO: many tests on the pages:
# - renaming a page
# - changing a page's parent --> check that page's children's full_name
......@@ -29,10 +29,10 @@ urlpatterns = [
# Page views
url(r'^page/$', PageListView.as_view(), name='page_list'),
url(r'^page/(?P<page_name>[a-z0-9/]*)/edit$', PageEditView.as_view(), name='page_edit'),
url(r'^page/(?P<page_name>[a-z0-9/]*)/prop$', PagePropView.as_view(), name='page_prop'),
url(r'^page/(?P<page_name>[a-z0-9/]*)/hist$', PageHistView.as_view(), name='page_hist'),
url(r'^page/(?P<page_name>[a-z0-9/]*)/rev/(?P<rev>[0-9]+)/', PageRevView.as_view(), name='page_rev'),
url(r'^page/(?P<page_name>[a-z0-9/]*)/$', PageView.as_view(), name='page'),
url(r'^page/(?P<page_name>[a-z0-9/\-_]*)/edit$', PageEditView.as_view(), name='page_edit'),
url(r'^page/(?P<page_name>[a-z0-9/\-_]*)/prop$', PagePropView.as_view(), name='page_prop'),
url(r'^page/(?P<page_name>[a-z0-9/\-_]*)/hist$', PageHistView.as_view(), name='page_hist'),
url(r'^page/(?P<page_name>[a-z0-9/\-_]*)/rev/(?P<rev>[0-9]+)/', PageRevView.as_view(), name='page_rev'),
url(r'^page/(?P<page_name>[a-z0-9/\-_]*)/$', PageView.as_view(), name='page'),
......@@ -13,7 +13,6 @@ def not_found(request):
return render(request, "core/404.html")
# TODO: see's TODO!
class CanEditPropMixin(View):
This view is made to protect any child view that would be showing some properties of an object that are restricted
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment