[Patchew-devel] [PATCH 3/3] maintainer: allow downloading queue mbox

Paolo Bonzini posted 3 patches 2 years, 4 months ago
[Patchew-devel] [PATCH 3/3] maintainer: allow downloading queue mbox
Posted by Paolo Bonzini 2 years, 4 months ago
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/models.py      |  7 +++++--
 mods/maintainer.py | 24 ++++++++++++++++++++----
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/api/models.py b/api/models.py
index 18392b1..2c503ed 100644
--- a/api/models.py
+++ b/api/models.py
@@ -688,7 +688,7 @@ class Message(models.Model):
         container.set_payload(payload, charset="utf-8")
         return msg.as_bytes(unixfrom=True)
 
-    def get_mbox_with_tags(self):
+    def get_mboxes_with_tags(self):
         if not self.is_patch:
             if not self.is_complete:
                 return None
@@ -701,7 +701,10 @@ class Message(models.Model):
         mbox_list = []
         for message in messages:
             mbox_list.append(message._get_mbox_with_tags(series_tags))
-        return b"\n".join(mbox_list)
+        return mbox_list
+
+    def get_mbox_with_tags(self):
+        return b"\n".join(self.get_mboxes_with_tags())
 
     def get_num(self):
         assert self.is_patch or self.is_series_head
diff --git a/mods/maintainer.py b/mods/maintainer.py
index d650ec4..4d4d7e9 100644
--- a/mods/maintainer.py
+++ b/mods/maintainer.py
@@ -11,7 +11,7 @@
 import re
 from django.conf.urls import url
 from django.core.exceptions import PermissionDenied
-from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest
+from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
 from django.urls import reverse
 from mod import PatchewModule
 from api.models import Message, QueuedSeries, Project, WatchedQuery
@@ -165,7 +165,7 @@ class MaintainerModule(PatchewModule):
         self._drop_from_queue(request.user, m, queue)
         return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
 
-    def www_view_queue(self, request, project, name):
+    def query_queue(self, request, project, name):
         if not request.user.is_authenticated:
             raise PermissionDenied()
 
@@ -175,12 +175,27 @@ class MaintainerModule(PatchewModule):
         po = Project.objects.filter(name=project).first()
         if not po:
             raise Http404("Project not found")
+        return Message.objects.series_heads(po.id).filter(queuedseries=q)
 
+    def www_download_queue_mbox(self, request, project, name):
+        query = self.query_queue(request, project, name).filter(is_complete=True)
+        mbox_list = []
+        for s in query:
+            mbox_list.extend(s.get_mboxes_with_tags())
+        mbox = b"\n".join(mbox_list)
+        return HttpResponse(mbox, content_type="text/plain")
+
+    def www_view_queue(self, request, project, name):
+        query = self.query_queue(request, project, name)
         search = 'project:' + project + ' queue:' + name
-        query = Message.objects.series_heads(po.id).filter(queuedseries=q)
         return render_series_list_page(request, query,
                                        search=search, project=project,
-                                       title='"' + name + '" queue')
+                                       title='"' + name + '" queue',
+                                       link_icon='fa fa-download',
+                                       link_text='Download mbox',
+                                       link_url=reverse("maintainer_queue_mbox",
+                                                        kwargs={"project": project,
+                                                                "name": name}))
 
     def www_view_my_queues(self, request, project=None):
         if not request.user.is_authenticated:
@@ -274,6 +289,7 @@ class MaintainerModule(PatchewModule):
             )
         )
         urlpatterns.append(url(r"^my-queues/(?P<project>[^/]*)/(?P<name>[^/]*)/$", self.www_view_queue, name="maintainer_queue"))
+        urlpatterns.append(url(r"^my-queues/(?P<project>[^/]*)/(?P<name>[^/]*)/mbox$", self.www_download_queue_mbox, name="maintainer_queue_mbox"))
         urlpatterns.append(url(r"^my-queues/(?P<project>[^/]*)/$", self.www_view_my_queues))
         urlpatterns.append(url(r"^my-queues/$", self.www_view_my_queues))
         urlpatterns.append(url(r"^watch-query/$", self.www_view_watch_query))
-- 
2.34.1

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/patchew-devel