diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index 31b5b81..08ac51b 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -60,6 +60,7 @@ def model_admin_url(obj, name=None) -> str: class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin): pass + @admin.register(Student) class Student(StudentAdmin): list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply') @@ -98,6 +99,17 @@ class AdminAdmin(ExportMixin, SimpleHistoryAdmin): resource_class = PlacementResources +class PlacementResources(resources.ModelResource): + class Meta: + model = Placement + exclude = ('id', 'changed_by', 'is_company_details_pdf', 'is_description_pdf', + 'is_compensation_details_pdf', 'is_selection_procedure_details_pdf') + + +class AdminAdmin(ExportMixin, SimpleHistoryAdmin): + resource_class = PlacementResources + + @admin.register(Placement) class Placement(AdminAdmin): list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC') @@ -111,6 +123,7 @@ class PlacementApplicationResources(resources.ModelResource): model = PlacementApplication exclude = ('id', 'changed_by') + class PlacementAdmin(ExportMixin, SimpleHistoryAdmin): resource_class = PlacementApplicationResources @@ -134,6 +147,7 @@ class PrePlacementResources(resources.ModelResource): model = PrePlacementOffer exclude = ('id', 'changed_by') + class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin): resource_class = PrePlacementResources diff --git a/CDC_Backend/APIs/studentUrls.py b/CDC_Backend/APIs/studentUrls.py index f532849..45b3619 100644 --- a/CDC_Backend/APIs/studentUrls.py +++ b/CDC_Backend/APIs/studentUrls.py @@ -9,4 +9,5 @@ urlpatterns = [ path("addResume/", studentViews.addResume, name="Upload Resume"), path("deleteResume/", studentViews.deleteResume, name="Upload Resume"), path("submitApplication/", studentViews.submitApplication, name="Submit Application"), + path("deleteApplication/", studentViews.deleteApplication, name="Delete Application"), ] diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 0fbadd0..45993a5 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -204,3 +204,30 @@ def submitApplication(request, id, email, user_type): return Response({'action': "Submit Application", 'message': "Something Went Wrong"}, status=status.HTTP_400_BAD_REQUEST) + + +@api_view(['POST']) +@isAuthorized(allowed_users=[STUDENT]) +@precheck(required_data=[APPLICATION_ID]) +def deleteApplication(request, id, email, user_type): + try: + data = request.data + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID], + student_id=id) + if application.placement.deadline_datetime < timezone.now(): + raise PermissionError("Deadline Passed") + + application.delete() + return Response({'action': "Delete Application", 'message': "Application Deleted"}, + status=status.HTTP_200_OK) + except Http404 as e: + return Response({'action': "Delete Application", 'message': str(e)}, + status=status.HTTP_404_NOT_FOUND) + except PermissionError as e: + return Response({'action': "Delete Application", 'message': str(e)}, + status=status.HTTP_403_FORBIDDEN) + except: + logger.warning("Delete Application: " + str(sys.exc_info())) + + return Response({'action': "Delete Application", 'message': "Something Went Wrong"}, + status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file