]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
REST: Expose '/event' fields in 'payload' field
authorStephen Finucane <stephen@that.guru>
Tue, 7 Feb 2017 13:13:34 +0000 (13:13 +0000)
committerStephen Finucane <stephen@that.guru>
Wed, 1 Mar 2017 22:17:24 +0000 (22:17 +0000)
Instead of exposing differing fields depending on the event category,
expose a consistent set of 'id', 'category', 'date' and 'payload'. This
ensures we can loop through events in a somewhat standardized fashion.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Tested-by: Daniel Axtens <dja@axtens.net>
patchwork/api/event.py

index 0087ef7bab92154a9353032c50e4a067030dafff..32b3bde3cab4d0e18b9cde0fed70dcd0112a6476 100644 (file)
@@ -17,6 +17,8 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from collections import OrderedDict
+
 from django.core.urlresolvers import reverse
 from rest_framework.generics import ListAPIView
 from rest_framework.serializers import HyperlinkedModelSerializer
@@ -57,11 +59,18 @@ class EventSerializer(HyperlinkedModelSerializer):
 
     def to_representation(self, instance):
         data = super(EventSerializer, self).to_representation(instance)
-
+        payload = OrderedDict()
         kept_fields = self._category_map[instance.category] + [
             'id', 'category', 'project', 'date']
-        for field in [x for x in data if x not in kept_fields]:
-            del data[field]
+
+        for field in [x for x in data]:
+            if field not in kept_fields:
+                del data[field]
+            elif field in self._category_map[instance.category]:
+                field_name = 'check' if field == 'created_check' else field
+                payload[field_name] = data.pop(field)
+
+        data['payload'] = payload
 
         return data