mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
Add Markdown support and better url tolerance for pages
This commit is contained in:
parent
b35483d2a9
commit
8ebd6c64a7
@ -2,7 +2,7 @@ import os
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.core.management 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'",
|
||||
email="skia@git.an",
|
||||
date_of_birth="1942-06-12T00:00:00+01:00",
|
||||
is_superuser=True, is_staff=True)
|
||||
u.set_password("plop")
|
||||
u.save()
|
||||
s.set_password("plop")
|
||||
s.save()
|
||||
u = User(username='guy', last_name="Carlier", first_name="Guy",
|
||||
email="guy@git.an",
|
||||
date_of_birth="1942-06-12T00:00:00+01:00",
|
||||
is_superuser=False, is_staff=False)
|
||||
u.set_password("plop")
|
||||
u.save()
|
||||
p = Page(name='aide_syntaxe')
|
||||
p.set_lock(s)
|
||||
p.save()
|
||||
PageRev(page=p, title="Aide sur la syntaxe", author=s, content="""
|
||||
Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
""").save()
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
{% extends "core/page.html" %}
|
||||
{% load renderer %}
|
||||
|
||||
{% block page %}
|
||||
<h3>Page</h3>
|
||||
@ -14,10 +15,10 @@
|
||||
{% if rev %}
|
||||
<h4>This may not be the last update, you are seeing revision {{ rev.id }}!</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 %}
|
||||
|
||||
|
0
core/templatetags/__init__.py
Normal file
0
core/templatetags/__init__.py
Normal file
17
core/templatetags/renderer.py
Normal file
17
core/templatetags/renderer.py
Normal file
@ -0,0 +1,17 @@
|
||||
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()
|
||||
|
||||
@register.filter(is_safe=False)
|
||||
@stringfilter
|
||||
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
|
||||
"""
|
||||
self.client.post(reverse('core:page_prop', kwargs={'page_name': 'guy'}), {'parent': '',
|
||||
'name': 'guy',
|
||||
'owner_group': '1',
|
||||
})
|
||||
r = self.client.post(reverse('core:page_edit', kwargs={'page_name': 'guy'}),
|
||||
{
|
||||
'title': 'Bibou',
|
||||
'content':
|
||||
'''Guy *bibou*
|
||||
|
||||
http://git.an
|
||||
|
||||
# Swag
|
||||
|
||||
<guy>Bibou</guy>
|
||||
|
||||
<script>alert('Guy');</script>
|
||||
''',
|
||||
})
|
||||
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="http://git.an">http://git.an</a></p>\\n' +
|
||||
'<h1>Swag</h1>\\n<p><guy>Bibou</guy></p>\\n' +
|
||||
'<p><script>alert('Guy');</script></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
|
||||
|
10
core/urls.py
10
core/urls.py
@ -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 models.py'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
|
||||
|
Loading…
Reference in New Issue
Block a user