[PATCH] Allow to download public bundle as mbox

Simo Sorce idra at samba.org
Tue Nov 6 12:15:20 EST 2012


Downloading single patches anonimously is allowed, we may as well allow
downloading public bundles as mboxes.

Signed-off-by: Simo Sorce <idra at samba.org>
---
 apps/patchwork/urls.py                 |  2 ++
 apps/patchwork/views/bundle.py         | 18 +++++++++++++-----
 templates/patchwork/bundle-public.html |  2 ++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/apps/patchwork/urls.py b/apps/patchwork/urls.py
index 10fc3b9..3209830 100644
--- a/apps/patchwork/urls.py
+++ b/apps/patchwork/urls.py
@@ -67,6 +67,8 @@ urlpatterns = patterns('',
     # public view for bundles
     (r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/$',
                                 'patchwork.views.bundle.public'),
+    (r'^bundle/(?P<username>[^/]*)/(?P<bundlename>[^/]*)/mbox/$',
+                                'patchwork.views.bundle.public_mbox'),
 
     (r'^confirm/(?P<key>[0-9a-f]+)/$', 'patchwork.views.confirm'),
 
diff --git a/apps/patchwork/views/bundle.py b/apps/patchwork/views/bundle.py
index e418b3a..e592bca 100644
--- a/apps/patchwork/views/bundle.py
+++ b/apps/patchwork/views/bundle.py
@@ -168,15 +168,18 @@ def bundle(request, bundle_id):
 
     return render_to_response('patchwork/bundle.html', context)
 
- at login_required
-def mbox(request, bundle_id):
-    bundle = get_object_or_404(Bundle, id = bundle_id)
+def mbox_response(bundle, name):
     response = HttpResponse(mimetype='text/plain')
-    response['Content-Disposition'] = 'attachment; filename=bundle-%d.mbox' % \
-        bundle.id
+    response['Content-Disposition'] = 'attachment; filename=bundle-%s.mbox' % \
+        name
     response.write(bundle.mbox())
     return response
 
+ at login_required
+def mbox(request, bundle_id):
+    bundle = get_object_or_404(Bundle, id = bundle_id)
+    return mbox_response(bundle, str(bundle.id))
+
 def public(request, username, bundlename):
     user = get_object_or_404(User, username = username)
     bundle = get_object_or_404(Bundle, name = bundlename, owner = user,
@@ -191,3 +194,8 @@ def public(request, username, bundlename):
     context['bundle'] = bundle
 
     return render_to_response('patchwork/bundle-public.html', context)
+
+def public_mbox(request, username, bundlename):
+    bundle = get_object_or_404(Bundle, name = bundlename, public = True)
+    return mbox_response(bundle, bundle.name)
+    return response
diff --git a/templates/patchwork/bundle-public.html b/templates/patchwork/bundle-public.html
index 3590c46..4947a7e 100644
--- a/templates/patchwork/bundle-public.html
+++ b/templates/patchwork/bundle-public.html
@@ -7,6 +7,8 @@
 
 {% block body %}
 
+<a href="{% url patchwork.views.bundle.public_mbox username=bundle.owner bundlename=bundle.name %}">Download</a> bundle as mbox
+
 {% include "patchwork/patch-list.html" %}
 
 {% endblock %}
-- 
1.7.12.1



More information about the Patchwork mailing list