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
6af3dcb8
Commit
6af3dcb8
authored
Aug 16, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:benjaoming/django-wiki
parents
5fe706cf
8cd2bb7b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
12 deletions
+31
-12
wiki/decorators.py
+2
-2
wiki/migrations/0002_auto__add_field_articleplugin_created.py
+0
-0
wiki/models/__init__.py
+15
-2
wiki/models/article.py
+4
-2
wiki/models/urlpath.py
+7
-3
wiki/plugins/attachments/views.py
+2
-2
wiki/views/article.py
+1
-1
No files found.
wiki/decorators.py
View file @
6af3dcb8
...
...
@@ -78,14 +78,14 @@ def get_article(func=None, can_read=True, can_write=False, deleted_contents=Fals
return
redirect
(
return_url
)
if
can_read
and
not
article
.
can_read
(
request
.
user
):
if
request
.
user
.
is_anonymous
:
if
request
.
user
.
is_anonymous
()
:
return
redirect
(
django_settings
.
LOGIN_URL
)
else
:
pass
# TODO: Return a permission denied page
if
can_write
and
not
article
.
can_write
(
request
.
user
):
if
request
.
user
.
is_anonymous
:
if
request
.
user
.
is_anonymous
()
:
return
redirect
(
django_settings
.
LOGIN_URL
)
else
:
pass
...
...
wiki/migrations/0002_auto__add_field_articleplugin_created.py
0 → 100644
View file @
6af3dcb8
This diff is collapsed.
Click to expand it.
wiki/models/__init__.py
View file @
6af3dcb8
...
...
@@ -56,7 +56,13 @@ original_django_reverse = urlresolvers.reverse
def
reverse
(
*
args
,
**
kwargs
):
"""Now this is a crazy and silly hack, but it is basically here to
enforce that an empty path always takes precedence over an article_id
such that the root article doesn't get resolved to /ID/ but /."""
such that the root article doesn't get resolved to /ID/ but /.
Another crazy hack that this supports is transforming every wiki url
by a function. If _transform_url is set on this function, it will
return the result of calling reverse._transform_url(reversed_url)
for every url in the wiki namespace.
"""
if
args
[
0
]
.
startswith
(
'wiki:'
):
url_kwargs
=
kwargs
.
get
(
'kwargs'
,
{})
path
=
url_kwargs
.
get
(
'path'
,
False
)
...
...
@@ -65,8 +71,14 @@ def reverse(*args, **kwargs):
url_kwargs
.
pop
(
'article_id'
,
None
)
url_kwargs
[
'path'
]
=
path
kwargs
[
'kwargs'
]
=
url_kwargs
url
=
original_django_reverse
(
*
args
,
**
kwargs
)
if
hasattr
(
reverse
,
'_transform_url'
):
url
=
reverse
.
_transform_url
(
url
)
else
:
url
=
original_django_reverse
(
*
args
,
**
kwargs
)
return
original_django_reverse
(
*
args
,
**
kwargs
)
return
url
# Now we redefine reverse method
urlresolvers
.
reverse
=
reverse
\ No newline at end of file
wiki/models/article.py
View file @
6af3dcb8
...
...
@@ -39,7 +39,8 @@ class Article(models.Model):
other_write
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
u'others write access'
))
def
can_read
(
self
,
user
=
None
,
group
=
None
):
if
self
.
other_read
:
is_other
=
(
user
and
not
user
.
is_anonymous
()
)
or
settings
.
ANONYMOUS
if
is_other
and
self
.
other_read
:
return
True
if
user
==
self
.
owner
:
return
True
...
...
@@ -53,7 +54,8 @@ class Article(models.Model):
return
False
def
can_write
(
self
,
user
=
None
,
group
=
None
):
if
self
.
other_write
:
is_other
=
(
user
and
not
user
.
is_anonymous
()
)
or
settings
.
ANONYMOUS
if
is_other
and
self
.
other_write
:
return
True
if
user
==
self
.
owner
:
return
True
...
...
wiki/models/urlpath.py
View file @
6af3dcb8
...
...
@@ -32,13 +32,17 @@ class URLPath(MPTTModel):
@property
def
path
(
self
):
if
not
self
.
parent
:
return
""
return
"/"
.
join
([
obj
.
slug
if
obj
.
slug
else
""
for
obj
in
self
.
get_ancestors
(
include_self
=
True
)
.
exclude
(
parent
=
None
)])
+
"/"
if
not
hasattr
(
self
,
'_cachedpath'
):
self
.
_cachedpath
=
"/"
.
join
([
obj
.
slug
if
obj
.
slug
else
""
for
obj
in
self
.
get_ancestors
(
include_self
=
True
)
.
exclude
(
parent
=
None
)])
+
"/"
return
self
.
_cachedpath
@classmethod
def
root
(
cls
):
site
=
Site
.
objects
.
get_current
()
root_nodes
=
cls
.
objects
.
root_nodes
()
.
filter
(
site
=
site
)
no_paths
=
root_nodes
.
count
()
root_nodes
=
list
(
cls
.
objects
.
root_nodes
()
.
filter
(
site
=
site
))
# We fetch the nodes as a list and use len(), not count() because we need
# to get the result out anyway. This only takes one sql query
no_paths
=
len
(
root_nodes
)
if
no_paths
==
0
:
raise
NoRootURL
(
"You need to create a root article on site '
%
s'"
%
site
)
if
no_paths
>
1
:
...
...
wiki/plugins/attachments/views.py
View file @
6af3dcb8
...
...
@@ -35,7 +35,7 @@ class AttachmentView(ArticleMixin, FormView):
# WARNING! The below decorator silences other exceptions that may occur!
#@transaction.commit_manually
def
form_valid
(
self
,
form
):
if
self
.
request
.
user
.
is_anonymous
and
not
settings
.
ANONYMOUS
:
if
self
.
request
.
user
.
is_anonymous
()
and
not
settings
.
ANONYMOUS
:
return
redirect
(
django_settings
.
LOGIN_URL
)
try
:
...
...
@@ -63,7 +63,7 @@ class AttachmentView(ArticleMixin, FormView):
kwargs
[
'attachments'
]
=
self
.
attachments
kwargs
[
'search_form'
]
=
forms
.
SearchForm
()
kwargs
[
'selected_tab'
]
=
'attachments'
kwargs
[
'anonymous_disallowed'
]
=
self
.
request
.
user
.
is_anonymous
and
not
settings
.
ANONYMOUS
kwargs
[
'anonymous_disallowed'
]
=
self
.
request
.
user
.
is_anonymous
()
and
not
settings
.
ANONYMOUS
return
super
(
AttachmentView
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
wiki/views/article.py
View file @
6af3dcb8
...
...
@@ -59,7 +59,7 @@ class Create(FormView, ArticleMixin):
def
form_valid
(
self
,
form
):
user
=
None
ip_address
=
None
if
not
self
.
request
.
user
.
is_anonymous
:
if
not
self
.
request
.
user
.
is_anonymous
()
:
user
=
self
.
request
.
user
if
settings
.
LOG_IPS_USERS
:
ip_address
=
self
.
request
.
META
.
get
(
'REMOTE_ADDR'
,
None
)
...
...
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