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
1d3677b3
Commit
1d3677b3
authored
Aug 17, 2012
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prefetch and swap lookups such that path is always looked up before article_id
parent
6af3dcb8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
wiki/decorators.py
+21
-8
No files found.
wiki/decorators.py
View file @
1d3677b3
...
...
@@ -46,16 +46,15 @@ def get_article(func=None, can_read=True, can_write=False, deleted_contents=Fals
articles
=
models
.
Article
.
objects
# TODO: Is this the way to do it?
articles
=
articles
.
select_related
()
# https://docs.djangoproject.com/en/1.4/ref/models/querysets/#django.db.models.query.QuerySet.prefetch_related
# This is not the way to go... optimize below statements to behave
# according to normal prefetching.
articles
=
articles
.
prefetch_related
()
urlpath
=
None
if
article_id
:
article
=
get_object_or_404
(
articles
,
id
=
article_id
)
try
:
urlpath
=
models
.
URLPath
.
objects
.
get
(
articles__article
=
article
)
except
models
.
URLPath
.
DoesNotExist
,
models
.
URLPath
.
MultipleObjectsReturned
:
urlpath
=
None
else
:
# fetch by urlpath.path
if
not
path
is
None
:
try
:
urlpath
=
models
.
URLPath
.
get_by_path
(
path
,
select_related
=
True
)
except
NoRootURL
:
...
...
@@ -77,6 +76,20 @@ def get_article(func=None, can_read=True, can_write=False, deleted_contents=Fals
urlpath
.
delete
()
return
redirect
(
return_url
)
# fetch by article.id
if
article_id
:
article
=
get_object_or_404
(
articles
,
id
=
article_id
)
try
:
urlpath
=
models
.
URLPath
.
objects
.
get
(
articles__article
=
article
)
except
models
.
URLPath
.
DoesNotExist
,
models
.
URLPath
.
MultipleObjectsReturned
:
urlpath
=
None
else
:
# TODO: Return something??
raise
TypeError
(
'You should specify either article_id or path'
)
if
can_read
and
not
article
.
can_read
(
request
.
user
):
if
request
.
user
.
is_anonymous
():
return
redirect
(
django_settings
.
LOGIN_URL
)
...
...
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