Move default ACLS application, recent document setting and document creation event from the Source model to the Document model
Now event document directly created by the save() method of the Document model will have those properties set
This commit is contained in:
@@ -19,13 +19,16 @@ from django.utils.timezone import now
|
||||
from django.utils.translation import ugettext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from acls.utils import apply_default_acls
|
||||
from converter.api import (convert, get_page_count,
|
||||
get_available_transformations_choices)
|
||||
from converter.exceptions import UnknownFileFormat
|
||||
from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
|
||||
DEFAULT_PAGE_NUMBER)
|
||||
from history.api import create_history
|
||||
from mimetype.api import get_mimetype
|
||||
|
||||
from .events import HISTORY_DOCUMENT_CREATED
|
||||
from .exceptions import NewDocumentVersionNotAllowed
|
||||
from .literals import (RELEASE_LEVEL_CHOICES, RELEASE_LEVEL_FINAL,
|
||||
VERSION_UPDATE_MAJOR, VERSION_UPDATE_MICRO,
|
||||
@@ -104,11 +107,22 @@ class Document(models.Model):
|
||||
return ('documents:document_view_simple', [self.pk])
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.pk:
|
||||
user = kwargs.pop('user', None)
|
||||
new_document = not self.pk
|
||||
if new_document:
|
||||
self.uuid = UUID_FUNCTION()
|
||||
self.date_added = now()
|
||||
super(Document, self).save(*args, **kwargs)
|
||||
|
||||
if new_document:
|
||||
apply_default_acls(self, user)
|
||||
|
||||
if user:
|
||||
self.add_as_recent_document_for_user(user)
|
||||
create_history(HISTORY_DOCUMENT_CREATED, self, {'user': user})
|
||||
else:
|
||||
create_history(HISTORY_DOCUMENT_CREATED, self)
|
||||
|
||||
def get_cached_image_name(self, page, version):
|
||||
document_version = DocumentVersion.objects.get(pk=version)
|
||||
document_page = document_version.pages.get(page_number=page)
|
||||
|
||||
@@ -12,13 +12,10 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from model_utils.managers import InheritanceManager
|
||||
|
||||
from acls.utils import apply_default_acls
|
||||
from common.compressed_files import CompressedFile, NotACompressedFile
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.literals import DIMENSION_SEPARATOR
|
||||
from documents.events import HISTORY_DOCUMENT_CREATED
|
||||
from documents.models import Document
|
||||
from history.api import create_history
|
||||
from metadata.api import save_metadata_list
|
||||
|
||||
from .classes import StagingFile
|
||||
@@ -92,7 +89,7 @@ class Source(models.Model):
|
||||
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None, description=None):
|
||||
new_document = not document
|
||||
|
||||
if not document:
|
||||
if new_document:
|
||||
document = Document()
|
||||
if document_type:
|
||||
document.document_type = document_type
|
||||
@@ -100,17 +97,7 @@ class Source(models.Model):
|
||||
if description:
|
||||
document.description = description
|
||||
|
||||
document.save()
|
||||
|
||||
# TODO: move this to the Document model
|
||||
apply_default_acls(document, user)
|
||||
|
||||
# TODO: move this to the Document model
|
||||
if user:
|
||||
document.add_as_recent_document_for_user(user)
|
||||
create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
|
||||
else:
|
||||
create_history(HISTORY_DOCUMENT_CREATED, document)
|
||||
document.save(user=user)
|
||||
else:
|
||||
if use_file_name:
|
||||
filename = None
|
||||
|
||||
Reference in New Issue
Block a user