#86 Revocation edit
* adds support for revocation edit
* revocation document files will be replaced on an edit
This commit is contained in:
@@ -24,7 +24,7 @@ from konova.contexts import BaseContext
|
||||
from konova.models import BaseObject, Geometry, RecordableObjectMixin
|
||||
from konova.settings import DEFAULT_SRID
|
||||
from konova.tasks import celery_update_parcels
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from konova.utils.message_templates import FORM_INVALID, FILE_TYPE_UNSUPPORTED, FILE_SIZE_TOO_LARGE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -424,14 +424,14 @@ class NewDocumentForm(BaseModalForm):
|
||||
if not mime_type_valid:
|
||||
self.add_error(
|
||||
"file",
|
||||
_("Unsupported file type")
|
||||
FILE_TYPE_UNSUPPORTED
|
||||
)
|
||||
|
||||
file_size_valid = self.document_model.is_file_size_valid(_file)
|
||||
if not file_size_valid:
|
||||
self.add_error(
|
||||
"file",
|
||||
_("File too large")
|
||||
FILE_SIZE_TOO_LARGE
|
||||
)
|
||||
|
||||
file_valid = mime_type_valid and file_size_valid
|
||||
|
||||
@@ -101,3 +101,19 @@ class AbstractDocument(BaseResource):
|
||||
def is_file_size_valid(cls, _file):
|
||||
max_size = cls._maximum_file_size * pow(1000, 2)
|
||||
return _file.size <= max_size
|
||||
|
||||
def replace_file(self, new_file):
|
||||
""" Replaces the old file on the hard drive with the new one
|
||||
|
||||
Args:
|
||||
new_file (File): The new file
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
try:
|
||||
os.remove(self.file.file.name)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
self.file = new_file
|
||||
self.save()
|
||||
@@ -18,6 +18,10 @@ MISSING_GROUP_PERMISSION = _("You need to be part of another user group.")
|
||||
|
||||
CHECKED_RECORDED_RESET = _("Status of Checked and Recorded reseted")
|
||||
|
||||
# FILES
|
||||
FILE_TYPE_UNSUPPORTED = _("Unsupported file type")
|
||||
FILE_SIZE_TOO_LARGE = _("File too large")
|
||||
|
||||
# ECO ACCOUNT
|
||||
CANCEL_ACC_RECORDED_OR_DEDUCTED = _("Action canceled. Eco account is recorded or deductions exist. Only conservation office member can perform this action.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user