From: Stephen Finucane Date: Wed, 23 Nov 2016 19:41:12 +0000 (+0000) Subject: REST: Explicitly define fields X-Git-Tag: v2.0.0-rc1~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=207bc10f74034509f0c17fad1dfc8713e73a5a3e;p=thirdparty%2Fpatchwork.git REST: Explicitly define fields 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 Reviewed-by: Andy Doan --- diff --git a/patchwork/api/check.py b/patchwork/api/check.py index 26a25958..2fd681a1 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 3f464b26..3af5994f 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 758b21d4..fe1e3b76 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 b4debb61..2f636948 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 b25054fe..3a4ae1a6 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):