Commit 7f6acb73 by benjaoming

#119 do not fail when deleting blank image and attachment fields

parent 51497ca2
...@@ -166,7 +166,11 @@ def on_revision_delete(instance, *args, **kwargs): ...@@ -166,7 +166,11 @@ def on_revision_delete(instance, *args, **kwargs):
max_depth = 1 max_depth = 1
for depth in range(0, max_depth): for depth in range(0, max_depth):
delete_path = "/".join(path[:-depth] if depth > 0 else path) delete_path = "/".join(path[:-depth] if depth > 0 else path)
if len(os.listdir(os.path.join(django_settings.MEDIA_ROOT, delete_path))) == 0: try:
os.rmdir(delete_path) if len(os.listdir(os.path.join(django_settings.MEDIA_ROOT, delete_path))) == 0:
os.rmdir(delete_path)
except OSError:
# Raised by os.listdir if directory is missing
pass
signals.pre_delete.connect(on_revision_delete, AttachmentRevision) signals.pre_delete.connect(on_revision_delete, AttachmentRevision)
...@@ -103,6 +103,8 @@ class ImageRevision(RevisionPluginRevision): ...@@ -103,6 +103,8 @@ class ImageRevision(RevisionPluginRevision):
def on_image_revision_delete(instance, *args, **kwargs): def on_image_revision_delete(instance, *args, **kwargs):
if not instance.image:
return
# Remove image file # Remove image file
path = instance.image.path.split("/")[:-1] path = instance.image.path.split("/")[:-1]
instance.image.delete(save=False) instance.image.delete(save=False)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{% block pagetitle %}{% endblock %} -- django-\/\/ i K |</title> <title>{% block pagetitle %}{% endblock %} - django-\/\/ i K |</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content=""> <meta name="description" content="">
<meta name="author" content="www.django-wiki.org"> <meta name="author" content="www.django-wiki.org">
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
</a> </a>
{% block wiki_header_branding %} {% block wiki_header_branding %}
<a class="brand" href="{% url 'wiki:root' %}">django-wiki</a> <a class="brand" href="{% url 'wiki:root' %}">django-\/\/ i K |</a>
{% endblock %} {% endblock %}
<form class="navbar-search pull-right" id="navbar_wiki_search" method="GET" action="{% url 'wiki:search' %}"> <form class="navbar-search pull-right" id="navbar_wiki_search" method="GET" action="{% url 'wiki:search' %}">
<span class="icon-search"></span> <span class="icon-search"></span>
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""This is nothing but the usual handling of django user accounts, so """Here is a very basic handling of accounts."""
go ahead and replace it or disable it!"""
from django.conf import settings as django_settings from django.conf import settings as django_settings
from django.contrib import messages from django.contrib import messages
......
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