Beispiel #1
0
    def get_related_links(self, obj=None, request=None, *args, **kwargs):
        links = {}

        if request and request.user.is_authenticated():
            user_resource = get_resource_for_object(request.user)
            href = user_resource.get_href(request.user, request, *args,
                                          **kwargs)

            # Since there's no object, DELETE won't be populated automatically.
            clean_href = request.build_absolute_uri()
            i = clean_href.find('?')

            if i != -1:
                clean_href = clean_href[:i]

            links['delete'] = {
                'method': 'DELETE',
                'href': clean_href,
            }

            links['user'] = {
                'method': 'GET',
                'href': href,
                'title': six.text_type(request.user),
                'resource': user_resource,
                'list-resource': False,
            }

        return links
Beispiel #2
0
    def get_related_links(self, obj=None, request=None, *args, **kwargs):
        links = {}

        if request and request.user.is_authenticated():
            user_resource = get_resource_for_object(request.user)
            href = user_resource.get_href(request.user, request,
                                          *args, **kwargs)

            # Since there's no object, DELETE won't be populated automatically.
            clean_href = request.build_absolute_uri()
            i = clean_href.find('?')

            if i != -1:
                clean_href = clean_href[:i]

            links['delete'] = {
                'method': 'DELETE',
                'href': clean_href,
            }

            links['user'] = {
                'method': 'GET',
                'href': href,
                'title': six.text_type(request.user),
                'resource': user_resource,
                'list-resource': False,
            }

        return links
Beispiel #3
0
    def test_get_resource_for_object_only_fields(self):
        """Testing get_resource_for_model when model is deferred"""
        class TestResource(WebAPIResource):
            pass

        resource = TestResource()

        with register_resource_for_model_temp(Site, resource):
            config = Site.objects.only('domain').get()

            self.assertEqual(get_resource_for_object(config), resource)
Beispiel #4
0
    def get_serializer_for_object(self, obj):
        """Returns the serializer used to serialize an object.

        This is called when serializing objects for payloads returned
        by this resource instance. It must return the resource instance
        that will be responsible for serializing the given object for the
        payload.

        By default, this calls ``get_resource_for_object`` to find the
        appropriate resource.
        """
        return get_resource_for_object(obj)
Beispiel #5
0
    def get_serializer_for_object(self, obj):
        """Returns the serializer used to serialize an object.

        This is called when serializing objects for payloads returned
        by this resource instance. It must return the resource instance
        that will be responsible for serializing the given object for the
        payload.

        By default, this calls ``get_resource_for_object`` to find the
        appropriate resource.
        """
        return get_resource_for_object(obj)
Beispiel #6
0
    def test_get_resource_for_object_only_fields(self):
        """Testing get_resource_for_model when model is deferred"""
        class TestResource(WebAPIResource):
            pass

        resource = TestResource()

        with register_resource_for_model_temp(Site, resource):
            config = Site.objects.only('domain').get()

            self.assertEqual(get_resource_for_object(config),
                             resource)
Beispiel #7
0
    def test_get_resource_for_object_only_fields(self):
        """Testing get_resource_for_model when model is deferred"""
        class TestResource(WebAPIResource):
            pass

        resource = TestResource()
        register_resource_for_model(SiteConfiguration, resource)

        site = Site.objects.create(domain='example.com', name='example.com')
        SiteConfiguration.objects.create(site=site)

        with register_resource_for_model_temp(SiteConfiguration, resource):
            config = SiteConfiguration.objects.only('site').get()

            self.assertEqual(get_resource_for_object(config), resource)
Beispiel #8
0
    def test_get_resource_for_object_only_fields(self):
        """Testing get_resource_for_model when model is deferred"""
        class TestResource(WebAPIResource):
            pass

        resource = TestResource()
        register_resource_for_model(SiteConfiguration, resource)

        site = Site.objects.create(domain='example.com', name='example.com')
        SiteConfiguration.objects.create(site=site)

        with register_resource_for_model_temp(SiteConfiguration, resource):
            config = SiteConfiguration.objects.only('site').get()

            self.assertEqual(get_resource_for_object(config),
                             resource)