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
cdb2c3a8
Commit
cdb2c3a8
authored
Aug 15, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a bit of caching to retrieving path, so it doesn't make so many sql queries.
parent
6c9e1a03
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
wiki/models/urlpath.py
+7
-3
No files found.
wiki/models/urlpath.py
View file @
cdb2c3a8
...
...
@@ -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
:
...
...
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