def get_context_data(self, **kwargs): """ Retrieves the context data of this view """ # We would like to add years to our index to enable filterbuttons context = super(GalleryIndex, self).get_context_data(**kwargs) years = set() total_disk_usage = 0 # We cannot re-use the self.queryset, as it contains cached instances that might be deleted, # thus causing the file size summation to fail due to missing files. for img in ResponsiveImage.objects.all(): years.add(img.timestamp.year) if img.id: try: total_disk_usage += img.sizeof_total_raw() except OSError as e: getLogger(__name__).error('GalleryIndex file summation on missing file: %s' % e) # Filter out potential ResponsiveImage objects that have orphan file references context['images'] = [i for i in context['images'] if i.file_status_ok()] # Add query filters and some statistics on disk usage context['years'] = years context['tags'] = sorted(set(tag.tag.name for tag in TaggedItem.objects.filter( content_type=ContentType.objects.get_for_model(ResponsiveImage) ).order_by('tag__name'))) context['disk_usage'] = humanize_size(total_disk_usage) return context
def sizeof_total(self): """ Returns a human readable string representation of the total disk usage. """ total = self.sizeof_total_raw() return humanize_size(total)
def sizeof_total(self): return humanize_size(self.image.size + self.thumbnail.size)
def sizeof_original(self): return humanize_size(self.image.size)