Commit 0012481a by benjaoming

Merge branch 'master' of github.com:benjaoming/django-wiki

parents c0d7e2ab 63003aa6
# -*- 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()
......
......@@ -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 %}
......
......@@ -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()
......@@ -509,6 +508,7 @@ class Settings(ArticleMixin, TemplateView):
# could be mixed up with a different instance
# Use strategy from Edit view...
setattr(settings_forms[i], 'action', 'form%d' % i)
return settings_forms
def post(self, *args, **kwargs):
......@@ -531,8 +531,14 @@ class Settings(ArticleMixin, TemplateView):
def get(self, *args, **kwargs):
self.forms = []
# There is a bug where articles fetched with select_related have bad boolean field https://code.djangoproject.com/ticket/15040
# We fetch a fresh new article for this reason
new_article = models.Article.objects.get(id=self.article.id)
for Form in self.get_form_classes():
self.forms.append(Form(self.article, self.request))
self.forms.append(Form(new_article, self.request))
return super(Settings, self).get(*args, **kwargs)
def get_success_url(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment