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): ...@@ -1365,6 +1365,7 @@ class ChangeRequestFormPost(APIView):
except ValidationError as e: except ValidationError as e:
transaction.savepoint_rollback(sp1) transaction.savepoint_rollback(sp1)
message = { message = {
'code': 400, 'code': 400,
'status': 'failed', 'status': 'failed',
......
...@@ -14,7 +14,8 @@ from app.applicationlayer.utils import (CustomPagination, ...@@ -14,7 +14,8 @@ from app.applicationlayer.utils import (CustomPagination,
status_message_response) status_message_response)
from app.applicationlayer.cms.utils_cr import ( 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.applicationlayer.utils import model_to_dict
from app.entities import enums, models from app.entities import enums, models
...@@ -443,6 +444,11 @@ class ChangeRequestTemplatePost(APIView): ...@@ -443,6 +444,11 @@ class ChangeRequestTemplatePost(APIView):
except ValidationError as e: except ValidationError as e:
transaction.savepoint_rollback(sp1) transaction.savepoint_rollback(sp1)
if template_header['tmp_attachments']:
delete_master_attachment_file(
template_header['tmp_attachments'])
message = { message = {
'code': 400, 'code': 400,
'status': 'failed', 'status': 'failed',
...@@ -452,6 +458,11 @@ class ChangeRequestTemplatePost(APIView): ...@@ -452,6 +458,11 @@ class ChangeRequestTemplatePost(APIView):
except Exception as e: except Exception as e:
transaction.savepoint_rollback(sp1) transaction.savepoint_rollback(sp1)
if template_header['tmp_attachments']:
delete_master_attachment_file(
template_header['tmp_attachments'])
message = { message = {
'code': 500, 'code': 500,
'status': 'failed', 'status': 'failed',
......
...@@ -822,4 +822,13 @@ def cancelled_user_trigger(form_code, ...@@ -822,4 +822,13 @@ def cancelled_user_trigger(form_code,
# create notification # create notification
notification_create(form_code, message, receiver_code, notification_create(form_code, message, receiver_code,
sender_code, 'cms') sender_code, 'cms')
\ No newline at end of file
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