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
096e1493
Commit
096e1493
authored
Aug 21, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:benjaoming/django-wiki
parents
af0b2a6c
d5d90a4f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
6 deletions
+14
-6
wiki/managers.py
+2
-2
wiki/models/article.py
+10
-3
wiki/views/mixins.py
+2
-1
No files found.
wiki/managers.py
View file @
096e1493
...
@@ -47,7 +47,7 @@ class ArticleFkQuerySetMixin():
...
@@ -47,7 +47,7 @@ class ArticleFkQuerySetMixin():
def
can_read
(
self
,
user
):
def
can_read
(
self
,
user
):
"""Filter objects so only the ones with a user's reading access
"""Filter objects so only the ones with a user's reading access
are included"""
are included"""
if
user
.
has_perm
(
'wiki.moderat
or
'
):
if
user
.
has_perm
(
'wiki.moderat
e
'
):
return
self
return
self
if
user
.
is_anonymous
():
if
user
.
is_anonymous
():
q
=
self
.
filter
(
article__other_read
=
True
)
q
=
self
.
filter
(
article__other_read
=
True
)
...
@@ -61,7 +61,7 @@ class ArticleFkQuerySetMixin():
...
@@ -61,7 +61,7 @@ class ArticleFkQuerySetMixin():
def
can_write
(
self
,
user
):
def
can_write
(
self
,
user
):
"""Filter objects so only the ones with a user's writing access
"""Filter objects so only the ones with a user's writing access
are included"""
are included"""
if
user
.
has_perm
(
'wiki.moderat
or
'
):
if
user
.
has_perm
(
'wiki.moderat
e
'
):
return
self
return
self
if
user
.
is_anonymous
():
if
user
.
is_anonymous
():
q
=
self
.
filter
(
article__other_write
=
True
)
q
=
self
.
filter
(
article__other_write
=
True
)
...
...
wiki/models/article.py
View file @
096e1493
...
@@ -65,7 +65,7 @@ class Article(models.Model):
...
@@ -65,7 +65,7 @@ class Article(models.Model):
def
can_write
(
self
,
user
=
None
):
def
can_write
(
self
,
user
=
None
):
# Deny writing access to deleted articles if user has no delete access
# Deny writing access to deleted articles if user has no delete access
if
self
.
current_revision
and
self
.
current_revision
.
deleted
and
not
self
.
can_
dele
te
(
user
):
if
self
.
current_revision
and
self
.
current_revision
.
deleted
and
not
self
.
can_
modera
te
(
user
):
return
False
return
False
# Check access for other users...
# Check access for other users...
if
user
.
is_anonymous
()
and
not
settings
.
ANONYMOUS_WRITE
:
if
user
.
is_anonymous
()
and
not
settings
.
ANONYMOUS_WRITE
:
...
@@ -96,11 +96,15 @@ class Article(models.Model):
...
@@ -96,11 +96,15 @@ class Article(models.Model):
for
descendant
in
obj
.
content_object
.
get_descendants
():
for
descendant
in
obj
.
content_object
.
get_descendants
():
yield
descendant
yield
descendant
def
get_children
(
self
,
max_num
=
None
,
**
kwargs
):
def
get_children
(
self
,
max_num
=
None
,
user_can_read
=
None
,
**
kwargs
):
"""NB! This generator is expensive, so use it with care!!"""
"""NB! This generator is expensive, so use it with care!!"""
cnt
=
0
cnt
=
0
for
obj
in
self
.
articleforobject_set
.
filter
(
is_mptt
=
True
):
for
obj
in
self
.
articleforobject_set
.
filter
(
is_mptt
=
True
):
for
child
in
obj
.
content_object
.
get_children
()
.
filter
(
**
kwargs
)
.
order_by
(
'articles__article__current_revision__title'
):
if
user_can_read
:
objects
=
obj
.
content_object
.
get_children
()
.
filter
(
**
kwargs
)
.
can_read
(
user_can_read
)
else
:
objects
=
obj
.
content_object
.
get_children
()
.
filter
(
**
kwargs
)
for
child
in
objects
.
order_by
(
'articles__article__current_revision__title'
):
cnt
+=
1
cnt
+=
1
if
max_num
and
cnt
>
max_num
:
return
if
max_num
and
cnt
>
max_num
:
return
yield
child
yield
child
...
@@ -187,6 +191,9 @@ class Article(models.Model):
...
@@ -187,6 +191,9 @@ class Article(models.Model):
class
ArticleForObject
(
models
.
Model
):
class
ArticleForObject
(
models
.
Model
):
objects
=
managers
.
ArticleFkManager
()
article
=
models
.
ForeignKey
(
'Article'
,
on_delete
=
models
.
CASCADE
)
article
=
models
.
ForeignKey
(
'Article'
,
on_delete
=
models
.
CASCADE
)
# Same as django.contrib.comments
# Same as django.contrib.comments
content_type
=
models
.
ForeignKey
(
ContentType
,
content_type
=
models
.
ForeignKey
(
ContentType
,
...
...
wiki/views/mixins.py
View file @
096e1493
...
@@ -14,7 +14,8 @@ class ArticleMixin(TemplateResponseMixin):
...
@@ -14,7 +14,8 @@ class ArticleMixin(TemplateResponseMixin):
self
.
children_slice
=
[]
self
.
children_slice
=
[]
if
settings
.
SHOW_MAX_CHILDREN
>
0
:
if
settings
.
SHOW_MAX_CHILDREN
>
0
:
for
child
in
self
.
article
.
get_children
(
max_num
=
settings
.
SHOW_MAX_CHILDREN
+
1
,
for
child
in
self
.
article
.
get_children
(
max_num
=
settings
.
SHOW_MAX_CHILDREN
+
1
,
articles__article__current_revision__deleted
=
False
):
articles__article__current_revision__deleted
=
False
,
user_can_read
=
request
.
user
):
self
.
children_slice
.
append
(
child
)
self
.
children_slice
.
append
(
child
)
return
super
(
ArticleMixin
,
self
)
.
dispatch
(
request
,
*
args
,
**
kwargs
)
return
super
(
ArticleMixin
,
self
)
.
dispatch
(
request
,
*
args
,
**
kwargs
)
...
...
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