From 6a65544fb78b35af558338051c50ea9298c08ab3 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 16 Apr 2018 15:20:16 -0400 Subject: [PATCH] Remove some label argument from the apps module and move them to the model. Signed-off-by: Roberto Rosario --- mayan/apps/documents/apps.py | 19 +++++++------------ mayan/apps/documents/models.py | 6 ++++-- mayan/apps/tags/admin.py | 2 +- mayan/apps/tags/apps.py | 14 +++++++++----- mayan/apps/tags/models.py | 5 +++++ mayan/apps/tags/views.py | 15 ++++++++++----- 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/mayan/apps/documents/apps.py b/mayan/apps/documents/apps.py index 82417d5fbd..de9bfce44e 100644 --- a/mayan/apps/documents/apps.py +++ b/mayan/apps/documents/apps.py @@ -212,7 +212,7 @@ class DocumentsApp(MayanAppConfig): ) ) SourceColumn( - source=Document, label=_('Type'), attribute='document_type' + source=Document, attribute='document_type' ) SourceColumn( source=Document, label=_('Pages'), @@ -263,11 +263,10 @@ class DocumentsApp(MayanAppConfig): ) SourceColumn( - source=DeletedDocument, label=_('Type'), attribute='document_type' + source=DeletedDocument, attribute='document_type' ) SourceColumn( - source=DeletedDocument, label=_('Date time trashed'), - attribute='deleted_date_time' + source=DeletedDocument, attribute='deleted_date_time' ) # DocumentVersion @@ -278,8 +277,7 @@ class DocumentsApp(MayanAppConfig): ) ) SourceColumn( - source=DocumentVersion, label=_('Time and date'), - attribute='timestamp' + source=DocumentVersion, attribute='timestamp' ) SourceColumn( source=DocumentVersion, label=_('Pages'), @@ -288,16 +286,13 @@ class DocumentsApp(MayanAppConfig): ) ) SourceColumn( - source=DocumentVersion, label=_('MIME type'), - attribute='mimetype' + source=DocumentVersion, attribute='mimetype' ) SourceColumn( - source=DocumentVersion, label=_('Encoding'), - attribute='encoding' + source=DocumentVersion, attribute='encoding' ) SourceColumn( - source=DocumentVersion, label=_('Comment'), - attribute='comment' + source=DocumentVersion, attribute='comment' ) # DuplicatedDocument diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 60a9f90e23..afdaeb4e06 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -398,10 +398,12 @@ class DocumentVersion(models.Model): verbose_name=_('File') ) mimetype = models.CharField( - blank=True, editable=False, max_length=255, null=True + blank=True, editable=False, max_length=255, null=True, + verbose_name=_('MIME type') ) encoding = models.CharField( - blank=True, editable=False, max_length=64, null=True + blank=True, editable=False, max_length=64, null=True, + verbose_name=_('Encoding') ) checksum = models.CharField( blank=True, db_index=True, editable=False, max_length=64, null=True, diff --git a/mayan/apps/tags/admin.py b/mayan/apps/tags/admin.py index a703ba2e03..7d0f1a007a 100644 --- a/mayan/apps/tags/admin.py +++ b/mayan/apps/tags/admin.py @@ -8,4 +8,4 @@ from .models import Tag @admin.register(Tag) class TagAdmin(admin.ModelAdmin): filter_horizontal = ('documents',) - list_display = ('label', 'color') + list_display = ('label', 'color', 'get_preview_widget') diff --git a/mayan/apps/tags/apps.py b/mayan/apps/tags/apps.py index 5b8cfd1936..6a3120c9cc 100644 --- a/mayan/apps/tags/apps.py +++ b/mayan/apps/tags/apps.py @@ -25,7 +25,7 @@ from .permissions import ( permission_tag_remove, permission_tag_view ) from .search import tag_search # NOQA -from .widgets import widget_document_tags, widget_single_tag +from .widgets import widget_document_tags class TagsApp(MayanAppConfig): @@ -73,8 +73,10 @@ class TagsApp(MayanAppConfig): ) SourceColumn( - source=DocumentTag, label=_('Preview'), - func=lambda context: widget_single_tag(context['object']) + source=DocumentTag, attribute='label' + ) + SourceColumn( + source=DocumentTag, attribute='get_preview_widget' ) SourceColumn( @@ -93,8 +95,10 @@ class TagsApp(MayanAppConfig): ) SourceColumn( - source=Tag, label=_('Preview'), - func=lambda context: widget_single_tag(context['object']) + source=Tag, attribute='label' + ) + SourceColumn( + source=Tag, attribute='get_preview_widget' ) SourceColumn( source=Tag, label=_('Documents'), diff --git a/mayan/apps/tags/models.py b/mayan/apps/tags/models.py index 975529454d..72157ef897 100644 --- a/mayan/apps/tags/models.py +++ b/mayan/apps/tags/models.py @@ -12,6 +12,7 @@ from documents.models import Document from documents.permissions import permission_document_view from .events import event_tag_attach, event_tag_remove +from .widgets import widget_single_tag @python_2_unicode_compatible @@ -48,6 +49,10 @@ class Tag(models.Model): return queryset.count() + def get_preview_widget(self): + return widget_single_tag(tag=self) + get_preview_widget.short_description = _('Preview') + def remove_from(self, document, user=None): self.documents.remove(document) event_tag_remove.commit( diff --git a/mayan/apps/tags/views.py b/mayan/apps/tags/views.py index ce854bd234..84ab8e43b2 100644 --- a/mayan/apps/tags/views.py +++ b/mayan/apps/tags/views.py @@ -181,6 +181,7 @@ class TagListView(SingleObjectListView): def get_extra_context(self): return { 'hide_link': True, + 'hide_object': True, 'title': _('Tags'), } @@ -224,11 +225,15 @@ class DocumentTagListView(TagListView): ) def get_extra_context(self): - return { - 'hide_link': True, - 'object': self.document, - 'title': _('Tags for document: %s') % self.document, - } + context = super(DocumentTagListView, self).get_extra_context() + context.update( + { + 'hide_link': True, + 'object': self.document, + 'title': _('Tags for document: %s') % self.document, + } + ) + return context def get_tag_queryset(self): return self.document.attached_tags().all()