Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-wiki
Commits
d7df0af4
Commit
d7df0af4
authored
Jun 10, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 cleanup
parent
ed9d853e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletions
+12
-1
wiki/templatetags/wiki_tags.py
+12
-1
No files found.
wiki/templatetags/wiki_tags.py
View file @
d7df0af4
...
...
@@ -23,7 +23,10 @@ _cache = {}
@register.assignment_tag
(
takes_context
=
True
)
def
article_for_object
(
context
,
obj
):
if
not
isinstance
(
obj
,
Model
):
raise
TypeError
(
"A Wiki article can only be associated to a Django Model instance, not
%
s"
%
type
(
obj
))
raise
TypeError
(
"A Wiki article can only be associated to a Django Model "
"instance, not
%
s"
%
type
(
obj
)
)
content_type
=
ContentType
.
objects
.
get_for_model
(
obj
)
...
...
@@ -37,6 +40,7 @@ def article_for_object(context, obj):
_cache
[
obj
]
=
article
return
_cache
[
obj
]
@register.inclusion_tag
(
'wiki/includes/render.html'
,
takes_context
=
True
)
def
wiki_render
(
context
,
article
,
preview_content
=
None
):
...
...
@@ -54,6 +58,7 @@ def wiki_render(context, article, preview_content=None):
})
return
context
@register.inclusion_tag
(
'wiki/includes/form.html'
,
takes_context
=
True
)
def
wiki_form
(
context
,
form_obj
):
if
not
isinstance
(
form_obj
,
BaseForm
):
...
...
@@ -61,6 +66,7 @@ def wiki_form(context, form_obj):
context
.
update
({
'form'
:
form_obj
})
return
context
@register.filter
def
get_content_snippet
(
content
,
keyword
,
max_words
=
30
):
max_words
=
int
(
max_words
)
...
...
@@ -81,26 +87,31 @@ def get_content_snippet(content, keyword, max_words=30):
html
=
" "
.
join
(
filter
(
lambda
x
:
x
!=
""
,
striptags
(
content
)
.
replace
(
"
\n
"
,
" "
)
.
split
(
" "
))[:
max_words
])
return
html
@register.filter
def
can_read
(
obj
,
user
):
"""Articles and plugins have a can_read method..."""
return
obj
.
can_read
(
user
)
@register.filter
def
can_write
(
obj
,
user
):
"""Articles and plugins have a can_write method..."""
return
obj
.
can_write
(
user
)
@register.filter
def
can_delete
(
obj
,
user
):
"""Articles and plugins have a can_delete method..."""
return
obj
.
can_delete
(
user
)
@register.filter
def
can_moderate
(
obj
,
user
):
"""Articles and plugins have a can_moderate method..."""
return
obj
.
can_moderate
(
user
)
@register.filter
def
is_locked
(
obj
):
"""Articles and plugins have a can_delete method..."""
...
...
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