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
c83ad432
Commit
c83ad432
authored
Aug 20, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checking read permissions on page list
parent
b37e140b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
14 deletions
+60
-14
wiki/conf/settings.py
+2
-0
wiki/managers.py
+43
-4
wiki/models/urlpath.py
+5
-0
wiki/templates/wiki/list.html
+3
-3
wiki/views/article.py
+7
-7
No files found.
wiki/conf/settings.py
View file @
c83ad432
...
@@ -49,6 +49,8 @@ else:
...
@@ -49,6 +49,8 @@ else:
LOGIN_URL
=
getattr
(
django_settings
,
"LOGIN_URL"
,
"/"
)
LOGIN_URL
=
getattr
(
django_settings
,
"LOGIN_URL"
,
"/"
)
# Maximum amount of children to display in a menu before going "+more"
# Maximum amount of children to display in a menu before going "+more"
# NEVER set this to 0 as it will wrongly inform the user that there are no
# children and for instance that an article can be safely deleted.
SHOW_MAX_CHILDREN
=
getattr
(
django_settings
,
'WIKI_SHOW_MAX_CHILDREN'
,
20
)
SHOW_MAX_CHILDREN
=
getattr
(
django_settings
,
'WIKI_SHOW_MAX_CHILDREN'
,
20
)
####################
####################
...
...
wiki/managers.py
View file @
c83ad432
from
django.db
import
models
from
django.db
import
models
from
django.db.models
import
Q
from
django.db.models
import
Q
from
django.db.models.query
import
QuerySet
from
django.db.models.query
import
QuerySet
,
EmptyQuerySet
from
mptt.managers
import
TreeManager
from
mptt.managers
import
TreeManager
class
ArticleEmptyQuerySet
(
QuerySet
):
def
can_read
(
self
,
user
):
return
self
def
can_write
(
self
,
user
):
return
self
class
ArticleQuerySet
(
QuerySet
):
class
ArticleQuerySet
(
QuerySet
):
def
can_read
(
self
,
user
):
def
can_read
(
self
,
user
):
...
@@ -36,7 +42,7 @@ class ArticleQuerySet(QuerySet):
...
@@ -36,7 +42,7 @@ class ArticleQuerySet(QuerySet):
def
active
(
self
):
def
active
(
self
):
return
self
.
filter
(
current_revision__deleted
=
False
)
return
self
.
filter
(
current_revision__deleted
=
False
)
class
ArticleFkQuerySet
(
QuerySet
):
class
ArticleFkQuerySet
Mixin
(
):
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
...
@@ -69,7 +75,23 @@ class ArticleFkQuerySet(QuerySet):
...
@@ -69,7 +75,23 @@ class ArticleFkQuerySet(QuerySet):
def
active
(
self
):
def
active
(
self
):
return
self
.
filter
(
article__current_revision__deleted
=
False
)
return
self
.
filter
(
article__current_revision__deleted
=
False
)
class
ArticleFkEmptyQuerySetMixin
():
def
can_read
(
self
,
user
):
return
self
def
can_write
(
self
,
user
):
return
self
def
active
(
self
,
user
):
return
self
class
ArticleFkQuerySet
(
ArticleFkQuerySetMixin
,
QuerySet
):
pass
class
ArticleFkEmptyQuerySet
(
ArticleFkEmptyQuerySetMixin
,
EmptyQuerySet
):
pass
class
ArticleManager
(
models
.
Manager
):
class
ArticleManager
(
models
.
Manager
):
def
get_empty_query_set
(
self
):
return
ArticleEmptyQuerySet
()
def
get_query_set
(
self
):
def
get_query_set
(
self
):
return
ArticleQuerySet
(
self
.
model
,
using
=
self
.
_db
)
return
ArticleQuerySet
(
self
.
model
,
using
=
self
.
_db
)
def
active
(
self
):
def
active
(
self
):
...
@@ -80,6 +102,8 @@ class ArticleManager(models.Manager):
...
@@ -80,6 +102,8 @@ class ArticleManager(models.Manager):
return
self
.
get_query_set
()
.
can_write
(
user
)
return
self
.
get_query_set
()
.
can_write
(
user
)
class
ArticleFkManager
(
models
.
Manager
):
class
ArticleFkManager
(
models
.
Manager
):
def
get_empty_query_set
(
self
):
return
ArticleFkEmptyQuerySet
()
def
get_query_set
(
self
):
def
get_query_set
(
self
):
return
ArticleFkQuerySet
(
self
.
model
,
using
=
self
.
_db
)
return
ArticleFkQuerySet
(
self
.
model
,
using
=
self
.
_db
)
def
active
(
self
):
def
active
(
self
):
...
@@ -90,16 +114,31 @@ class ArticleFkManager(models.Manager):
...
@@ -90,16 +114,31 @@ class ArticleFkManager(models.Manager):
return
self
.
get_query_set
()
.
can_write
(
user
)
return
self
.
get_query_set
()
.
can_write
(
user
)
class
URLPathQuerySet
(
QuerySet
):
class
URLPathEmptyQuerySet
(
EmptyQuerySet
,
ArticleFkEmptyQuerySetMixin
):
def
select_related_common
(
self
):
return
self
class
URLPathQuerySet
(
QuerySet
,
ArticleFkQuerySetMixin
):
def
select_related_common
(
self
):
def
select_related_common
(
self
):
return
self
.
select_related
(
"parent"
,
"article__current_revision"
,
"article__owner"
)
return
self
.
select_related
(
"parent"
,
"article__current_revision"
,
"article__owner"
)
class
URLPathManager
(
TreeManager
):
class
URLPathManager
(
TreeManager
):
def
get_empty_query_set
(
self
):
return
URLPathEmptyQuerySet
()
def
get_query_set
(
self
):
def
get_query_set
(
self
):
"""Return a QuerySet with the same ordering as the TreeManager."""
"""Return a QuerySet with the same ordering as the TreeManager."""
return
URLPathQuerySet
(
self
.
model
,
using
=
self
.
_db
)
.
order_by
(
return
URLPathQuerySet
(
self
.
model
,
using
=
self
.
_db
)
.
order_by
(
self
.
tree_id_attr
,
self
.
left_attr
)
self
.
tree_id_attr
,
self
.
left_attr
)
def
select_related_common
(
self
):
def
select_related_common
(
self
):
return
self
.
get_query_set
()
.
common_select_related
()
return
self
.
get_query_set
()
.
common_select_related
()
def
active
(
self
):
return
self
.
get_query_set
()
.
active
()
def
can_read
(
self
,
user
):
return
self
.
get_query_set
()
.
can_read
(
user
)
def
can_write
(
self
,
user
):
return
self
.
get_query_set
()
.
can_write
(
user
)
wiki/models/urlpath.py
View file @
c83ad432
...
@@ -27,6 +27,7 @@ class URLPath(MPTTModel):
...
@@ -27,6 +27,7 @@ class URLPath(MPTTModel):
INHERIT_PERMISSIONS
=
True
INHERIT_PERMISSIONS
=
True
objects
=
managers
.
URLPathManager
()
objects
=
managers
.
URLPathManager
()
_default_manager
=
objects
articles
=
generic
.
GenericRelation
(
ArticleForObject
)
articles
=
generic
.
GenericRelation
(
ArticleForObject
)
...
@@ -38,6 +39,10 @@ class URLPath(MPTTModel):
...
@@ -38,6 +39,10 @@ class URLPath(MPTTModel):
site
=
models
.
ForeignKey
(
Site
)
site
=
models
.
ForeignKey
(
Site
)
parent
=
TreeForeignKey
(
'self'
,
null
=
True
,
blank
=
True
,
related_name
=
'children'
)
parent
=
TreeForeignKey
(
'self'
,
null
=
True
,
blank
=
True
,
related_name
=
'children'
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_tree_manager
=
URLPath
.
objects
return
super
(
URLPath
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
@property
@property
def
cached_ancestors
(
self
):
def
cached_ancestors
(
self
):
"""
"""
...
...
wiki/templates/wiki/list.html
View file @
c83ad432
...
@@ -2,14 +2,14 @@
...
@@ -2,14 +2,14 @@
{% load wiki_tags i18n sekizai_tags %}
{% load wiki_tags i18n sekizai_tags %}
{% load url from future %}
{% load url from future %}
{% block pagetitle %}{% trans "
Children
of" %} {{ article.current_revision.title }}{% endblock %}
{% block pagetitle %}{% trans "
Sub-articles
of" %} {{ article.current_revision.title }}{% endblock %}
{% block wiki_contents_tab %}
{% block wiki_contents_tab %}
<ul>
<ul>
{% for
child in children
%}
{% for
article in articles
%}
<li>
<li>
<a
href=
"{% url 'wiki:get' child.path %}"
>
{{
child
.article.current_revision.title }}
</a>
<a
href=
"{% url 'wiki:get' child.path %}"
>
{{
article
.article.current_revision.title }}
</a>
</li>
</li>
{% endfor %}
{% endfor %}
</ul>
</ul>
...
...
wiki/views/article.py
View file @
c83ad432
...
@@ -395,15 +395,13 @@ class List(ListView, ArticleMixin):
...
@@ -395,15 +395,13 @@ class List(ListView, ArticleMixin):
template_name
=
"wiki/list.html"
template_name
=
"wiki/list.html"
allow_empty
=
True
allow_empty
=
True
context_object_name
=
'
children
'
context_object_name
=
'
articles
'
paginate_by
=
5
0
paginate_by
=
3
0
def
get_queryset
(
self
):
def
get_queryset
(
self
):
return
self
.
urlpath
.
get_children
()
.
order_by
(
'slug'
)
.
select_related_common
()
return
self
.
urlpath
.
get_children
()
.
can_read
(
self
.
request
.
user
)
.
select_related_common
()
.
order_by
(
'slug'
)
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
# Is this a bit of a hack? Use better inheritance?
kwargs_article
=
ArticleMixin
.
get_context_data
(
self
,
**
kwargs
)
kwargs_article
=
ArticleMixin
.
get_context_data
(
self
,
**
kwargs
)
kwargs_listview
=
ListView
.
get_context_data
(
self
,
**
kwargs
)
kwargs_listview
=
ListView
.
get_context_data
(
self
,
**
kwargs
)
kwargs
.
update
(
kwargs_article
)
kwargs
.
update
(
kwargs_article
)
...
@@ -415,14 +413,15 @@ class List(ListView, ArticleMixin):
...
@@ -415,14 +413,15 @@ class List(ListView, ArticleMixin):
new_ancestors
=
self
.
urlpath
.
cached_ancestors
+
[
self
.
urlpath
]
new_ancestors
=
self
.
urlpath
.
cached_ancestors
+
[
self
.
urlpath
]
for
child
in
updated_children
:
for
child
in
updated_children
:
child
.
cached_ancestors
=
new_ancestors
child
.
cached_ancestors
=
new_ancestors
kwargs
[
'object_list'
]
=
kwargs
[
self
.
context_object_name
]
=
updated_children
kwargs
[
self
.
context_object_name
]
=
updated_children
return
kwargs
return
kwargs
@method_decorator
(
get_article
(
can_read
=
True
))
@method_decorator
(
get_article
(
can_read
=
True
))
def
dispatch
(
self
,
request
,
article
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
request
,
article
,
*
args
,
**
kwargs
):
return
super
(
List
,
self
)
.
dispatch
(
request
,
article
,
*
args
,
**
kwargs
)
return
super
(
List
,
self
)
.
dispatch
(
request
,
article
,
*
args
,
**
kwargs
)
class
Plugin
(
View
):
class
Plugin
(
View
):
def
dispatch
(
self
,
request
,
path
=
None
,
slug
=
None
,
**
kwargs
):
def
dispatch
(
self
,
request
,
path
=
None
,
slug
=
None
,
**
kwargs
):
...
@@ -431,6 +430,7 @@ class Plugin(View):
...
@@ -431,6 +430,7 @@ class Plugin(View):
if
getattr
(
plugin
,
'slug'
,
None
)
==
slug
:
if
getattr
(
plugin
,
'slug'
,
None
)
==
slug
:
return
plugin
.
article_view
(
request
,
**
kwargs
)
return
plugin
.
article_view
(
request
,
**
kwargs
)
class
Settings
(
ArticleMixin
,
TemplateView
):
class
Settings
(
ArticleMixin
,
TemplateView
):
permission_form_class
=
forms
.
PermissionsForm
permission_form_class
=
forms
.
PermissionsForm
...
...
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