publish occupancy (#16828)
As an absolute size, as a ratio of the max size and as a percentage of the max size.
This commit is contained in:
parent
09cd831cf4
commit
6cca9e9165
|
@ -232,6 +232,10 @@ class Document(models.Model):
|
|||
return ''
|
||||
return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height}
|
||||
|
||||
@classmethod
|
||||
def occupancy_for_user(cls, user):
|
||||
return float(sum(document.content.size for document in cls.objects.filter(user_documents__user=user).distinct()))
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
|
||||
|
||||
|
|
|
@ -86,6 +86,10 @@ class Homepage(Documents, 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)
|
||||
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
|
||||
return ctx
|
||||
|
||||
def get_success_url(self):
|
||||
|
@ -182,7 +186,7 @@ class Thumbnail(Documents, View):
|
|||
thumbnail = user_document.document.thumbnail
|
||||
if not thumbnail:
|
||||
raise Http404
|
||||
return HttpResponse(thumbnail.chunks(), content_type='image/jpeg')
|
||||
return HttpResponse(thumbnail.read(), content_type='image/jpeg')
|
||||
|
||||
|
||||
class RemoteDownload(Download):
|
||||
|
|
Loading…
Reference in New Issue