[PATCH v3 05/16] REST: Explicitly define fields

Stephen Finucane stephen at that.guru
Sat Nov 26 05:18:24 AEDT 2016


Explicitly define included fields (using 'Meta.fields') rather than
those that should be excluded (using 'Meta.exclude'). This ensure fields
that are exposed by the API don't change unless we explicitly change
them

The only side-effect of this change should be a consistent ordering of
the output - the ordering used in the 'Meta.fields' will be consistently
used, thus ordering is now important and some fields are moved around
to reflect this.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/api/check.py   | 2 +-
 patchwork/api/patch.py   | 7 ++++---
 patchwork/api/person.py  | 2 +-
 patchwork/api/project.py | 3 ++-
 patchwork/api/user.py    | 4 +---
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/patchwork/api/check.py b/patchwork/api/check.py
index 26a2595..2fd681a 100644
--- a/patchwork/api/check.py
+++ b/patchwork/api/check.py
@@ -63,7 +63,7 @@ class CheckSerializer(ModelSerializer):
     class Meta:
         model = Check
         fields = ('patch', 'user', 'date', 'state', 'target_url',
-                  'description', 'context',)
+                  'context', 'description')
         read_only_fields = ('date',)
 
 
diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py
index 3f464b2..3af5994 100644
--- a/patchwork/api/patch.py
+++ b/patchwork/api/patch.py
@@ -72,11 +72,12 @@ class PatchSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = Patch
         list_serializer_class = PatchListSerializer
+        fields = ('url', 'project', 'msgid', 'date', 'name', 'commit_ref',
+                  'pull_url', 'state', 'archived', 'hash', 'submitter',
+                  'delegate', 'mbox', 'check', 'checks', 'tags', 'headers',
+                  'content', 'diff')
         read_only_fields = ('project', 'name', 'date', 'submitter', 'diff',
                             'content', 'hash', 'msgid')
-        # there's no need to expose an entire "tags" endpoint, so we custom
-        # render this field
-        exclude = ('tags',)
 
 
 class PatchViewSet(PatchworkViewSet):
diff --git a/patchwork/api/person.py b/patchwork/api/person.py
index 758b21d..fe1e3b7 100644
--- a/patchwork/api/person.py
+++ b/patchwork/api/person.py
@@ -27,7 +27,7 @@ from patchwork.models import Person
 class PersonSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = Person
-        fields = ('email', 'name', 'user')
+        fields = ('url', 'name', 'email', 'user')
 
 
 class PeopleViewSet(PatchworkViewSet):
diff --git a/patchwork/api/project.py b/patchwork/api/project.py
index b4debb6..2f63694 100644
--- a/patchwork/api/project.py
+++ b/patchwork/api/project.py
@@ -34,7 +34,8 @@ class ProjectSerializer(HyperlinkedModelSerializer):
 
     class Meta:
         model = Project
-        exclude = ('send_notifications', 'use_tags')
+        fields = ('url', 'name', 'linkname', 'listid', 'listemail', 'web_url',
+                  'scm_url', 'webscm_url')
 
 
 class ProjectViewSet(PatchworkViewSet):
diff --git a/patchwork/api/user.py b/patchwork/api/user.py
index b25054f..3a4ae1a 100644
--- a/patchwork/api/user.py
+++ b/patchwork/api/user.py
@@ -27,9 +27,7 @@ from patchwork.api.base import PatchworkViewSet
 class UserSerializer(HyperlinkedModelSerializer):
     class Meta:
         model = User
-        exclude = ('date_joined', 'groups', 'is_active', 'is_staff',
-                   'is_superuser', 'last_login', 'password',
-                   'user_permissions')
+        fields = ('url', 'username', 'first_name', 'last_name', 'email')
 
 
 class UserViewSet(PatchworkViewSet):
-- 
2.7.4



More information about the Patchwork mailing list