def delete_model(self, request, obj):
# Retrieve the bin page or create it
try:
p = Page.objects.get(title_set__title=BIN_PAGE_NAME)
except ObjectDoesNotExist:
p = api.create_page(BIN_PAGE_NAME, constants.TEMPLATE_INHERITANCE_MAGIC, BIN_PAGE_LANGUAGE)
except MultipleObjectsReturned:
p = Page.objects.filter(title_set__title=BIN_PAGE_NAME).first()
# is the page already under the ~BIN folder?
is_in_bin = False
q = obj
while q:
if q.title_set.filter(title=BIN_PAGE_NAME).count() > 0:
is_in_bin = True
break
q = q.parent
# if yes -> delete it
if is_in_bin:
obj.delete()
p.fix_tree()
return
# else -> move it to the bin folder
# split the contents of the bin into buckets (too many children will slow the javascript down
bucket_title = datetime.datetime.now().strftime(BIN_BUCKET_NAMING)
try:
bucket = Page.objects.get(title_set__title=bucket_title)
except ObjectDoesNotExist:
bucket = api.create_page(bucket_title, constants.TEMPLATE_INHERITANCE_MAGIC,
BIN_PAGE_LANGUAGE, parent=p)
obj.move_page(bucket)
p.fix_tree()
obj.fix_tree()
bucket.fix_tree()
评论列表
文章目录