From 7a0fe33ffed2bea300328787223ad9e40df9fd93 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 25 Aug 2015 16:29:23 -0400 Subject: [PATCH] Rename methods to retrieve a document's folders and tag membership to avoid search related field problems. --- mayan/apps/folders/api_views.py | 2 +- mayan/apps/folders/apps.py | 5 ++++- mayan/apps/folders/models.py | 2 +- mayan/apps/folders/views.py | 2 +- mayan/apps/tags/api_views.py | 4 ++-- mayan/apps/tags/apps.py | 2 +- mayan/apps/tags/models.py | 2 +- mayan/apps/tags/views.py | 6 +++--- mayan/apps/tags/widgets.py | 6 ++---- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/mayan/apps/folders/api_views.py b/mayan/apps/folders/api_views.py index 52195bebe7..730194b621 100644 --- a/mayan/apps/folders/api_views.py +++ b/mayan/apps/folders/api_views.py @@ -46,7 +46,7 @@ class APIDocumentFolderListView(generics.ListAPIView): permission_document_view, self.request.user, document ) - queryset = document.folders().all() + queryset = document.document_folders().all() return queryset diff --git a/mayan/apps/folders/apps.py b/mayan/apps/folders/apps.py index b27a581a71..b27a6e5cd3 100644 --- a/mayan/apps/folders/apps.py +++ b/mayan/apps/folders/apps.py @@ -37,7 +37,10 @@ class FoldersApp(MayanAppConfig): APIEndPoint(app=self, version_string='1') - Document.add_to_class('folders', lambda document: DocumentFolder.objects.filter(documents=document)) + Document.add_to_class( + 'document_folders', + lambda document: DocumentFolder.objects.filter(documents=document) + ) ModelPermission.register( model=Document, permissions=( diff --git a/mayan/apps/folders/models.py b/mayan/apps/folders/models.py index 8f22c5afdb..cbad0d8c08 100644 --- a/mayan/apps/folders/models.py +++ b/mayan/apps/folders/models.py @@ -23,7 +23,7 @@ class Folder(models.Model): auto_now_add=True, verbose_name=_('Datetime created') ) documents = models.ManyToManyField( - Document, verbose_name=_('Documents') + Document, related_name='folders', verbose_name=_('Documents') ) def __str__(self): diff --git a/mayan/apps/folders/views.py b/mayan/apps/folders/views.py index 68baea3885..0caa4eaaed 100644 --- a/mayan/apps/folders/views.py +++ b/mayan/apps/folders/views.py @@ -228,7 +228,7 @@ class DocumentFolderListView(FolderListView): return super(DocumentFolderListView, self).dispatch(request, *args, **kwargs) def get_folder_queryset(self): - return self.document.folders().all() + return self.document.document_folders().all() def get_extra_context(self): return { diff --git a/mayan/apps/tags/api_views.py b/mayan/apps/tags/api_views.py index 19dad396b0..7ce9aa5352 100644 --- a/mayan/apps/tags/api_views.py +++ b/mayan/apps/tags/api_views.py @@ -133,7 +133,7 @@ class APIDocumentTagListView(generics.ListCreateAPIView): permission_document_view, self.request.user, document ) - return document.tags().all() + return document.attached_tags().all() def get_serializer_context(self): """ @@ -199,7 +199,7 @@ class APIDocumentTagView(generics.RetrieveDestroyAPIView): return document def get_queryset(self): - return self.get_document().tags().all() + return self.get_document().attached_tags().all() def get_serializer_context(self): """ diff --git a/mayan/apps/tags/apps.py b/mayan/apps/tags/apps.py index 118c21e1f9..362f3c3616 100644 --- a/mayan/apps/tags/apps.py +++ b/mayan/apps/tags/apps.py @@ -37,7 +37,7 @@ class TagsApp(MayanAppConfig): APIEndPoint(app=self, version_string='1') - Document.add_to_class('tags', lambda document: DocumentTag.objects.filter(documents=document)) + Document.add_to_class('attached_tags', lambda document: DocumentTag.objects.filter(documents=document)) ModelPermission.register( model=Document, permissions=( diff --git a/mayan/apps/tags/models.py b/mayan/apps/tags/models.py index 8920030230..1a872db9af 100644 --- a/mayan/apps/tags/models.py +++ b/mayan/apps/tags/models.py @@ -20,7 +20,7 @@ class Tag(models.Model): ) color = RGBColorField(verbose_name=_('Color')) documents = models.ManyToManyField( - Document, verbose_name=_('Documents') + Document, related_name='tags', verbose_name=_('Documents') ) class Meta: diff --git a/mayan/apps/tags/views.py b/mayan/apps/tags/views.py index c5c5dddae7..a58bce3b67 100644 --- a/mayan/apps/tags/views.py +++ b/mayan/apps/tags/views.py @@ -74,7 +74,7 @@ def tag_attach(request, document_id=None, document_id_list=None): if form.is_valid(): tag = form.cleaned_data['tag'] for document in documents: - if tag in document.tags().all(): + if tag in document.attached_tags().all(): messages.warning( request, _( 'Document "%(document)s" is already tagged as "%(tag)s"' @@ -263,7 +263,7 @@ class DocumentTagListView(TagListView): } def get_tag_queryset(self): - return self.document.tags().all() + return self.document.attached_tags().all() def tag_remove(request, document_id=None, document_id_list=None, tag_id=None, tag_id_list=None): @@ -369,7 +369,7 @@ def tag_remove(request, document_id=None, document_id_list=None, tag_id=None, ta if request.method == 'POST': for document in documents: for tag in tags: - if tag not in document.tags().all(): + if tag not in document.attached_tags().all(): messages.warning( request, _( 'Document "%(document)s" wasn\'t tagged as "%(tag)s"' diff --git a/mayan/apps/tags/widgets.py b/mayan/apps/tags/widgets.py index 8e51e4ec07..1a26e34914 100644 --- a/mayan/apps/tags/widgets.py +++ b/mayan/apps/tags/widgets.py @@ -10,10 +10,8 @@ def widget_inline_tags(document): """ tags_template = [] - tag_count = document.tags().count() - if tag_count: - for tag in document.tags().all(): - tags_template.append(widget_single_tag(tag)) + for tag in document.attached_tags().all(): + tags_template.append(widget_single_tag(tag)) return mark_safe(''.join(tags_template))