Add support for natural keys to the DocumentPageImageCache model.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* Add test mixin to test the db conversion (dumping and loading) of a specific app.
|
||||
* Add an user test mixin to group user testing.
|
||||
* Add test the user managament app for database conversion.
|
||||
* Add support for natural keys to the DocumentPageImageCache model.
|
||||
|
||||
3.1.1 (2018-09-18)
|
||||
==================
|
||||
|
||||
@@ -34,6 +34,21 @@ class DocumentManager(models.Manager):
|
||||
document.invalidate_cache()
|
||||
|
||||
|
||||
class DocumentPageCachedImage(models.Manager):
|
||||
def get_by_natural_key(self, filename, document_page_natural_key):
|
||||
DocumentPage = apps.get_model(
|
||||
app_label='documents', model_name='DocumentPage'
|
||||
)
|
||||
try:
|
||||
document_page = DocumentPage.objects.get_by_natural_key(
|
||||
*document_page_natural_key
|
||||
)
|
||||
except DocumentPage.DoesNotExist:
|
||||
raise self.model.DoesNotExist
|
||||
|
||||
return self.get(document_page__pk=document_page.pk, filename=filename)
|
||||
|
||||
|
||||
class DocumentPageManager(models.Manager):
|
||||
def get_by_natural_key(self, page_number, document_version_natural_key):
|
||||
DocumentVersion = apps.get_model(
|
||||
|
||||
@@ -36,9 +36,10 @@ from .events import (
|
||||
)
|
||||
from .literals import DEFAULT_DELETE_PERIOD, DEFAULT_DELETE_TIME_UNIT
|
||||
from .managers import (
|
||||
DocumentManager, DocumentPageManager, DocumentVersionManager,
|
||||
DocumentTypeManager, DuplicatedDocumentManager, FavoriteDocumentManager,
|
||||
PassthroughManager, RecentDocumentManager, TrashCanManager
|
||||
DocumentManager, DocumentPageCachedImage, DocumentPageManager,
|
||||
DocumentVersionManager, DocumentTypeManager, DuplicatedDocumentManager,
|
||||
FavoriteDocumentManager, PassthroughManager, RecentDocumentManager,
|
||||
TrashCanManager
|
||||
)
|
||||
from .permissions import permission_document_view
|
||||
from .settings import (
|
||||
@@ -1005,6 +1006,8 @@ class DocumentPageCachedImage(models.Model):
|
||||
db_index=True, default=0, verbose_name=_('File size')
|
||||
)
|
||||
|
||||
objects = DocumentPageCachedImage()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Document page cached image')
|
||||
verbose_name_plural = _('Document page cached images')
|
||||
@@ -1013,6 +1016,10 @@ class DocumentPageCachedImage(models.Model):
|
||||
storage_documentimagecache.delete(self.filename)
|
||||
return super(DocumentPageCachedImage, self).delete(*args, **kwargs)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.filename, self.document_page.natural_key())
|
||||
natural_key.dependencies = ['documents.DocumentPage']
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.file_size = storage_documentimagecache.size(self.filename)
|
||||
return super(DocumentPageCachedImage, self).save(*args, **kwargs)
|
||||
|
||||
@@ -18,13 +18,18 @@ from .literals import (
|
||||
TEST_PDF_INDIRECT_ROTATE_PATH, TEST_OFFICE_DOCUMENT_PATH,
|
||||
TEST_SMALL_DOCUMENT_CHECKSUM, TEST_SMALL_DOCUMENT_FILENAME,
|
||||
TEST_SMALL_DOCUMENT_MIMETYPE, TEST_SMALL_DOCUMENT_PATH,
|
||||
TEST_SMALL_DOCUMENT_SIZE
|
||||
TEST_SMALL_DOCUMENT_SIZE, TEST_DOCUMENT_FILENAME
|
||||
)
|
||||
from .mixins import DocumentTestMixin
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=False)
|
||||
class DocumentTestCase(DocumentTestMixin, BaseTestCase):
|
||||
def test_natural_keys(self):
|
||||
self.document.pages.first().generate_image()
|
||||
|
||||
self._test_database_conversion('documents')
|
||||
|
||||
def test_document_creation(self):
|
||||
self.assertEqual(self.document_type.label, TEST_DOCUMENT_TYPE_LABEL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user