Style: Move document model functions
Move the document UUID and document hash functions to the documents.utils module. Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
@@ -17,7 +17,7 @@ class Migration(migrations.Migration):
|
||||
model_name='document',
|
||||
name='uuid',
|
||||
field=models.CharField(
|
||||
default=mayan.apps.documents.models.UUID_FUNCTION,
|
||||
default=mayan.apps.documents.utils.document_uuid_function,
|
||||
editable=False, max_length=48,
|
||||
),
|
||||
preserve_default=True,
|
||||
@@ -27,7 +27,7 @@ class Migration(migrations.Migration):
|
||||
name='file',
|
||||
field=models.FileField(
|
||||
storage=FileSystemStorage(),
|
||||
upload_to=mayan.apps.documents.models.UUID_FUNCTION,
|
||||
upload_to=mayan.apps.documents.utils.document_uuid_function,
|
||||
verbose_name='File'
|
||||
),
|
||||
preserve_default=True,
|
||||
|
||||
@@ -17,7 +17,7 @@ class Migration(migrations.Migration):
|
||||
field=models.FileField(
|
||||
storage=django.core.files.storage.FileSystemStorage(
|
||||
location=b'mayan/media/document_storage'
|
||||
), upload_to=mayan.apps.documents.models.UUID_FUNCTION,
|
||||
), upload_to=mayan.apps.documents.utils.document_uuid_function,
|
||||
verbose_name='File'
|
||||
),
|
||||
model_name='documentversion', name='file',
|
||||
|
||||
@@ -24,7 +24,7 @@ class Migration(migrations.Migration):
|
||||
field=models.FileField(
|
||||
storage=django.core.files.storage.FileSystemStorage(
|
||||
location=b'/home/rosarior/development/mayan-edms/mayan/media/document_storage'
|
||||
), upload_to=mayan.apps.documents.models.UUID_FUNCTION,
|
||||
), upload_to=mayan.apps.documents.utils.document_uuid_function,
|
||||
verbose_name='File'
|
||||
),
|
||||
model_name='documentversion', name='file',
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
@@ -55,19 +54,11 @@ from .signals import (
|
||||
post_document_created, post_document_type_change, post_version_upload
|
||||
)
|
||||
from .storages import storage_documentversion
|
||||
from .utils import document_hash_function, document_uuid_function
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# document image cache name hash function
|
||||
def HASH_FUNCTION(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def UUID_FUNCTION(*args, **kwargs):
|
||||
return force_text(uuid.uuid4())
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class DocumentType(models.Model):
|
||||
"""
|
||||
@@ -433,7 +424,7 @@ class DocumentVersion(models.Model):
|
||||
|
||||
# File related fields
|
||||
file = models.FileField(
|
||||
storage=storage_documentversion, upload_to=UUID_FUNCTION,
|
||||
storage=storage_documentversion, upload_to=document_uuid_function,
|
||||
verbose_name=_('File')
|
||||
)
|
||||
mimetype = models.CharField(
|
||||
@@ -701,7 +692,7 @@ class DocumentVersion(models.Model):
|
||||
"""
|
||||
if self.exists():
|
||||
source = self.open()
|
||||
self.checksum = force_text(HASH_FUNCTION(source.read()))
|
||||
self.checksum = force_text(document_hash_function(source.read()))
|
||||
source.close()
|
||||
if save:
|
||||
self.save()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import uuid
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from .literals import DOCUMENT_IMAGES_CACHE_NAME
|
||||
|
||||
@@ -12,6 +16,14 @@ def callback_update_cache_size(setting):
|
||||
cache.save()
|
||||
|
||||
|
||||
def document_hash_function(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def document_uuid_function(*args, **kwargs):
|
||||
return force_text(uuid.uuid4())
|
||||
|
||||
|
||||
def parse_range(astr):
|
||||
# http://stackoverflow.com/questions/4248399/
|
||||
# page-range-for-printing-algorithm
|
||||
|
||||
Reference in New Issue
Block a user