Add NewDocumentVersionNotAllowed exception to documents app

This commit is contained in:
Roberto Rosario
2012-06-15 19:28:22 -04:00
parent 30842d5d9b
commit 8fdd361071
2 changed files with 10 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
class NewDocumentVersionNotAllowed(Exception):
"""
Uploading new versions for this document is not allowed
Current reasons: Document is in checked out state
"""
pass

View File

@@ -37,6 +37,7 @@ from .managers import DocumentPageTransformationManager
from .utils import document_save_to_temp_dir
from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES,
VERSION_UPDATE_MAJOR, VERSION_UPDATE_MINOR, VERSION_UPDATE_MICRO)
from .exceptions import NewDocumentVersionNotAllowed
# document image cache name hash function
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
@@ -171,6 +172,9 @@ class Document(models.Model):
def new_version(self, file, comment=None, version_update=None, release_level=None, serial=None):
logger.debug('creating new document version')
if not self.is_new_versions_allowed():
raise NewDocumentVersionNotAllowed
if version_update:
new_version_dict = self.latest_version.get_new_version_dict(version_update)
logger.debug('new_version_dict: %s' % new_version_dict)