Commit fc71568c authored by Gladys Forte's avatar Gladys Forte

delegation remove destroy

parent d6574721
...@@ -64,54 +64,61 @@ class DelegationViewSet(viewsets.ModelViewSet): ...@@ -64,54 +64,61 @@ class DelegationViewSet(viewsets.ModelViewSet):
@transaction.atomic @transaction.atomic
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
instance = self.get_object() # instance = self.get_object()
new_instance = model_to_dict(instance) # new_instance = model_to_dict(instance)
message = {
'code': 400,
'status': 'failed',
'message': 'Delegation/s cannot delete, Please update instead'
}
return Response(message, status=status.HTTP_400_BAD_REQUEST)
exist_in_dept = instance.departments.all() # exist_in_dept = instance.departments.all()
# restrictions # restrictions
if not exist_in_dept.count() > 0: # if not exist_in_dept.count() > 0:
print(exist_in_dept) # print(exist_in_dept)
if not (new_instance['name'].lower() == 'head of department' or # if not (new_instance['name'].lower() == 'head of department' or
new_instance['name'].lower() == 'sd/od' or # new_instance['name'].lower() == 'sd/od' or
new_instance['name'].lower() == 'change control board' or # new_instance['name'].lower() == 'change control board' or
new_instance['name'].lower() == 'approver' or # new_instance['name'].lower() == 'approver' or
new_instance['name'].lower() == 'vendor/implementor' or # new_instance['name'].lower() == 'vendor/implementor' or
new_instance['name'].lower() == 'requestor'): # new_instance['name'].lower() == 'requestor'):
self.perform_destroy(instance) # self.perform_destroy(instance)
log_save( # log_save(
enums.LogEnum.DELETED.value, # enums.LogEnum.DELETED.value,
enums.LogEntitiesEnum.DELEGATION.value, # enums.LogEntitiesEnum.DELEGATION.value,
new_instance['id'], # new_instance['id'],
new_instance, # new_instance,
'' # ''
) # )
message = { # message = {
'code': 200, # 'code': 200,
'status': 'success', # 'status': 'success',
'message': 'Delegation Successfully deleted' # 'message': 'Delegation Successfully deleted'
} # }
return Response(message, status=status.HTTP_200_OK) # return Response(message, status=status.HTTP_200_OK)
else: # else:
message = { # message = {
'code': 400, # 'code': 400,
'status': 'failed', # 'status': 'failed',
'message': 'Default delegation cannot delete' # 'message': 'Default delegation cannot delete'
} # }
return Response(message, status=status.HTTP_400_BAD_REQUEST) # return Response(message, status=status.HTTP_400_BAD_REQUEST)
else: # else:
message = { # message = {
'code': 400, # 'code': 400,
'status': 'failed', # 'status': 'failed',
'message': 'Cannot delete this delegation due to existing record in department' # 'message': 'Cannot delete this delegation due to existing record in department'
} # }
return Response(message, status=status.HTTP_400_BAD_REQUEST) # return Response(message, status=status.HTTP_400_BAD_REQUEST)
@transaction.atomic @transaction.atomic
def update(self, request, *args, **kwargs): def update(self, request, *args, **kwargs):
...@@ -136,9 +143,9 @@ class DelegationViewSet(viewsets.ModelViewSet): ...@@ -136,9 +143,9 @@ class DelegationViewSet(viewsets.ModelViewSet):
self.perform_update(serializer) self.perform_update(serializer)
new_instance = serializer.data new_instance = serializer.data
log_save( log_save(
enums.LogEnum.DELETED.value, enums.LogEnum.UPDATE.value,
enums.LogEntitiesEnum.DELEGATION.value, enums.LogEntitiesEnum.DELEGATION.value,
old_instance['id'], old_instance['id'],
old_instance, old_instance,
......
...@@ -91,7 +91,7 @@ class Delegation(AuditClass): ...@@ -91,7 +91,7 @@ class Delegation(AuditClass):
max_length=255 max_length=255
) )
name = models.CharField(unique=True, max_length=255) name = models.CharField(unique=True, max_length=255)
class Meta: class Meta:
db_table = 'delegations' db_table = 'delegations'
......
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