Commit 91b6c315 authored by Gladys Forte's avatar Gladys Forte

{dev bugfix} delete media file on master attachment when error occurs

parent c0703d79
......@@ -1365,6 +1365,7 @@ class ChangeRequestFormPost(APIView):
except ValidationError as e:
transaction.savepoint_rollback(sp1)
message = {
'code': 400,
'status': 'failed',
......
......@@ -14,7 +14,8 @@ from app.applicationlayer.utils import (CustomPagination,
status_message_response)
from app.applicationlayer.cms.utils_cr import (
entity_log_bulk
entity_log_bulk,
delete_master_attachment_file
)
from app.applicationlayer.utils import model_to_dict
from app.entities import enums, models
......@@ -443,6 +444,11 @@ class ChangeRequestTemplatePost(APIView):
except ValidationError as e:
transaction.savepoint_rollback(sp1)
if template_header['tmp_attachments']:
delete_master_attachment_file(
template_header['tmp_attachments'])
message = {
'code': 400,
'status': 'failed',
......@@ -452,6 +458,11 @@ class ChangeRequestTemplatePost(APIView):
except Exception as e:
transaction.savepoint_rollback(sp1)
if template_header['tmp_attachments']:
delete_master_attachment_file(
template_header['tmp_attachments'])
message = {
'code': 500,
'status': 'failed',
......
......@@ -822,4 +822,13 @@ def cancelled_user_trigger(form_code,
# create notification
notification_create(form_code, message, receiver_code,
sender_code, 'cms')
\ No newline at end of file
sender_code, 'cms')
def delete_master_attachment_file(attachments):
# delete master attachment data and media file attachments
for attachment in attachments:
attach = models.MasterAttachment.objects.filter(
id=attachment['file_upload'])
if attach:
attach.first().delete()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment