Merge branch 'main' into track-object-changes-new

This commit is contained in:
karthik mv 2022-06-30 00:52:36 +05:30 committed by GitHub
commit a3e4077723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 16 deletions

View File

@ -8,7 +8,8 @@ urlpatterns = [
path('updateDeadline/', adminViews.updateDeadline, name="Update Deadline"),
path('updateOfferAccepted/', adminViews.updateOfferAccepted, name="Update Offer Accepted"),
path('updateEmailVerified', adminViews.updateEmailVerified, name="Update Email Verified"),
path('updateAdditionalInfo/', adminViews.updateAdditionalInfo, name="Update Additional Info"),
path('deleteAdditionalInfo/', adminViews.deleteAdditionalInfo, name="Delete Additional Info"),
path('addAdditionalInfo/', adminViews.addAdditionalInfo, name="Add Additional Info"),
path('getApplications/', adminViews.getApplications, name="Get Applications"),
path("submitApplication/", adminViews.submitApplication, name="Submit Application"),
path('generateCSV/', adminViews.generateCSV, name="Generate CSV"),

View File

@ -149,33 +149,58 @@ def updateEmailVerified(request, id, email, user_type):
@api_view(['POST'])
@isAuthorized([ADMIN])
@precheck([OPENING_ID, ADDITIONAL_INFO])
def updateAdditionalInfo(request, id, email, user_type):
@precheck([OPENING_ID, FIELD])
def deleteAdditionalInfo(request, id, email, user_type):
try:
data = request.data
opening = get_object_or_404(Placement, pk=data[OPENING_ID])
if data[ADDITIONAL_INFO] == "":
opening.additional_info = []
elif isinstance(data[ADDITIONAL_INFO], list):
opening.additional_info = data[ADDITIONAL_INFO]
if data[FIELD] in opening.additional_info:
opening.additional_info.remove(data[FIELD])
opening.changed_by = get_object_or_404(User, id=id)
opening.save()
return Response({'action': "Delete Additional Info", 'message': "Additional Info Deleted"},
status=status.HTTP_200_OK)
else:
raise ValueError("Additional Info must be a list")
opening.changed_by = get_object_or_404(User, id=id)
opening.save()
return Response({'action': "Update Additional Info", 'message': "Additional Info Updated"},
status=status.HTTP_200_OK)
raise ValueError("Additional Info Not Found")
except Http404:
return Response({'action': "Update Additional Info", 'message': 'Opening Not Found'},
return Response({'action': "Delete Additional Info", 'message': 'Opening Not Found'},
status=status.HTTP_404_NOT_FOUND)
except ValueError:
return Response({'action': "Update Additional Info", 'message': "Additional Info must be a list"},
return Response({'action': "Delete Additional Info", 'message': "Additional Info not found"},
status=status.HTTP_404_NOT_FOUND)
except Exception as e:
logger.warning("Delete Additional Info: " + str(e))
return Response({'action': "Delete Additional Info", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)
@api_view(['POST'])
@isAuthorized([ADMIN])
@precheck([OPENING_ID, FIELD])
def addAdditionalInfo(request, id, email, user_type):
try:
data = request.data
opening = get_object_or_404(Placement, pk=data[OPENING_ID])
if data[FIELD] not in opening.additional_info:
opening.additional_info.append(data[FIELD])
opening.save()
return Response({'action': "Add Additional Info", 'message': "Additional Info Added"},
status=status.HTTP_200_OK)
else:
raise ValueError("Additional Info Found")
except Http404:
return Response({'action': "Add Additional Info", 'message': 'Opening Not Found'},
status=status.HTTP_404_NOT_FOUND)
except ValueError:
return Response({'action': "Add Additional Info", 'message': "Additional Info already found"},
status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
logger.warning("Update Additional Info: " + str(e))
return Response({'action': "Update Additional Info", 'message': "Something went wrong"},
logger.warning("Add Additional Info: " + str(e))
return Response({'action': "Add Additional Info", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)
@api_view(['GET'])
@isAuthorized([ADMIN])
@precheck([OPENING_ID])

View File

@ -70,6 +70,7 @@ RESUME_FILE_NAME = 'resume_file_name'
APPLICATION_ID = "application_id"
OPENING_ID = "opening_id"
ADDITIONAL_INFO = "additional_info"
FIELD = "field"
STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications"