Improve Document Tag API URL
Update the API routers registration to not duplicate the document's URL parameter definition. Signed-off-by: Roberto Rosario <Roberto.Rosario.Gonzalez@mayan-edms.com>
This commit is contained in:
@@ -104,7 +104,7 @@ class DocumentTagAPIViewSet(MayanAPIGenericViewSet):
|
||||
queryset = Document.objects.all()
|
||||
|
||||
@action(
|
||||
detail=False, lookup_url_kwarg='document_id', methods=('post',),
|
||||
detail=True, lookup_url_kwarg='document_id', methods=('post',),
|
||||
serializer_class=DocumentTagAttachRemoveSerializer,
|
||||
url_name='tag-attach', url_path='tags/attach'
|
||||
)
|
||||
@@ -119,7 +119,7 @@ class DocumentTagAPIViewSet(MayanAPIGenericViewSet):
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=False, lookup_url_kwarg='document_id',
|
||||
detail=True, lookup_url_kwarg='document_id',
|
||||
serializer_class=TagSerializer, url_name='tag-list',
|
||||
url_path='tags'
|
||||
)
|
||||
@@ -139,7 +139,7 @@ class DocumentTagAPIViewSet(MayanAPIGenericViewSet):
|
||||
return Response(serializer.data)
|
||||
|
||||
@action(
|
||||
detail=False, lookup_field='pk', lookup_url_kwarg='document_id',
|
||||
detail=True, lookup_field='pk', lookup_url_kwarg='document_id',
|
||||
methods=('post',), serializer_class=DocumentTagAttachRemoveSerializer,
|
||||
url_name='tag-remove', url_path='tags/remove'
|
||||
)
|
||||
|
||||
@@ -75,6 +75,33 @@ class TagsApp(MayanAppConfig):
|
||||
Document.add_to_class(name='tags_attach', value=method_document_tags_attach)
|
||||
Document.add_to_class(name='tags_remove', value=method_document_tags_remove)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_attach_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-attach'
|
||||
)
|
||||
)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_list_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-list'
|
||||
)
|
||||
)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_remove_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-remove'
|
||||
)
|
||||
)
|
||||
|
||||
ModelEventType.register(
|
||||
model=Tag, event_types=(
|
||||
event_tag_attach, event_tag_created, event_tag_edited,
|
||||
@@ -201,30 +228,3 @@ class TagsApp(MayanAppConfig):
|
||||
dispatch_uid='tags_handler_tag_pre_delete',
|
||||
receiver=handler_tag_pre_delete, sender=Tag
|
||||
)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_attach_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-attach'
|
||||
)
|
||||
)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_list_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-list'
|
||||
)
|
||||
)
|
||||
|
||||
LazyExtraFieldsSerializerMixin.add_field(
|
||||
dotted_path='mayan.apps.documents.serializers.DocumentSerializer',
|
||||
field_name='tag_remove_url',
|
||||
field=HyperlinkField(
|
||||
lookup_url_kwarg='document_id',
|
||||
view_name='rest_api:document-tag-remove'
|
||||
)
|
||||
)
|
||||
|
||||
@@ -60,13 +60,7 @@ urlpatterns = [
|
||||
api_router_entries = (
|
||||
{'prefix': r'tags', 'viewset': TagAPIViewSet, 'basename': 'tag'},
|
||||
{
|
||||
'prefix': r'documents/(?P<document_id>\d+)',
|
||||
'viewset': DocumentTagAPIViewSet, 'basename': 'document'
|
||||
'prefix': r'documents', 'viewset': DocumentTagAPIViewSet,
|
||||
'basename': 'document'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
# {
|
||||
# 'prefix': r'permission_namespaces/(?P<permission_namespace_name>[^/.]+)/permissions',
|
||||
# 'viewset': PermissionViewSet, 'basename': 'permission'
|
||||
# },
|
||||
|
||||
Reference in New Issue
Block a user