diff --git a/mayan/apps/common/utils.py b/mayan/apps/common/utils.py index 16cee91d2d..548b7cde7b 100644 --- a/mayan/apps/common/utils.py +++ b/mayan/apps/common/utils.py @@ -71,33 +71,6 @@ def get_descriptor(file_input, read=True): return file_input -# http://snippets.dzone.com/posts/show/5434 -# http://snippets.dzone.com/user/jakob -def pretty_size(size, suffixes=None): - suffixes = suffixes or [ - ('B', 1024L), ('K', 1048576L), ('M', 1073741824L), - ('G', 1099511627776L), ('T', 1125899906842624L) - ] - - for suf, lim in suffixes: - if size > lim: - continue - else: - try: - return round(size / float(lim / 1024L), 2).__str__() + suf - except ZeroDivisionError: - return 0 - - -def pretty_size_10(size): - return pretty_size( - size, - suffixes=[ - ('B', 1000L), ('K', 1000000L), ('M', 1000000000L), - ('G', 1000000000000L), ('T', 1000000000000000L) - ]) - - def render_date_object(date_time_object): return force_text(formats.localize(date_time_object, use_l10n=True)) diff --git a/mayan/apps/documents/statistics.py b/mayan/apps/documents/statistics.py index 3569ee5eab..63f0bfba0e 100644 --- a/mayan/apps/documents/statistics.py +++ b/mayan/apps/documents/statistics.py @@ -1,9 +1,9 @@ from __future__ import absolute_import, unicode_literals +from django.db.models import Avg, Count, Max, Min +from django.template.defaultfilters import filesizeformat from django.utils.translation import ugettext_lazy as _ -from django.db.models import Avg, Count, Min, Max -from common.utils import pretty_size, pretty_size_10 from statistics.classes import Statistic from .models import Document, DocumentType, DocumentPage, DocumentVersion @@ -44,23 +44,27 @@ class DocumentStatistics(Statistic): def get_results(self): results = [] - results.extend([ - _('Document types: %d') % DocumentType.objects.count(), - ]) + results.extend( + [ + _('Document types: %d') % DocumentType.objects.count(), + ] + ) document_stats = DocumentVersion.objects.annotate( page_count=Count('pages') ).aggregate(Min('page_count'), Max('page_count'), Avg('page_count')) - results.extend([ - _( - 'Minimum amount of pages per document: %d' - ) % (document_stats['page_count__min'] or 0), - _( - 'Maximum amount of pages per document: %d' - ) % (document_stats['page_count__max'] or 0), - _( - 'Average amount of pages per document: %f' - ) % (document_stats['page_count__avg'] or 0), - ]) + results.extend( + [ + _( + 'Minimum amount of pages per document: %d' + ) % (document_stats['page_count__min'] or 0), + _( + 'Maximum amount of pages per document: %d' + ) % (document_stats['page_count__max'] or 0), + _( + 'Average amount of pages per document: %f' + ) % (document_stats['page_count__avg'] or 0), + ] + ) return results @@ -71,23 +75,21 @@ class DocumentUsageStatistics(Statistic): total_db_documents = Document.objects.only('pk',).count() - results.extend([ - _('Documents in database: %d') % total_db_documents, - ]) + results.extend( + [ + _('Documents in database: %d') % total_db_documents, + ] + ) try: total_storage_documents, storage_used_space = storage_count() - results.append(_('Documents in storage: %d') % - total_storage_documents) + results.append( + _('Documents in storage: %d') % total_storage_documents + ) results.append( _( - 'Space used in storage: %(base_2)s (base 2), %(base_10)s ' - '(base 10), %(bytes)d bytes' - ) % { - 'base_2': pretty_size(storage_used_space), - 'base_10': pretty_size_10(storage_used_space), - 'bytes': storage_used_space - } + 'Space used in storage: %s' + ) % filesizeformat(storage_used_space) ) except NotImplementedError: pass diff --git a/mayan/apps/documents/views.py b/mayan/apps/documents/views.py index c00fb622b9..37ece0564a 100644 --- a/mayan/apps/documents/views.py +++ b/mayan/apps/documents/views.py @@ -8,6 +8,7 @@ from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied from django.core.urlresolvers import resolve, reverse, reverse_lazy +from django.template.defaultfilters import filesizeformat from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext @@ -21,7 +22,7 @@ from common.generics import ( SingleObjectEditView, SingleObjectListView ) from common.mixins import MultipleInstanceActionMixin -from common.utils import pretty_size, render_date_object +from common.utils import render_date_object from converter.literals import ( DEFAULT_PAGE_NUMBER, DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL ) @@ -278,15 +279,15 @@ def document_properties(request, document_id): document_fields.extend([ { 'label': _('File mimetype'), - 'field': lambda x: x.file_mimetype or _('None') + 'field': lambda x: document.file_mimetype or _('None') }, { 'label': _('File encoding'), - 'field': lambda x: x.file_mime_encoding or _('None') + 'field': lambda x: document.file_mime_encoding or _('None') }, { 'label': _('File size'), - 'field': lambda x: pretty_size(x.size) if x.size else '-' + 'field': lambda document: filesizeformat(document.size) if document.size else '-' }, {'label': _('Exists in storage'), 'field': 'exists'}, {'label': _('File path in storage'), 'field': 'latest_version.file'},