[PATCH 01/13] REST: Create 'api' directory

Stephen Fincane stephen at that.guru
Fri Nov 25 06:44:30 AEDT 2016


On Mon, 2016-11-21 at 11:22 +1100, Daniel Axtens wrote:
> Stephen Finucane <stephen at that.guru> writes:
> 
> > 
> > Move all REST API-related code into an 'api' directory. This allows
> > us
> > to break the existing files into endpoint-based files and will
> > allow us
> > to split the API into a different Django app in the future.
> > 
> > Signed-off-by: Stephen Finucane <stephen at that.guru>
> > Cc: Andy Doan <andy.doan at linaro.org>
> > ---
> >  patchwork/api/__init__.py     |  92 ++++++++++++++++++++++
> >  patchwork/api/check.py        |  96 +++++++++++++++++++++++
> >  patchwork/api/patch.py        |  84 ++++++++++++++++++++
> >  patchwork/api/person.py       |  37 +++++++++
> >  patchwork/api/project.py      |  60 +++++++++++++++
> >  patchwork/api/user.py         |  37 +++++++++
> >  patchwork/rest_serializers.py | 144 ------------------------------
> > ----
> >  patchwork/urls.py             |  20 ++++-
> >  patchwork/views/rest_api.py   | 175 ------------------------------
> > ------------
> 
> I assume you've just moved things - any changes to the code? If there
> are no changes I will avoid reviewing existing code!

Exactly. Updated the commit message to clarify this.

> > 
> >  9 files changed, 425 insertions(+), 320 deletions(-)
> >  create mode 100644 patchwork/api/__init__.py
> >  create mode 100644 patchwork/api/check.py
> >  create mode 100644 patchwork/api/patch.py
> >  create mode 100644 patchwork/api/person.py
> >  create mode 100644 patchwork/api/project.py
> >  create mode 100644 patchwork/api/user.py
> >  delete mode 100644 patchwork/rest_serializers.py
> >  delete mode 100644 patchwork/views/rest_api.py
> > 
> > diff --git a/patchwork/api/__init__.py b/patchwork/api/__init__.py
> > new file mode 100644
> > index 0000000..dc88a85
> > --- /dev/null
> > +++ b/patchwork/api/__init__.py
> > @@ -0,0 +1,92 @@
> > +# Patchwork - automated patch tracking system
> > +# Copyright (C) 2016 Linaro Corporation
> > +#
> > +# This file is part of the Patchwork package.
> > +#
> > +# Patchwork is free software; you can redistribute it and/or
> > modify
> > +# it under the terms of the GNU General Public License as
> > published by
> > +# the Free Software Foundation; either version 2 of the License,
> > or
> > +# (at your option) any later version.
> > +#
> > +# Patchwork is distributed in the hope that it will be useful,
> > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +# GNU General Public License for more details.
> > +#
> > +# You should have received a copy of the GNU General Public
> > License
> > +# along with Patchwork; if not, write to the Free Software
> > +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-
> > 1307  USA
> > +
> > +from django.conf import settings
> > +
> > +from rest_framework import permissions
> > +from rest_framework.pagination import PageNumberPagination
> > +from rest_framework.response import Response
> > +from rest_framework.serializers import HyperlinkedModelSerializer
> > +from rest_framework.serializers import HyperlinkedRelatedField
> > +from rest_framework.viewsets import ModelViewSet
> > +
> > +
> > +class URLSerializer(HyperlinkedModelSerializer):
> > +    """Just like parent but puts _url for fields"""
> > +
> > +    def to_representation(self, instance):
> > +        data = super(URLSerializer,
> > self).to_representation(instance)
> > +        for name, field in self.fields.items():
> > +            if isinstance(field, HyperlinkedRelatedField) and name
> > != 'url':
> > +                data[name + '_url'] = data.pop(name)
> > +        return data
> > +
> 
> I'm very much not a fan of putting anything other than import
> statements
> in __init__.py. I feel it violates the principle of least
> surprise. However, I'm very open to being persuaded that it's a Good
> Thing for some reason.

I've no strong feeling either way, so I've moved to 'base.py' in v3.

Stephen


More information about the Patchwork mailing list