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
edx
django-wiki
Commits
36e87060
Commit
36e87060
authored
Feb 23, 2016
by
Saleem Latif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update django wiki to support multi-tenancy
parent
629fc2f6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
6 deletions
+72
-6
setup.py
+1
-1
testproject/testproject/settings.py
+1
-0
wiki/__init__.py
+1
-0
wiki/middleware.py
+62
-0
wiki/models/urlpath.py
+7
-5
No files found.
setup.py
View file @
36e87060
...
...
@@ -29,7 +29,7 @@ package_data = dict(
setup
(
name
=
"django-wiki"
,
version
=
"0.0.
5
"
,
version
=
"0.0.
6
"
,
author
=
"Benjamin Bach"
,
author_email
=
"benjamin@overtag.dk"
,
description
=
(
"A wiki system written for the Django framework."
),
...
...
testproject/testproject/settings.py
View file @
36e87060
...
...
@@ -69,6 +69,7 @@ MIDDLEWARE_CLASSES = (
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'wiki.middleware.RequestCache'
,
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
...
...
wiki/__init__.py
View file @
36e87060
from
middleware
import
get_current_request
wiki/middleware.py
0 → 100644
View file @
36e87060
import
threading
import
importlib
from
django.conf
import
settings
if
getattr
(
settings
,
"WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS"
,
None
):
class_name
=
settings
.
WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS
.
split
(
"."
)[
-
1
]
module
=
"."
.
join
(
settings
.
WIKI_REQUEST_CACHE_MIDDLEWARE_CLASS
.
split
(
'.'
)[:
-
1
])
RequestCache
=
getattr
(
importlib
.
import_module
(
module
),
class_name
)
else
:
class
_RequestCache
(
threading
.
local
):
"""
A thread-local for storing the per-request cache.
"""
def
__init__
(
self
):
super
(
_RequestCache
,
self
)
.
__init__
()
self
.
data
=
{}
self
.
request
=
None
REQUEST_CACHE
=
_RequestCache
()
class
RequestCache
(
object
):
@classmethod
def
get_request_cache
(
cls
,
name
=
None
):
"""
This method is deprecated. Please use :func:`request_cache.get_cache`.
"""
if
name
is
None
:
return
REQUEST_CACHE
else
:
return
REQUEST_CACHE
.
data
.
setdefault
(
name
,
{})
@classmethod
def
get_current_request
(
cls
):
"""
This method is deprecated. Please use :func:`request_cache.get_request`.
"""
return
REQUEST_CACHE
.
request
@classmethod
def
clear_request_cache
(
cls
):
"""
Empty the request cache.
"""
REQUEST_CACHE
.
data
=
{}
REQUEST_CACHE
.
request
=
None
def
process_request
(
self
,
request
):
self
.
clear_request_cache
()
REQUEST_CACHE
.
request
=
request
return
None
def
process_response
(
self
,
request
,
response
):
self
.
clear_request_cache
()
return
response
def
get_current_request
():
"""Return the request associated with the current thread."""
return
RequestCache
.
get_current_request
()
wiki/models/urlpath.py
View file @
36e87060
...
...
@@ -4,6 +4,7 @@ import logging
from
django.contrib.contenttypes
import
fields
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.sites.models
import
Site
from
django.contrib.sites.shortcuts
import
get_current_site
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.db
import
models
,
transaction
...
...
@@ -14,6 +15,7 @@ from mptt.fields import TreeForeignKey
from
mptt.models
import
MPTTModel
from
wiki
import
managers
from
wiki
import
get_current_request
from
wiki.conf
import
settings
from
wiki.core.exceptions
import
NoRootURL
,
MultipleRootURLs
from
wiki.models.article
import
ArticleRevision
,
ArticleForObject
,
Article
...
...
@@ -110,7 +112,7 @@ class URLPath(MPTTModel):
@classmethod
def
root
(
cls
):
site
=
Site
.
objects
.
get_current
(
)
site
=
get_current_site
(
get_current_request
()
)
root_nodes
=
list
(
cls
.
objects
.
root_nodes
()
.
filter
(
site
=
site
)
.
select_related_common
()
)
...
...
@@ -192,7 +194,7 @@ class URLPath(MPTTModel):
@classmethod
def
create_root
(
cls
,
site
=
None
,
title
=
"Root"
,
**
kwargs
):
if
not
site
:
site
=
Site
.
objects
.
get_current
(
)
if
not
site
:
site
=
get_current_site
(
get_current_request
()
)
root_nodes
=
cls
.
objects
.
root_nodes
()
.
filter
(
site
=
site
)
if
not
root_nodes
:
# (get_or_create does not work for MPTT models??)
...
...
@@ -210,7 +212,7 @@ class URLPath(MPTTModel):
def
create_article
(
cls
,
parent
,
slug
,
site
=
None
,
title
=
"Root"
,
article_kwargs
=
{},
**
kwargs
):
"""Utility function:
Create a new urlpath with an article and a new revision for the article"""
if
not
site
:
site
=
Site
.
objects
.
get_current
(
)
if
not
site
:
site
=
get_current_site
(
get_current_request
()
)
article
=
Article
(
**
article_kwargs
)
article
.
add_revision
(
ArticleRevision
(
title
=
title
,
**
kwargs
),
save
=
True
)
...
...
@@ -241,8 +243,8 @@ post_save.connect(on_article_relation_save, ArticleForObject)
def
on_article_delete
(
instance
,
*
args
,
**
kwargs
):
# If an article is deleted, then throw out its URLPaths
# But move all descendants to a lost-and-found node.
site
=
Site
.
objects
.
get_current
(
)
site
=
get_current_site
(
get_current_request
()
)
# Get the Lost-and-found path or create a new one
try
:
lost_and_found
=
URLPath
.
objects
.
get
(
slug
=
settings
.
LOST_AND_FOUND_SLUG
,
...
...
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