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
6ccd08e0
Commit
6ccd08e0
authored
Aug 22, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved subtree delete to a model method with transactions.
parent
c2cfcc2a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
wiki/models/urlpath.py
+23
-1
wiki/templates/wiki/error.html
+1
-1
wiki/views/article.py
+1
-2
No files found.
wiki/models/urlpath.py
View file @
6ccd08e0
# -*- coding: utf-8 -*-
import
logging
from
django.contrib.contenttypes
import
generic
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.sites.models
import
Site
from
django.core.exceptions
import
ValidationError
from
django.core.urlresolvers
import
reverse
from
django.db
import
models
from
django.db
import
models
,
transaction
from
django.db.models.signals
import
pre_delete
,
post_save
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext
...
...
@@ -16,6 +18,8 @@ from wiki.conf import settings
from
wiki.core.exceptions
import
NoRootURL
,
MultipleRootURLs
from
wiki.models.article
import
ArticleRevision
,
ArticleForObject
,
Article
log
=
logging
.
getLogger
(
__name__
)
class
URLPath
(
MPTTModel
):
"""
Strategy: Very few fields go here, as most has to be managed through an
...
...
@@ -89,6 +93,24 @@ class URLPath(MPTTModel):
return
ancestor
return
None
@transaction.commit_manually
def
delete_subtree
(
self
):
"""
NB! This deletes this urlpath, its children, and ALL of the related
articles. This is a purged delete and CANNOT be undone.
"""
try
:
for
descendant
in
self
.
get_descendants
(
include_self
=
True
)
.
order_by
(
"-level"
):
print
"deleting "
,
descendant
descendant
.
article
.
delete
()
transaction
.
commit
()
except
:
transaction
.
rollback
()
log
.
exception
(
"Exception deleting article subtree."
)
@classmethod
def
root
(
cls
):
site
=
Site
.
objects
.
get_current
()
...
...
wiki/templates/wiki/error.html
View file @
6ccd08e0
...
...
@@ -13,7 +13,7 @@
{% if error_type == "ancestors_missing" %}
<div
class=
"missing"
>
<p>
This article was not found, and neither was its parent article.
<a
href=
"{% url 'wiki:get' path='' %}"
>
Go
back
to the main wiki article
</a></p>
<p>
This article was not found, and neither was its parent article.
<a
href=
"{% url 'wiki:get' path='' %}"
>
Go to the main wiki article
</a></p>
</div>
{% else %}
...
...
wiki/views/article.py
View file @
6ccd08e0
...
...
@@ -176,8 +176,7 @@ class Delete(FormView, ArticleMixin):
if
can_moderate
and
purge
:
# First, remove children
if
self
.
urlpath
:
for
descendant
in
self
.
urlpath
.
get_descendants
(
include_self
=
True
):
descendant
.
article
.
delete
()
self
.
urlpath
.
delete_subtree
()
else
:
self
.
article
.
delete
()
...
...
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