~netlandish/django-wiki

90e20e0cfff513ddae668a0705701832a6db054f — Benjamin Bach 8 years ago 98f5da6
Image soft deletion was out of order, fixes #533
M wiki/plugins/images/markdown_extensions.py => wiki/plugins/images/markdown_extensions.py +0 -1
@@ 12,7 12,6 @@ IMAGE_RE = re.compile(
    re.IGNORECASE)



class ImageExtension(markdown.Extension):

    """ Images plugin markdown extension for django-wiki. """

M wiki/plugins/images/models.py => wiki/plugins/images/models.py +6 -1
@@ 91,8 91,13 @@ class ImageRevision(RevisionPluginRevision):
        """
        Inherit certain properties from predecessor because it's very
        convenient. Remember to always call this method before
        setting properties :)"""
        setting properties :)

        A revision may not have a predecessor if the property is unset, it may
        be unset if it's the initial history entry.
        """
        predecessor = image.current_revision.imagerevision
        super(ImageRevision, self).inherit_predecessor(image)
        self.plugin = predecessor.plugin
        self.deleted = predecessor.deleted
        self.locked = predecessor.locked

M wiki/plugins/images/templates/wiki/plugins/images/index.html => wiki/plugins/images/templates/wiki/plugins/images/index.html +2 -2
@@ 36,7 36,7 @@
              {% trans "Upload and publish new image" %}
            </a> <br />
            <a href="{% url 'wiki:images_restore' path=urlpath.path article_id=article.id image_id=image.id %}">
              <span class="fa ra-repeat"></span>
              <span class="fa fa-refresh"></span>
              {% trans "Restore image" %}
            </a>
          {% else %}


@@ 84,7 84,7 @@
              <td>{{ old_revision.imagerevision.width }}x{{ old_revision.imagerevision.height }}</td>
              <td>
                {% if image|can_write:user and old_revision != image.current_revision %}
                  <a href="#">
                  <a href="{% url 'wiki:images_set_revision' path=urlpath.path article_id=article.id image_id=image.id rev_id=old_revision.id %}">
                    <span class="fa fa-refresh"></span>
                    {% trans "Revert to this version" %}
                  </a>

M wiki/plugins/images/views.py => wiki/plugins/images/views.py +13 -0
@@ 1,5 1,7 @@
from __future__ import absolute_import, unicode_literals

import logging

from django.contrib import messages
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404, redirect


@@ 10,9 12,12 @@ from django.views.generic.edit import FormView
from django.views.generic.list import ListView
from wiki.conf import settings as wiki_settings
from wiki.decorators import get_article
from wiki.models.pluginbase import RevisionPluginRevision
from wiki.plugins.images import forms, models
from wiki.views.mixins import ArticleMixin

logger = logging.getLogger(__name__)


class ImageView(ArticleMixin, ListView):



@@ 60,9 65,17 @@ class DeleteView(ArticleMixin, RedirectView):

    def get_redirect_url(self, **kwargs):

        if not self.image.current_revision:
            logger.critical('Encountered an image without current revision set, ID: {}'.format(self.image.id))
            latest_revision = RevisionPluginRevision.objects.filter(
                plugin=self.image
            ).latest('pk')
            self.image.current_revision = latest_revision

        new_revision = models.ImageRevision()
        new_revision.inherit_predecessor(self.image)
        new_revision.set_from_request(self.request)
        new_revision.revision_number = RevisionPluginRevision.objects.filter(plugin=self.image).count()
        new_revision.deleted = not self.restore
        new_revision.save()
        self.image.current_revision = new_revision

M wiki/plugins/images/wiki_plugin.py => wiki/plugins/images/wiki_plugin.py +1 -1
@@ 60,7 60,7 @@ class ImagePlugin(BasePlugin):
            name='images_purge'),
        url('^(?P<image_id>\d+)/revision/change/(?P<rev_id>\d+)/$',
            views.RevisionChangeView.as_view(),
            name='images_restore'),
            name='images_set_revision'),
        url('^(?P<image_id>\d+)/revision/add/$',
            views.RevisionAddView.as_view(),
            name='images_add_revision'),