Remove the APIRoot view. Remove the Endpoint class. Remove the EndpointSerializer. Move API documentation generation from the root urls module to the app's urls module. Update the app API URL generation to be based on viewsets instead of an custom api_urls list. Remove MayanObjectPermissionsFilter and replace it with MayanViewSetObjectPermissionsFilter which allows mapping a required permission to a specific viewset action. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from rest_framework.relations import HyperlinkedIdentityField
|
|
|
|
from mayan.apps.common.utils import resolve_attribute
|
|
|
|
|
|
class MultiKwargHyperlinkedIdentityField(HyperlinkedIdentityField):
|
|
def __init__(self, *args, **kwargs):
|
|
self.view_kwargs = kwargs.pop('view_kwargs', [])
|
|
super(MultiKwargHyperlinkedIdentityField, self).__init__(*args, **kwargs)
|
|
|
|
def get_url(self, obj, view_name, request, format):
|
|
"""
|
|
Extends HyperlinkedRelatedField to allow passing more than one view
|
|
keyword argument.
|
|
----
|
|
Given an object, return the URL that hyperlinks to the object.
|
|
|
|
May raise a `NoReverseMatch` if the `view_name` and `lookup_field`
|
|
attributes are not configured to correctly match the URL conf.
|
|
"""
|
|
# Unsaved objects will not yet have a valid URL.
|
|
if hasattr(obj, 'pk') and obj.pk in (None, ''):
|
|
return None
|
|
|
|
kwargs = {}
|
|
for entry in self.view_kwargs:
|
|
kwargs[entry['lookup_url_kwarg']] = resolve_attribute(
|
|
obj=obj, attribute=entry['lookup_field']
|
|
)
|
|
|
|
return self.reverse(
|
|
viewname=view_name, kwargs=kwargs, request=request, format=format
|
|
)
|