Repository: django-wiki/django-wiki

Issue:
[Bug] NotImplemented is not an exception
https://github.com/django-wiki/django-wiki/blob/a144a3110cc688d796895aa1caddc4db1a4b62c6/src/wiki/plugins/images/models.py#L122

I think this is a bug as 'NotImplemented" is not an exception but a singleton. Delete lines 120-124?

[Docs](https://docs.python.org/3.6/library/constants.html#NotImplemented)


Discussion:

Resolving patch:
diff --git a/src/wiki/plugins/images/models.py b/src/wiki/plugins/images/models.py
--- a/src/wiki/plugins/images/models.py
+++ b/src/wiki/plugins/images/models.py
@@ -110,16 +110,10 @@ def on_image_revision_delete(instance, *args, **kwargs):
 
     # Remove image file
     instance.image.delete(save=False)
-    
-    try:
-        path = instance.image.path.split("/")[:-1]
-    except NotImplementedError:
-            # This backend storage doesn't implement 'path' so there is no path to delete
-        return
 
     try:
         path = instance.image.path.split("/")[:-1]
-    except NotImplemented:
+    except NotImplementedError:
             # This backend storage doesn't implement 'path' so there is no path to delete
         return
 


Test patch:
diff --git a/tests/plugins/images/test_views.py b/tests/plugins/images/test_views.py
--- a/tests/plugins/images/test_views.py
+++ b/tests/plugins/images/test_views.py
@@ -1,4 +1,5 @@
 import base64
+import os
 from io import BytesIO
 
 from django.core.files.uploadedfile import InMemoryUploadedFile
@@ -166,6 +167,62 @@ def test_add_revision(self):
         self.assertEqual(models.Image.objects.count(), 1)
         self.assertEqual(image.current_revision.previous_revision.revision_number, before_edit_rev)
 
+    def test_delete_restore_revision(self):
+        self._create_test_image(path='')
+        image = models.Image.objects.get()
+        before_edit_rev = image.current_revision.revision_number
+
+        response = self.client.get(
+            reverse('wiki:images_delete', kwargs={
+                'article_id': self.root_article, 'image_id': image.pk, 'path': '',
+            }),
+        )
+        self.assertRedirects(
+            response, reverse('wiki:images_index', kwargs={'path': ''})
+        )
+        image = models.Image.objects.get()
+        self.assertEqual(models.Image.objects.count(), 1)
+        self.assertEqual(image.current_revision.previous_revision.revision_number, before_edit_rev)
+        self.assertTrue(image.current_revision.deleted)
+
+        # RESTORE
+        before_edit_rev = image.current_revision.revision_number
+        response = self.client.get(
+            reverse('wiki:images_restore', kwargs={
+                'article_id': self.root_article, 'image_id': image.pk, 'path': '',
+            }),
+        )
+        self.assertRedirects(
+            response, reverse('wiki:images_index', kwargs={'path': ''})
+        )
+        image = models.Image.objects.get()
+        self.assertEqual(models.Image.objects.count(), 1)
+        self.assertEqual(image.current_revision.previous_revision.revision_number, before_edit_rev)
+        self.assertFalse(image.current_revision.deleted)
+
+    def test_purge(self):
+        """
+        Tests that an image is really purged
+        """
+        self._create_test_image(path='')
+        image = models.Image.objects.get()
+        image_revision = image.current_revision.imagerevision
+        f_path = image_revision.image.file.name
+
+        self.assertTrue(os.path.exists(f_path))
+
+        response = self.client.post(
+            reverse('wiki:images_purge', kwargs={
+                'article_id': self.root_article, 'image_id': image.pk, 'path': '',
+            }),
+            data={'confirm': True}
+        )
+        self.assertRedirects(
+            response, reverse('wiki:images_index', kwargs={'path': ''})
+        )
+        self.assertEqual(models.Image.objects.count(), 0)
+        self.assertFalse(os.path.exists(f_path))
+
     @wiki_override_settings(ACCOUNT_HANDLING=True)
     def test_login_on_revision_add(self):
         self._create_test_image(path='')