modified article publish and un-publish api, sonar issues, modification in create task api

This commit is contained in:
abutalib-kiwi
2023-09-07 13:49:06 +05:30
parent ffb99f5099
commit bc18c67527
4 changed files with 64 additions and 31 deletions

View File

@ -185,9 +185,12 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
try:
image = request.data['default_image']
junior_ids = request.data['junior'].split(',')
# if not junior.isnumeric():
# """junior value must be integer"""
# return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
invalid_junior_ids = [junior_id for junior_id in junior_ids if not junior_id.isnumeric()]
if invalid_junior_ids:
# At least one junior value is not an integer
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
allowed_extensions = ['.jpg', '.jpeg', '.png']
if not any(extension in str(image) for extension in allowed_extensions):
return custom_error_response(ERROR_CODE['2048'], response_status=status.HTTP_400_BAD_REQUEST)
@ -203,15 +206,14 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
guardian = Guardian.objects.filter(user=request.user).select_related('user').last()
junior_data = Junior.objects.filter(id__in=junior_ids).select_related('auth')
for junior in junior_data:
if junior:
if junior_data:
for junior in junior_data:
index = junior.guardian_code.index(guardian.guardian_code)
status_index = junior.guardian_code_status[index]
if status_index == str(NUMBER['three']):
return custom_error_response(ERROR_CODE['2078'], response_status=status.HTTP_400_BAD_REQUEST)
else:
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
else:
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
# use TaskSerializer serializer
serializer = TaskSerializer(context={"guardian": guardian, "image": image_data,