[Patchew-devel] [PATCH 5/7] rest: pass request to hooks

Paolo Bonzini posted 7 patches 6 years, 3 months ago
[Patchew-devel] [PATCH 5/7] rest: pass request to hooks
Posted by Paolo Bonzini 6 years, 3 months ago
The request is needed by rest_framework.reverse.reverse.  It is already
passed to the plugins via PluginMethodField, pass it to the hooks as
well.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 api/rest.py     | 12 +++++++++---
 mods/diff.py    |  2 +-
 mods/git.py     |  2 +-
 mods/tags.py    |  2 +-
 mods/testing.py |  2 +-
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/api/rest.py b/api/rest.py
index be774a9..7c131a4 100644
--- a/api/rest.py
+++ b/api/rest.py
@@ -171,12 +171,16 @@ class SeriesSerializer(BaseMessageSerializer):
 
     def get_fields(self):
         fields = super(SeriesSerializer, self).get_fields()
-        dispatch_module_hook("rest_series_fields_hook", fields=fields, detailed=self.detailed)
+        request = self.context['request']
+        dispatch_module_hook("rest_series_fields_hook", request=request,
+                             fields=fields, detailed=self.detailed)
         return fields
 
     def get_results(self, message):
         results = {}
-        dispatch_module_hook("rest_results_hook", message=message, results=results)
+        request = self.context['request']
+        dispatch_module_hook("rest_results_hook", request=request,
+                             message=message, results=results)
         return results
 
     def get_total_patches(self, obj):
@@ -276,7 +280,9 @@ class MessageSerializer(BaseMessageSerializer):
 
     def get_fields(self):
         fields = super(MessageSerializer, self).get_fields()
-        dispatch_module_hook("rest_message_fields_hook", fields=fields)
+        request = self.context['request']
+        dispatch_module_hook("rest_message_fields_hook", request=request,
+                             fields=fields)
         return fields
 
 class StaticTextRenderer(renderers.BaseRenderer):
diff --git a/mods/diff.py b/mods/diff.py
index eb8dfb8..38404e0 100644
--- a/mods/diff.py
+++ b/mods/diff.py
@@ -60,7 +60,7 @@ class DiffModule(PatchewModule):
                  for o in sorted(other_versions, key=lambda y: y.version)
                  if o.message_id != message.message_id]
 
-    def rest_series_fields_hook(self, fields, detailed):
+    def rest_series_fields_hook(self, request, fields, detailed):
         fields['version'] = rest_framework.fields.IntegerField()
         if detailed:
             fields['other_versions'] = PluginMethodField(obj=self)
diff --git a/mods/git.py b/mods/git.py
index b0df7e8..2489f5a 100644
--- a/mods/git.py
+++ b/mods/git.py
@@ -113,7 +113,7 @@ class GitModule(PatchewModule):
             raise Exception("Project git repo invalid: %s" % project_git)
         return upstream, branch
 
-    def rest_results_hook(self, message, results):
+    def rest_results_hook(self, request, message, results):
         l = message.get_property("git.apply-log")
         if l:
             if message.get_property("git.apply-failed"):
diff --git a/mods/tags.py b/mods/tags.py
index 5a776ed..5ec5bc2 100644
--- a/mods/tags.py
+++ b/mods/tags.py
@@ -123,7 +123,7 @@ series cover letter, patch mail body and their replies.
     def get_tags(self, m, request, format):
         return m.get_property("tags", [])
 
-    def rest_message_fields_hook(self, fields):
+    def rest_message_fields_hook(self, request, fields):
         fields['tags'] = PluginMethodField(obj=self)
 
     def prepare_message_hook(self, request, message, detailed):
diff --git a/mods/testing.py b/mods/testing.py
index 47933e2..b822a34 100644
--- a/mods/testing.py
+++ b/mods/testing.py
@@ -257,7 +257,7 @@ class TestingModule(PatchewModule):
         return reverse("testing-get-prop",
                        kwargs={"project_or_series": obj.message_id})
 
-    def rest_results_hook(self, message, results):
+    def rest_results_hook(self, request, message, results):
         for pn, p in message.get_properties().items():
             if not pn.startswith("testing.report."):
                 continue
-- 
2.14.3


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