Exemplo n.º 1
0
    def response_change(self, request, obj):
        """
        Overrides the default to be able to forward to the directory listing
        instead of the default change_list_view
        """
        r = super(FileAdmin, self).response_change(request, obj)
        if 'Location' in r and r['Location']:
            # it was a successful save
            if (r['Location'] in ['../']
                    or r['Location'] == self._get_post_url(obj)):
                # this means it was a save: redirect to the directory view
                if obj.folder:
                    url = reverse('admin:filer-directory_listing',
                                  kwargs={'folder_id': obj.folder.id})
                else:
                    url = reverse(
                        'admin:filer-directory_listing-unfiled_images')
                url = "%s%s%s" % (url, popup_param(request),
                                  selectfolder_param(request, "&"))
                return HttpResponseRedirect(url)
            else:
                # this means it probably was a save_and_continue_editing
                pass
        else:
            # this means it was a save: redirect to the directory view
            if obj.folder:
                url = reverse('admin:filer-directory_listing',
                              kwargs={'folder_id': obj.folder.id})
            else:
                url = reverse('admin:filer-directory_listing-unfiled_images')
            url = "%s%s%s" % (url, popup_param(request),
                              selectfolder_param(request, "&"))
            return HttpResponseRedirect(url)

        return r
Exemplo n.º 2
0
    def response_change(self, request, obj):
        """
        Overrides the default to be able to forward to the directory listing
        instead of the default change_list_view
        """
        r = super(FileAdmin, self).response_change(request, obj)
        if 'Location' in r and r['Location']:
            # it was a successful save
            if (r['Location'] in ['../'] or
                    r['Location'] == self._get_post_url(obj)):
                # this means it was a save: redirect to the directory view
                if obj.folder:
                    url = reverse('admin:filer-directory_listing',
                                  kwargs={'folder_id': obj.folder.id})
                else:
                    url = reverse(
                        'admin:filer-directory_listing-unfiled_images')
                url = "%s%s%s" % (url, popup_param(request),
                                  selectfolder_param(request, "&"))
                return HttpResponseRedirect(url)
            else:
                # this means it probably was a save_and_continue_editing
                pass
        else:
            # this means it was a save: redirect to the directory view
            if obj.folder:
                url = reverse('admin:filer-directory_listing',
                              kwargs={'folder_id': obj.folder.id})
            else:
                url = reverse(
                    'admin:filer-directory_listing-unfiled_images')
            url = "%s%s%s" % (url, popup_param(request),
                              selectfolder_param(request, "&"))
            return HttpResponseRedirect(url)

        return r
Exemplo n.º 3
0
    def delete_view(self, request, object_id, extra_context=None):
        """
        Overrides the default to enable redirecting to the directory view after
        deletion of a image.

        we need to fetch the object and find out who the parent is
        before super, because super will delete the object and make it
        impossible to find out the parent folder to redirect to.
        """
        parent_folder = None
        try:
            obj = self.get_queryset(request).get(pk=unquote(object_id))
            parent_folder = obj.folder
        except self.model.DoesNotExist:
            obj = None

        r = super(FileAdmin, self).delete_view(
            request=request, object_id=object_id,
            extra_context=extra_context)

        url = r.get("Location", None)

        # Check against filer_file_changelist as file deletion is always made by
        # the base class
        if (url in ["../../../../", "../../"] or
                url == reverse("admin:media_file_changelist") or
                url == reverse("admin:media_image_changelist")):
            if parent_folder:
                url = reverse('admin:filer-directory_listing',
                              kwargs={'folder_id': parent_folder.id})
            else:
                url = reverse('admin:filer-directory_listing-unfiled_images')
            url = "%s%s%s" % (url, popup_param(request),
                              selectfolder_param(request, "&"))
            return HttpResponseRedirect(url)
        return r
Exemplo n.º 4
0
    def delete_view(self, request, object_id, extra_context=None):
        """
        Overrides the default to enable redirecting to the directory view after
        deletion of a image.

        we need to fetch the object and find out who the parent is
        before super, because super will delete the object and make it
        impossible to find out the parent folder to redirect to.
        """
        parent_folder = None
        try:
            obj = self.get_queryset(request).get(pk=unquote(object_id))
            parent_folder = obj.folder
        except self.model.DoesNotExist:
            obj = None

        r = super(FileAdmin, self).delete_view(request=request,
                                               object_id=object_id,
                                               extra_context=extra_context)

        url = r.get("Location", None)

        # Check against filer_file_changelist as file deletion is always made by
        # the base class
        if (url in ["../../../../", "../../"]
                or url == reverse("admin:media_file_changelist")
                or url == reverse("admin:media_image_changelist")):
            if parent_folder:
                url = reverse('admin:filer-directory_listing',
                              kwargs={'folder_id': parent_folder.id})
            else:
                url = reverse('admin:filer-directory_listing-unfiled_images')
            url = "%s%s%s" % (url, popup_param(request),
                              selectfolder_param(request, "&"))
            return HttpResponseRedirect(url)
        return r