[RFC 10/11] REST: Allow projects to be retrieved by linkname

Andy Doan andy.doan at linaro.org
Wed May 11 08:30:28 AEST 2016


On 05/09/2016 09:09 AM, Finucane, Stephen wrote:
>> diff --git a/patchwork/views/rest_api.py b/patchwork/views/rest_api.py
>> >index ae86627..e2ec616 100644
>> >--- a/patchwork/views/rest_api.py
>> >+++ b/patchwork/views/rest_api.py
>> >@@ -127,6 +127,22 @@ class ProjectViewSet(PatchworkViewSet):
>> >      permission_classes = (PatchworkPermission,)
>> >      serializer_class = create_model_serializer(Project)
>> >
>> >+    def retrieve(self, request, pk=None):
>> >+        try:
>> >+            int(pk)
>> >+        except ValueError:
>> >+            self.kwargs = {'linkname': pk}  # try and lookup by linkname
>> >+            self.lookup_field = 'linkname'
>> >+        return super(ProjectViewSet, self).retrieve(request, pk)
>> >+
>> >+    def partial_update(self, request, pk=None):
>> >+        try:
>> >+            int(pk)
>> >+        except ValueError:
>> >+            self.kwargs = {'linkname': pk}  # try and lookup by linkname
>> >+            self.lookup_field = 'linkname'
>> >+        return super(ProjectViewSet, self).partial_update(request, pk)
> I'm not sure of the lifecycle of this object, but do we need to worry
> about changing 'lookup_field' to 'id' an unsetting kwards in the
> non-exception path? Will we ever reenter this function from a different
> point?

The object's lifecycle is just per the HTTP request, so its safe.



More information about the Patchwork mailing list