From 58f7b1b55571f4eb8f99d717b496385a142f26d3 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 17 Sep 2018 03:39:28 -0400 Subject: [PATCH] Add file_size and datetime fields to the DocumentPageCachedImage model. Signed-off-by: Roberto Rosario --- HISTORY.rst | 2 ++ .../migrations/0047_auto_20180917_0737.py | 27 +++++++++++++++++++ mayan/apps/documents/models.py | 11 ++++++++ 3 files changed, 40 insertions(+) create mode 100644 mayan/apps/documents/migrations/0047_auto_20180917_0737.py diff --git a/HISTORY.rst b/HISTORY.rst index c7e053df65..a24e0c0d7f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -157,6 +157,8 @@ - Expose more document fields for use in smart links. - The size of the document type label field has been increased from 32 to 96 characters. +- Add file_size and datetime fields to the DocumentPageCachedImage + model. 3.0.3 (2018-08-17) ================== diff --git a/mayan/apps/documents/migrations/0047_auto_20180917_0737.py b/mayan/apps/documents/migrations/0047_auto_20180917_0737.py new file mode 100644 index 0000000000..3f9e50501e --- /dev/null +++ b/mayan/apps/documents/migrations/0047_auto_20180917_0737.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.11 on 2018-09-17 07:37 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('documents', '0046_auto_20180917_0713'), + ] + + operations = [ + migrations.AddField( + model_name='documentpagecachedimage', + name='datetime', + field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now, verbose_name='Date time'), + preserve_default=False, + ), + migrations.AddField( + model_name='documentpagecachedimage', + name='file_size', + field=models.PositiveIntegerField(db_index=True, default=0, verbose_name='File size'), + ), + ] diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 2df15eceed..86d6e8c3d3 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -997,7 +997,13 @@ class DocumentPageCachedImage(models.Model): on_delete=models.CASCADE, related_name='cached_images', to=DocumentPage, verbose_name=_('Document page') ) + datetime = models.DateTimeField( + auto_now_add=True, db_index=True, verbose_name=_('Date time') + ) filename = models.CharField(max_length=128, verbose_name=_('Filename')) + file_size = models.PositiveIntegerField( + db_index=True, default=0, verbose_name=_('File size') + ) class Meta: verbose_name = _('Document page cached image') @@ -1007,6 +1013,11 @@ class DocumentPageCachedImage(models.Model): storage_documentimagecache.delete(self.filename) return super(DocumentPageCachedImage, self).delete(*args, **kwargs) + def save(self, *args, **kwargs): + self.file_size = storage_documentimagecache.size(self.filename) + return super(DocumentPageCachedImage, self).save(*args, **kwargs) + + class DocumentPageResult(DocumentPage): class Meta: