From cd304e424cd805a28803e2662cd3a79acd5a3f17 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 7 Feb 2017 13:13:34 +0000 Subject: [PATCH] REST: Expose '/event' fields in 'payload' field 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 Tested-by: Daniel Axtens --- patchwork/api/event.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/patchwork/api/event.py b/patchwork/api/event.py index 0087ef7b..32b3bde3 100644 --- a/patchwork/api/event.py +++ b/patchwork/api/event.py @@ -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 -- 2.47.3