Code Duplication    Length = 30-30 lines in 2 locations

frontend/ore/api/frontend.py 2 locations

@@ 519-548 (lines=30) @@
516
            bundle.obj.set_attrs(bundle.data['properties'])
517
        return self.save(bundle)
518
519
    def patch_detail(self, request, **kwargs):
520
        """
521
            Updates a resource in-place. We could also override obj_update, which is
522
            the Tastypie intended-way of having a custom PATCH implementation, but this
523
            method gets a full updated object bundle that is expected to be directly written
524
            to the object. In this method, we still have access to what actually really
525
            comes as part of the update payload.
526
527
            If the resource is updated, return ``HttpAccepted`` (202 Accepted).
528
            If the resource did not exist, return ``HttpNotFound`` (404 Not Found).
529
        """
530
        try:
531
            # Fetch relevant node object as Tastypie does it
532
            basic_bundle = self.build_bundle(request=request)
533
            obj = self.cached_obj_get(
534
                bundle=basic_bundle,
535
                **self.remove_api_resource_names(kwargs))
536
        except ObjectDoesNotExist:
537
            return HttpNotFound()
538
        except MultipleObjectsReturned:
539
            return HttpMultipleChoices(
540
                "More than one resource is found at this URI.")
541
542
        # Deserialize incoming update payload JSON from request
543
        deserialized = self.deserialize(request, request.body,
544
                                        format=request.META.get('CONTENT_TYPE', 'application/json'))
545
        if 'properties' in deserialized:
546
            obj.set_attrs(deserialized['properties'])
547
        # return the updated edge object
548
        return HttpResponse(obj.to_json(), 'application/json', status=202)
549
550
551
class ProjectResource(common.ProjectResource):
@@ 278-307 (lines=30) @@
275
            bundle.obj.set_attrs(bundle.data['properties'])
276
        return self.save(bundle)
277
278
    def patch_detail(self, request, **kwargs):
279
        """
280
            Updates a resource in-place. We could also override obj_update, which is
281
            the Tastypie intended-way of having a custom PATCH implementation, but this
282
            method gets a full updated object bundle that is expected to be directly written
283
            to the object. In this method, we still have access to what actually really
284
            comes as part of the update payload.
285
286
            If the resource is updated, return ``HttpAccepted`` (202 Accepted).
287
            If the resource did not exist, return ``HttpNotFound`` (404 Not Found).
288
        """
289
        try:
290
            # Fetch relevant node object as Tastypie does it
291
            basic_bundle = self.build_bundle(request=request)
292
            obj = self.cached_obj_get(
293
                bundle=basic_bundle,
294
                **self.remove_api_resource_names(kwargs))
295
        except ObjectDoesNotExist:
296
            return HttpNotFound()
297
        except MultipleObjectsReturned:
298
            return HttpMultipleChoices(
299
                "More than one resource is found at this URI.")
300
301
        # Deserialize incoming update payload JSON from request
302
        deserialized = self.deserialize(request, request.body,
303
                                        format=request.META.get('CONTENT_TYPE', 'application/json'))
304
        if 'properties' in deserialized:
305
            obj.set_attrs(deserialized['properties'])
306
            # return the updated node object
307
        return HttpResponse(obj.to_json(), 'application/json', status=202)
308
309
310
class NodeGroupSerializer(Serializer):