summaryrefslogtreecommitdiff
path: root/tests/admin_views/admin.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2013-05-29 10:55:56 -0400
committerTim Graham <timograham@gmail.com>2013-05-29 11:25:42 -0400
commitd727518ad61beda4d9c2b744c9c05a805aa23ed1 (patch)
treea451ad2b488bc1a466a522f5f183a8af7981c99a /tests/admin_views/admin.py
parent8010289ea2f30f0bb819feba7ec78e67c198023b (diff)
Fixed #20331 -- Allowed admin actions to serve StreamingHttpResponses
Thanks Edwin.
Diffstat (limited to 'tests/admin_views/admin.py')
-rw-r--r--tests/admin_views/admin.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py
index 4ab7844ef7..a6ad7cc0bc 100644
--- a/tests/admin_views/admin.py
+++ b/tests/admin_views/admin.py
@@ -9,11 +9,13 @@ from django.contrib import admin
from django.contrib.admin.views.main import ChangeList
from django.core.files.storage import FileSystemStorage
from django.core.mail import EmailMessage
+from django.core.servers.basehttp import FileWrapper
from django.conf.urls import patterns, url
from django.db import models
from django.forms.models import BaseModelFormSet
-from django.http import HttpResponse
+from django.http import HttpResponse, StreamingHttpResponse
from django.contrib.admin import BooleanFieldListFilter
+from django.utils.six import StringIO
from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
Widget, DooHickey, Grommet, Whatsit, FancyDoodad, Category, Link,
@@ -238,8 +240,20 @@ def redirect_to(modeladmin, request, selected):
redirect_to.short_description = 'Redirect to (Awesome action)'
+def download(modeladmin, request, selected):
+ buf = StringIO('This is the content of the file')
+ return StreamingHttpResponse(FileWrapper(buf))
+download.short_description = 'Download subscription'
+
+
+def no_perm(modeladmin, request, selected):
+ return HttpResponse(content='No permission to perform this action',
+ status=403)
+no_perm.short_description = 'No permission to run'
+
+
class ExternalSubscriberAdmin(admin.ModelAdmin):
- actions = [redirect_to, external_mail]
+ actions = [redirect_to, external_mail, download, no_perm]
class Podcast(Media):