[PATCH v5 07/10] REST: Add Patch Checks to the API
stephen.finucane at intel.com
Fri Jun 3 00:22:40 AEST 2016
On 26 May 20:12, Andy Doan wrote:
> This exports patch checks via the REST API.
> The drf-nested-routers package is used to handle the fact Checks are
> nested under a Patch.
> Security Constraints:
> * Anyone (logged in or not) can read all objects.
> * No one can update/delete objects.
> * Project maintainers and patch owners may create objects.
> Signed-off-by: Andy Doan <andy.doan at linaro.org>
Turns out there was more than one request :/ Let's see if they all make
> class UserSerializer(HyperlinkedModelSerializer):
> @@ -74,9 +77,43 @@ class PatchSerializer(HyperlinkedModelSerializer):
> def to_representation(self, instance):
> data = super(PatchSerializer, self).to_representation(instance)
> + data['checks'] = data['url'] + 'checks/'
Thinking this should be 'checks_url', to help distinguish URLs across
> +class ChecksSerializer(ModelSerializer):
> + class Meta:
> + model = Check
> + user = HyperlinkedRelatedField(
> + 'user-detail', read_only=True, default=CurrentUserDefault())
> + patch = HiddenField(default=CurrentPatchDefault())
> + def run_validation(self, data):
> + for val, label in Check.STATE_CHOICES:
> + if label == data['state']:
> + data['state'] = val
> + break
> + return super(ChecksSerializer, self).run_validation(data)
Here's one I missed earlier: I don't think we should set 'date'
manually. Instead, it should be a read-only field that's automatically
set when we create a new status, using the latest time. I don't know if
the XML-RPC API works like this, but it should.
More information about the Patchwork