Rename methods to retrieve a document's folders and tag membership to avoid search related field problems.

This commit is contained in:
Roberto Rosario
2015-08-25 16:29:23 -04:00
parent 7392e80fc2
commit 7a0fe33ffe
9 changed files with 16 additions and 15 deletions

View File

@@ -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

View File

@@ -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=(

View File

@@ -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):

View File

@@ -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 {

View File

@@ -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):
"""

View File

@@ -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=(

View File

@@ -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:

View File

@@ -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"'

View File

@@ -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))