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()
|
queryset = Document.objects.all()
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
detail=False, lookup_url_kwarg='document_id', methods=('post',),
|
detail=True, lookup_url_kwarg='document_id', methods=('post',),
|
||||||
serializer_class=DocumentTagAttachRemoveSerializer,
|
serializer_class=DocumentTagAttachRemoveSerializer,
|
||||||
url_name='tag-attach', url_path='tags/attach'
|
url_name='tag-attach', url_path='tags/attach'
|
||||||
)
|
)
|
||||||
@@ -119,7 +119,7 @@ class DocumentTagAPIViewSet(MayanAPIGenericViewSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@action(
|
@action(
|
||||||
detail=False, lookup_url_kwarg='document_id',
|
detail=True, lookup_url_kwarg='document_id',
|
||||||
serializer_class=TagSerializer, url_name='tag-list',
|
serializer_class=TagSerializer, url_name='tag-list',
|
||||||
url_path='tags'
|
url_path='tags'
|
||||||
)
|
)
|
||||||
@@ -139,7 +139,7 @@ class DocumentTagAPIViewSet(MayanAPIGenericViewSet):
|
|||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
@action(
|
@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,
|
methods=('post',), serializer_class=DocumentTagAttachRemoveSerializer,
|
||||||
url_name='tag-remove', url_path='tags/remove'
|
url_name='tag-remove', url_path='tags/remove'
|
||||||
)
|
)
|
||||||
|
|||||||
+27
-27
@@ -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_attach', value=method_document_tags_attach)
|
||||||
Document.add_to_class(name='tags_remove', value=method_document_tags_remove)
|
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(
|
ModelEventType.register(
|
||||||
model=Tag, event_types=(
|
model=Tag, event_types=(
|
||||||
event_tag_attach, event_tag_created, event_tag_edited,
|
event_tag_attach, event_tag_created, event_tag_edited,
|
||||||
@@ -201,30 +228,3 @@ class TagsApp(MayanAppConfig):
|
|||||||
dispatch_uid='tags_handler_tag_pre_delete',
|
dispatch_uid='tags_handler_tag_pre_delete',
|
||||||
receiver=handler_tag_pre_delete, sender=Tag
|
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 = (
|
api_router_entries = (
|
||||||
{'prefix': r'tags', 'viewset': TagAPIViewSet, 'basename': 'tag'},
|
{'prefix': r'tags', 'viewset': TagAPIViewSet, 'basename': 'tag'},
|
||||||
{
|
{
|
||||||
'prefix': r'documents/(?P<document_id>\d+)',
|
'prefix': r'documents', 'viewset': DocumentTagAPIViewSet,
|
||||||
'viewset': DocumentTagAPIViewSet, 'basename': 'document'
|
'basename': 'document'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# {
|
|
||||||
# 'prefix': r'permission_namespaces/(?P<permission_namespace_name>[^/.]+)/permissions',
|
|
||||||
# 'viewset': PermissionViewSet, 'basename': 'permission'
|
|
||||||
# },
|
|
||||||
|
|||||||
Reference in New Issue
Block a user