From ac9a609f2b00746c0f28fc8c6cabcbc162f360f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sat, 11 Apr 2020 10:03:29 +0200 Subject: [PATCH] misc: don't ignore duplicated file in occupancy calculation (#41617) --- fargo/fargo/managers.py | 2 +- fargo/fargo/models.py | 5 ----- fargo/fargo/views.py | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/fargo/fargo/managers.py b/fargo/fargo/managers.py index e319cd2..13f489c 100644 --- a/fargo/fargo/managers.py +++ b/fargo/fargo/managers.py @@ -47,4 +47,4 @@ class DocumentManager(models.Manager): return o def used_space(self, user): - return sum([doc.content.size for doc in self.filter(user_documents__user=user).distinct()]) + return sum([doc.content.size for doc in self.filter(user_documents__user=user)]) diff --git a/fargo/fargo/models.py b/fargo/fargo/models.py index 6b08c34..547d16a 100644 --- a/fargo/fargo/models.py +++ b/fargo/fargo/models.py @@ -254,11 +254,6 @@ class Document(models.Model): return '' return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height} - @classmethod - def occupancy_for_user(cls, user): - documents = cls.objects.filter(user_documents__user=user).distinct() - return float(sum(document.content.size for document in documents)) - def __unicode__(self): return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6]) diff --git a/fargo/fargo/views.py b/fargo/fargo/views.py index 2bedee5..8b95bbb 100644 --- a/fargo/fargo/views.py +++ b/fargo/fargo/views.py @@ -118,7 +118,7 @@ class Homepage(SingleTableMixin, CommonUpload): ctx = super(Homepage, self).get_context_data(**kwargs) ctx['include_edit_link'] = settings.INCLUDE_EDIT_LINK ctx['max_document_size'] = settings.FARGO_MAX_DOCUMENT_SIZE - occupancy = ctx['occupancy'] = models.Document.occupancy_for_user(self.request.user) + occupancy = ctx['occupancy'] = models.Document.objects.used_space(self.request.user) max_size = ctx['max_portfolio_size'] = settings.FARGO_MAX_DOCUMENT_BOX_SIZE ctx['occupancy_ratio'] = float(occupancy) / max_size ctx['occupancy_ratio_percent'] = float(occupancy) * 100.0 / max_size