Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
AE
Sith
Commits
8ebd6c64
Commit
8ebd6c64
authored
Jan 08, 2016
by
Skia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Markdown support and better url tolerance for pages
parent
b35483d2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
12 deletions
+65
-12
core/management/commands/setup.py
core/management/commands/setup.py
+10
-4
core/templates/core/page_detail.html
core/templates/core/page_detail.html
+3
-2
core/templatetags/__init__.py
core/templatetags/__init__.py
+0
-0
core/templatetags/renderer.py
core/templatetags/renderer.py
+17
-0
core/tests.py
core/tests.py
+30
-0
core/urls.py
core/urls.py
+5
-5
core/views/__init__.py
core/views/__init__.py
+0
-1
No files found.
core/management/commands/setup.py
View file @
8ebd6c64
...
...
@@ -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
()
core/templates/core/page_detail.html
View file @
8ebd6c64
{% 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 %}
...
...
core/templatetags/__init__.py
0 → 100644
View file @
8ebd6c64
core/templatetags/renderer.py
0 → 100644
View file @
8ebd6c64
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
)))
core/tests.py
View file @
8ebd6c64
...
...
@@ -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
...
...
core/urls.py
View file @
8ebd6c64
...
...
@@ -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'
),
]
core/views/__init__.py
View file @
8ebd6c64
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment