Commit fc71568c authored by Gladys Forte's avatar Gladys Forte

delegation remove destroy

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