From 85f706828a27d14225249593858e0c0b8f2f604a Mon Sep 17 00:00:00 2001 From: Codewizard-18 Date: Thu, 17 Oct 2024 22:51:33 +0530 Subject: [PATCH 1/5] added api views for placement shedule --- .../placement_cell/api/serializers.py | 9 +- .../applications/placement_cell/api/urls.py | 8 + .../applications/placement_cell/api/views.py | 196 ++++++++++++++++++ .../applications/placement_cell/urls.py | 3 +- 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 FusionIIIT/applications/placement_cell/api/urls.py create mode 100644 FusionIIIT/applications/placement_cell/api/views.py diff --git a/FusionIIIT/applications/placement_cell/api/serializers.py b/FusionIIIT/applications/placement_cell/api/serializers.py index e6960adb0..e1238f29f 100644 --- a/FusionIIIT/applications/placement_cell/api/serializers.py +++ b/FusionIIIT/applications/placement_cell/api/serializers.py @@ -4,7 +4,14 @@ from applications.placement_cell.models import (Achievement, Course, Education, Experience, Has, Patent, Project, Publication, Skill, - PlacementStatus, NotifyStudent) + PlacementStatus, NotifyStudent , PlacementSchedule) + + +class PlacementScheduleSerializer(serializers.ModelSerializer): + class Meta: + model = PlacementSchedule + fields = '__all__' + class SkillSerializer(serializers.ModelSerializer): diff --git a/FusionIIIT/applications/placement_cell/api/urls.py b/FusionIIIT/applications/placement_cell/api/urls.py new file mode 100644 index 000000000..d6bc71b5a --- /dev/null +++ b/FusionIIIT/applications/placement_cell/api/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from .views import PlacementScheduleView,BatchStatisticsView + + +urlpatterns = [ + path('placement/', PlacementScheduleView.as_view(), name='placement-list'), + path('statistics/',BatchStatisticsView.as_view()), +] \ No newline at end of file diff --git a/FusionIIIT/applications/placement_cell/api/views.py b/FusionIIIT/applications/placement_cell/api/views.py new file mode 100644 index 000000000..cc180013f --- /dev/null +++ b/FusionIIIT/applications/placement_cell/api/views.py @@ -0,0 +1,196 @@ +from rest_framework.views import APIView +from rest_framework.response import Response +from rest_framework import status,permissions +from django.contrib.auth.models import User +from django.http import JsonResponse +from django.core.files.storage import FileSystemStorage +from django.views.decorators.csrf import csrf_exempt +from ..models import * +from applications.academic_information.models import Student +from .serializers import PlacementScheduleSerializer, NotifyStudentSerializer +import json + + +from rest_framework.views import APIView +from rest_framework.response import Response +from rest_framework import permissions +from django.http import JsonResponse + +class PlacementScheduleView(APIView): + permission_classes = [permissions.AllowAny] + + def get(self, request): + combined_data = [] + + notify_students = NotifyStudent.objects.all() + for notify in notify_students: + placements = PlacementSchedule.objects.filter(notify_id=notify.id) + placement_serializer = PlacementScheduleSerializer(placements, many=True) + notify_data = NotifyStudentSerializer(notify).data + + for placement in placement_serializer.data: + combined_entry = {**notify_data, **placement} + combined_data.append(combined_entry) + + return Response(combined_data) + + def post(self, request): + placement_type = request.data.get("placement_type") + company_name = request.data.get("company_name") + ctc = request.data.get("ctc") + description = request.data.get("description") + schedule_at = request.data.get("schedule_at") + date = request.data.get("placement_date") + location = request.data.get("location") + role = request.data.get("role") + resume = request.FILES.get("resume") + + try: + role_create, _ = Role.objects.get_or_create(role=role) + notify = NotifyStudent.objects.create( + placement_type=placement_type, + company_name=company_name, + description=description, + ctc=ctc, + timestamp=schedule_at, + ) + + schedule = PlacementSchedule.objects.create( + notify_id=notify, + title=company_name, + description=description, + placement_date=date, + attached_file=resume, + role=role_create, + location=location, + time=schedule_at, + ) + + return JsonResponse({"message": "Successfully Added Schedule"}, status=201) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + + + + +@csrf_exempt +def placement_schedule_save(request): + permission_classes = [permissions.AllowAny] + if request.method != "POST": + return JsonResponse({"error": "Method Not Allowed"}, status=405) + + placement_type = request.POST.get("placement_type") + company_name = request.POST.get("company_name") + ctc = request.POST.get("ctc") + description = request.POST.get("description") + timestamp = request.POST.get("time_stamp") + title = request.POST.get("title") + location = request.POST.get("location") + role = request.POST.get("role") + + resume = request.FILES.get("resume") + schedule_at = request.POST.get("schedule_at") + date = request.POST.get("placement_date") + + try: + role_create, _ = Role.objects.get_or_create(role=role) + + notify = NotifyStudent.objects.create( + placement_type=placement_type, + company_name=company_name, + description=description, + ctc=ctc, + timestamp=timestamp + ) + + schedule = PlacementSchedule.objects.create( + notify_id=notify, + title=company_name, + description=description, + placement_date=date, + attached_file=resume, + role=role_create, + location=location, + time=schedule_at + ) + + return JsonResponse({"message": "Successfully Added Schedule"}, status=201) + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + + + +class BatchStatisticsView(APIView): + def get(self, request): + combined_data = [] + student_records = StudentRecord.objects.all() + + if not student_records.exists(): + return Response({"error": "No student records found"}, status=status.HTTP_404_NOT_FOUND) + + for student in student_records: + try: + cur_student = Student.objects.get(id=student.unique_id) + cur_placement = PlacementRecord.objects.get(id=student.record_id) + user = User.objects.get(id=student.unique_id) + + combined_entry = { + "branch": cur_student.branch, + "placement_name": cur_placement.name, + "ctc": cur_placement.ctc, + "year": cur_placement.year, + "first_name": user.first_name + } + + combined_data.append(combined_entry) + + except Student.DoesNotExist: + return Response({"error": f"Student with id {student.unique_id} not found"}, status=status.HTTP_404_NOT_FOUND) + except PlacementRecord.DoesNotExist: + return Response({"error": f"Placement record with id {student.record_id} not found"}, status=status.HTTP_404_NOT_FOUND) + except User.DoesNotExist: + return Response({"error": f"User with id {student.unique_id} not found"}, status=status.HTTP_404_NOT_FOUND) + except Exception as e: + return Response({"error": str(e)}, status=status.HTTP_400_BAD_REQUEST) + + if not combined_data: + return Response({"message": "No combined data found"}, status=status.HTTP_204_NO_CONTENT) + + return Response(combined_data, status=status.HTTP_200_OK) + + # def get(self, request): + # combined_data = [] + + # # Get all student records + # student_records = StudentRecord.objects.all() + + # for student in student_records: + # # Get the current student, placement record, and user + # cur_student = Student.objects.get(id=student.unique_id) + # cur_placement = PlacementRecord.objects.get(id=student.record_id) + # user = User.objects.get(username=student.unique_id) + + # # Combine the required fields into a dictionary + # combined_entry = { + # "branch": cur_student.branch, # Assuming branch is a field in the Student model + # "placement_name": cur_placement.name, # Name field from PlacementRecord + # "ctc": cur_placement.ctc, # CTC field from PlacementRecord + # "year": cur_placement.year, # Year field from PlacementRecord + # "first_name": user.first_name # First name field from User + # } + + # # Append the combined data to the list + # combined_data.append(combined_entry) + + # return Response(combined_data, status=status.HTTP_200_OK) + + + + + + + + + + diff --git a/FusionIIIT/applications/placement_cell/urls.py b/FusionIIIT/applications/placement_cell/urls.py index 190638861..1aa89d001 100644 --- a/FusionIIIT/applications/placement_cell/urls.py +++ b/FusionIIIT/applications/placement_cell/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.conf.urls import url,include from . import views app_name = 'placement' @@ -26,4 +26,5 @@ url(r'^placement_record_save/$', views.placement_record_save, name='placement_record_save'), url(r'^add_placement_visit/$', views.add_placement_visit, name='add_placement_visit'), url(r'^placement_visit_save/$', views.placement_visit_save, name='placement_visit_save'), + url(r'^api/', include('applications.placement_cell.api.urls')), ] From 3302b5ace36d80b6b2e4c0bb9d069b391baa3bb8 Mon Sep 17 00:00:00 2001 From: Codewizard-18 Date: Tue, 22 Oct 2024 22:34:39 +0530 Subject: [PATCH 2/5] batch statistics --- .../applications/placement_cell/api/views.py | 70 +++++++++---------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/FusionIIIT/applications/placement_cell/api/views.py b/FusionIIIT/applications/placement_cell/api/views.py index cc180013f..67b5f8cc5 100644 --- a/FusionIIIT/applications/placement_cell/api/views.py +++ b/FusionIIIT/applications/placement_cell/api/views.py @@ -1,5 +1,6 @@ from rest_framework.views import APIView from rest_framework.response import Response +from django.shortcuts import get_object_or_404, redirect, render from rest_framework import status,permissions from django.contrib.auth.models import User from django.http import JsonResponse @@ -66,6 +67,7 @@ def post(self, request): time=schedule_at, ) + return redirect('placement') return JsonResponse({"message": "Successfully Added Schedule"}, status=201) except Exception as e: @@ -122,6 +124,7 @@ def placement_schedule_save(request): class BatchStatisticsView(APIView): + permission_classes = [permissions.AllowAny] def get(self, request): combined_data = [] student_records = StudentRecord.objects.all() @@ -131,12 +134,13 @@ def get(self, request): for student in student_records: try: - cur_student = Student.objects.get(id=student.unique_id) - cur_placement = PlacementRecord.objects.get(id=student.record_id) - user = User.objects.get(id=student.unique_id) + cur_student = Student.objects.get(id_id=student.unique_id_id) + cur_placement = PlacementRecord.objects.get(id=student.record_id_id) + user = User.objects.get(username=student.unique_id_id) combined_entry = { - "branch": cur_student.branch, + "branch": cur_student.specialization, + "batch" : cur_placement.year, "placement_name": cur_placement.name, "ctc": cur_placement.ctc, "year": cur_placement.year, @@ -159,38 +163,32 @@ def get(self, request): return Response(combined_data, status=status.HTTP_200_OK) - # def get(self, request): - # combined_data = [] - - # # Get all student records - # student_records = StudentRecord.objects.all() - - # for student in student_records: - # # Get the current student, placement record, and user - # cur_student = Student.objects.get(id=student.unique_id) - # cur_placement = PlacementRecord.objects.get(id=student.record_id) - # user = User.objects.get(username=student.unique_id) - - # # Combine the required fields into a dictionary - # combined_entry = { - # "branch": cur_student.branch, # Assuming branch is a field in the Student model - # "placement_name": cur_placement.name, # Name field from PlacementRecord - # "ctc": cur_placement.ctc, # CTC field from PlacementRecord - # "year": cur_placement.year, # Year field from PlacementRecord - # "first_name": user.first_name # First name field from User - # } - - # # Append the combined data to the list - # combined_data.append(combined_entry) - - # return Response(combined_data, status=status.HTTP_200_OK) - - - - - - - + def post(self,request): + placement_type=request.POST.get("placement_type") + company_name=request.POST.get("company_name") + roll_no = request.POST.get("roll_no") + ctc=request.POST.get("ctc") + year=request.POST.get("year") + test_type=request.POST.get("test_type") + test_score=request.POST.get("test_score") + try: + p2 = PlacementRecord.objects.create( + placement_type = placement_type, + name = company_name, + ctc = ctc, + year = year, + test_score = test_score, + test_type = test_type, + ) + p1 = StudentRecord.objects.create( + record_id = p2, + unique_id_id = roll_no, + ) + return JsonResponse({"message": "Successfully Added"}, status=201) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + From 7bfb27f5381689b456bbc4705c7135d726cff822 Mon Sep 17 00:00:00 2001 From: Codewizard-18 Date: Wed, 23 Oct 2024 11:29:55 +0530 Subject: [PATCH 3/5] delete edit --- .../applications/placement_cell/api/urls.py | 1 + .../applications/placement_cell/api/views.py | 128 +++++++++++++++--- 2 files changed, 107 insertions(+), 22 deletions(-) diff --git a/FusionIIIT/applications/placement_cell/api/urls.py b/FusionIIIT/applications/placement_cell/api/urls.py index d6bc71b5a..ccfb41696 100644 --- a/FusionIIIT/applications/placement_cell/api/urls.py +++ b/FusionIIIT/applications/placement_cell/api/urls.py @@ -4,5 +4,6 @@ urlpatterns = [ path('placement/', PlacementScheduleView.as_view(), name='placement-list'), + path('placement//', PlacementScheduleView.as_view(), name='placement-list'), path('statistics/',BatchStatisticsView.as_view()), ] \ No newline at end of file diff --git a/FusionIIIT/applications/placement_cell/api/views.py b/FusionIIIT/applications/placement_cell/api/views.py index 67b5f8cc5..44d67d038 100644 --- a/FusionIIIT/applications/placement_cell/api/views.py +++ b/FusionIIIT/applications/placement_cell/api/views.py @@ -6,35 +6,41 @@ from django.http import JsonResponse from django.core.files.storage import FileSystemStorage from django.views.decorators.csrf import csrf_exempt +from django.utils.decorators import method_decorator from ..models import * from applications.academic_information.models import Student from .serializers import PlacementScheduleSerializer, NotifyStudentSerializer import json - -from rest_framework.views import APIView -from rest_framework.response import Response -from rest_framework import permissions -from django.http import JsonResponse - +@method_decorator(csrf_exempt, name='dispatch') class PlacementScheduleView(APIView): permission_classes = [permissions.AllowAny] - def get(self, request): - combined_data = [] - - notify_students = NotifyStudent.objects.all() - for notify in notify_students: - placements = PlacementSchedule.objects.filter(notify_id=notify.id) - placement_serializer = PlacementScheduleSerializer(placements, many=True) - notify_data = NotifyStudentSerializer(notify).data - - for placement in placement_serializer.data: - combined_entry = {**notify_data, **placement} - combined_data.append(combined_entry) - - return Response(combined_data) - + def get(self, request, id=None): + if id: + try: + notify_schedule = NotifyStudent.objects.get(id=id) + placement_schedule = PlacementSchedule.objects.get(notify_id=notify_schedule) + combined_entry = {**NotifyStudentSerializer(notify_schedule).data, **PlacementScheduleSerializer(placement_schedule).data} + return Response(combined_entry, status=status.HTTP_200_OK) + except NotifyStudent.DoesNotExist: + return Response({"error": "NotifyStudent not found"}, status=status.HTTP_404_NOT_FOUND) + except PlacementSchedule.DoesNotExist: + return Response({"error": "PlacementSchedule not found"}, status=status.HTTP_404_NOT_FOUND) + else: + combined_data = [] + notify_students = NotifyStudent.objects.all() + for notify in notify_students: + placements = PlacementSchedule.objects.filter(notify_id=notify.id) + placement_serializer = PlacementScheduleSerializer(placements, many=True) + notify_data = NotifyStudentSerializer(notify).data + + for placement in placement_serializer.data: + combined_entry = {**notify_data, **placement} + combined_data.append(combined_entry) + + return Response(combined_data, status=status.HTTP_200_OK) + def post(self, request): placement_type = request.data.get("placement_type") company_name = request.data.get("company_name") @@ -67,11 +73,23 @@ def post(self, request): time=schedule_at, ) - return redirect('placement') return JsonResponse({"message": "Successfully Added Schedule"}, status=201) except Exception as e: return JsonResponse({"error": str(e)}, status=400) + + def delete(self, request, id): + try: + notify_schedule = NotifyStudent.objects.get(id=id) + placement_schedule = PlacementSchedule.objects.get(notify_id=notify_schedule) + notify_schedule.delete() + placement_schedule.delete() + + return JsonResponse({"message": "Successfully Deleted"}, status=200) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + @@ -189,6 +207,72 @@ def post(self,request): except Exception as e: return JsonResponse({"error": str(e)}, status=400) + + def put(self, request, record_id): + try: + placement_record = PlacementRecord.objects.get(id=record_id) + placement_record.placement_type = request.data.get("placement_type", placement_record.placement_type) + placement_record.name = request.data.get("company_name", placement_record.name) + placement_record.ctc = request.data.get("ctc", placement_record.ctc) + placement_record.year = request.data.get("year", placement_record.year) + placement_record.test_score = request.data.get("test_score", placement_record.test_score) + placement_record.test_type = request.data.get("test_type", placement_record.test_type) + placement_record.save() + + return JsonResponse({"message": "Successfully Updated"}, status=200) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + + + def delete(self, request, record_id): + try: + placement_record = PlacementRecord.objects.get(id=record_id) + student_record = StudentRecord.objects.get(record_id=placement_record) + student_record.delete() + placement_record.delete() + + return JsonResponse({"message": "Successfully Deleted"}, status=200) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + + def put(self, request, id): + try: + notify_schedule = NotifyStudent.objects.get(id=id) + placement_schedule = PlacementSchedule.objects.get(notify_id=notify_schedule) + + placement_type = request.data.get("placement_type", notify_schedule.placement_type) + company_name = request.data.get("company_name", notify_schedule.company_name) + ctc = request.data.get("ctc", notify_schedule.ctc) + description = request.data.get("description", notify_schedule.description) + schedule_at = request.data.get("schedule_at", notify_schedule.timestamp) + date = request.data.get("placement_date", placement_schedule.placement_date) + location = request.data.get("location", placement_schedule.location) + role = request.data.get("role", placement_schedule.role) + resume = request.FILES.get("resume", placement_schedule.attached_file) + + notify_schedule.placement_type = placement_type + notify_schedule.company_name = company_name + notify_schedule.ctc = ctc + notify_schedule.description = description + notify_schedule.timestamp = schedule_at + notify_schedule.save() + + placement_schedule.title = company_name + placement_schedule.description = description + placement_schedule.placement_date = date + placement_schedule.location = location + placement_schedule.attached_file = resume + placement_schedule.time = schedule_at + placement_schedule.role = Role.objects.get(role=role) if role else placement_schedule.role + placement_schedule.save() + + return JsonResponse({"message": "Successfully Updated"}, status=200) + + except Exception as e: + return JsonResponse({"error": str(e)}, status=400) + From 08be9f5262e343c55a3da0649d57deaa0b11d441 Mon Sep 17 00:00:00 2001 From: Codewizard-18 Date: Tue, 12 Nov 2024 23:01:50 +0530 Subject: [PATCH 4/5] written apis to view next rond details,track status,and more --- .../applications/placement_cell/api/urls.py | 7 +- .../applications/placement_cell/api/views.py | 303 ++++++++++++++---- .../0002_nextroundinfo_studentapplication.py | 38 +++ .../applications/placement_cell/models.py | 26 ++ 4 files changed, 317 insertions(+), 57 deletions(-) create mode 100644 FusionIIIT/applications/placement_cell/migrations/0002_nextroundinfo_studentapplication.py diff --git a/FusionIIIT/applications/placement_cell/api/urls.py b/FusionIIIT/applications/placement_cell/api/urls.py index ccfb41696..a1062f142 100644 --- a/FusionIIIT/applications/placement_cell/api/urls.py +++ b/FusionIIIT/applications/placement_cell/api/urls.py @@ -1,9 +1,14 @@ from django.urls import path -from .views import PlacementScheduleView,BatchStatisticsView +from .views import * urlpatterns = [ path('placement/', PlacementScheduleView.as_view(), name='placement-list'), path('placement//', PlacementScheduleView.as_view(), name='placement-list'), path('statistics/',BatchStatisticsView.as_view()), + path('generate-cv/',generate_cv,name='generate_cv'), + path('apply-placement/',ApplyForPlacement.as_view(),name="apply"), + path('student-applications//',ApplyForPlacement.as_view()), + path('calender/',NextRoundDetails.as_view()), + path('timeline//',TrackStatus.as_view()), ] \ No newline at end of file diff --git a/FusionIIIT/applications/placement_cell/api/views.py b/FusionIIIT/applications/placement_cell/api/views.py index 036c29a9c..7712fafa5 100644 --- a/FusionIIIT/applications/placement_cell/api/views.py +++ b/FusionIIIT/applications/placement_cell/api/views.py @@ -1,18 +1,23 @@ from rest_framework.views import APIView from rest_framework.response import Response - from django.shortcuts import get_object_or_404, redirect, render - from rest_framework import status,permissions +from rest_framework.decorators import api_view,permission_classes +from rest_framework.permissions import IsAuthenticated +from rest_framework.authentication import TokenAuthentication from django.contrib.auth.models import User -from django.http import JsonResponse +from django.http import JsonResponse,HttpResponse from django.core.files.storage import FileSystemStorage from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator from ..models import * from applications.academic_information.models import Student +from applications.globals.models import ExtraInfo from .serializers import PlacementScheduleSerializer, NotifyStudentSerializer -import json +from applications.academic_information.api.serializers import StudentSerializers +import datetime +import io +from reportlab.pdfgen import canvas @method_decorator(csrf_exempt, name='dispatch') class PlacementScheduleView(APIView): @@ -38,9 +43,14 @@ def get(self, request, id=None): notify_data = NotifyStudentSerializer(notify).data for placement in placement_serializer.data: - combined_entry = {**notify_data, **placement} + counting = StudentApplication.objects.filter(schedule_id_id=placement['id'],unique_id_id=request.user.username).count() + check = "True" + if counting==0: + check="False" + print(check) + combined_entry = {**notify_data, **placement ,'check':check} combined_data.append(combined_entry) - + return Response(combined_data, status=status.HTTP_200_OK) def post(self, request): @@ -132,55 +142,6 @@ def put(self, request, id): - - -@csrf_exempt -def placement_schedule_save(request): - permission_classes = [permissions.AllowAny] - if request.method != "POST": - return JsonResponse({"error": "Method Not Allowed"}, status=405) - - placement_type = request.POST.get("placement_type") - company_name = request.POST.get("company_name") - ctc = request.POST.get("ctc") - description = request.POST.get("description") - timestamp = request.POST.get("time_stamp") - title = request.POST.get("title") - location = request.POST.get("location") - role = request.POST.get("role") - - resume = request.FILES.get("resume") - schedule_at = request.POST.get("schedule_at") - date = request.POST.get("placement_date") - - try: - role_create, _ = Role.objects.get_or_create(role=role) - - notify = NotifyStudent.objects.create( - placement_type=placement_type, - company_name=company_name, - description=description, - ctc=ctc, - timestamp=timestamp - ) - - schedule = PlacementSchedule.objects.create( - notify_id=notify, - title=company_name, - description=description, - placement_date=date, - attached_file=resume, - role=role_create, - location=location, - time=schedule_at - ) - - return JsonResponse({"message": "Successfully Added Schedule"}, status=201) - except Exception as e: - return JsonResponse({"error": str(e)}, status=400) - - - class BatchStatisticsView(APIView): permission_classes = [permissions.AllowAny] @@ -206,7 +167,7 @@ def get(self, request): "placement_name": cur_placement.name, "ctc": cur_placement.ctc, "year": cur_placement.year, - "first_name": user.first_name + "first_name": user.first_name, } combined_data.append(combined_entry) @@ -283,5 +244,235 @@ def delete(self, request, record_id): return JsonResponse({"error": str(e)}, status=400) +@api_view(['POST']) +@permission_classes([IsAuthenticated]) +def generate_cv(request): + fields = request.data + user = request.user + + if user.is_authenticated: + profile = get_object_or_404(ExtraInfo, user=user) + else: + return Response({"error": "User not authenticated"}, status=401) + + buffer = io.BytesIO() + p = canvas.Canvas(buffer) + + y_position = 800 + p.drawString(100, y_position, f"CV for {user.get_full_name()}") + y_position -= 20 + + if fields.get("education", False): + p.drawString(100, y_position, "Education:") + y_position -= 15 + for edu in Education.objects.filter(unique_id=profile.id): + p.drawString(100, y_position, f"- {edu.degree} from {edu.institute}") + y_position -= 15 + + if fields.get("achievements", False): + p.drawString(100, y_position, "Achievements:") + y_position -= 15 + for ach in Achievement.objects.filter(unique_id=profile.id): + p.drawString(100, y_position, f"- {ach.description}") + y_position -= 15 + + if fields.get("skills", False): + p.drawString(100, y_position, "Skills:") + y_position -= 15 + for skil in Has.objects.filter(unique_id=profile.id): + skill_name = Skill.objects.get(id=skil.skill_id_id) + p.drawString(100, y_position, f"- {skill_name.skill}") + y_position -= 15 + + p.showPage() + p.save() + buffer.seek(0) + response = HttpResponse(buffer, content_type="application/pdf") + response['Content-Disposition'] = 'attachment; filename="student_cv.pdf"' + return response + + +@permission_classes([IsAuthenticated]) +class ApplyForPlacement(APIView): + def post(self,request): + user = request.user + profile = get_object_or_404(ExtraInfo, user=user) + student = Student.objects.get(id_id=profile.id) + placement_id = request.data.get('placementId') + placement = PlacementSchedule.objects.get(id=placement_id) + print(f"User: {user}, Profile: {profile}, Student: {student}, Placement ID: {placement_id}") + + try: + application = StudentApplication.objects.create( + schedule_id = placement, + unique_id = student, + current_status = "Pending", + ) + + + return JsonResponse({"message": "Successfully Applied"}, status=201) + + except Exception as e: + print(f"Error creating application: {str(e)}") + return JsonResponse({"error": str(e)}, status=400) + + + def get(self, request, id): + schedule = get_object_or_404(PlacementSchedule, id=id) + applications = StudentApplication.objects.filter(schedule_id=schedule) + + students_data = [] + for application in applications: + roll_no = application.unique_id_id + student = get_object_or_404(Student, id_id=roll_no) + user = get_object_or_404(User, username=roll_no) + + students_data.append({ + 'name': f"{user.first_name} {user.last_name}", + 'roll_no': roll_no, + 'email': user.email, + 'cpi': student.cpi, + 'status': application.current_status, + }) + + return Response({'students': students_data}, status=200) + + def put(self, request, application_id): + application = get_object_or_404(StudentApplication, id=application_id) + + new_status = request.data.get('status') + if new_status is None: + return JsonResponse({"error": "Status is required"}, status=400) + + try: + application.current_status = new_status + application.save() + return JsonResponse({"message": "Status updated successfully"}, status=200) + + except Exception as e: + print(f"Error updating application status: {str(e)}") + return JsonResponse({"error": str(e)}, status=400) + +@permission_classes([IsAuthenticated]) +class NextRoundDetails(APIView): + def post(self,request,id): + placement = PlacementSchedule.objects.get(id=id) + round_no = request.data.get('round_no') + test_type = request.data.get('test_type') + test_date = request.data.get('test_date') + description = request.data.get('description') + + try: + next_round = NextRoundInfo.objects.create( + schedule_id = placement, + round_no = round_no, + test_type = test_type, + test_date = test_date, + description = description, + ) + return JsonResponse({"message": "Successfully Created"}, status=201) + + except Exception as e: + print(f"Error creating round: {str(e)}") + return JsonResponse({"error": str(e)}, status=400) + + def get(self,request): + user = request.user + next_data=[] + if user.username=='omvir': + next_round_data = NextRoundInfo.objects.all() + for nr in next_round_data: + try: + schedule = PlacementSchedule.objects.get(id=nr.schedule_id_id) + print("Valid Schedule:", schedule.title) + except PlacementSchedule.DoesNotExist: + print("No schedule found for schedule_id:", nr.schedule_id_id) + next_data.append({ + 'company_name':schedule.title, + 'date':nr.test_date, + 'type':nr.test_type, + 'round':nr.round_no, + 'description':nr.description, + }) + + else: + profile = get_object_or_404(ExtraInfo, user=user) + roll_no = profile.id + applications = StudentApplication.objects.filter(unique_id_id=roll_no) + + for application in applications: + next_round_data = NextRoundInfo.objects.filter(schedule_id=application.schedule_id) + for nr in next_round_data: + next_data.append({ + 'company_name':application.schedule_id.title, + 'date':nr.test_date, + 'type':nr.test_type, + 'round':nr.round_no, + 'description':nr.description, + }) + + return Response({'schedule_data': next_data}, status=200) + + + def put(self, request, round_id): + next_round = get_object_or_404(NextRoundInfo, id=round_id) + + round_no = request.data.get('round_no') + test_type = request.data.get('test_type') + test_date = request.data.get('test_date') + description = request.data.get('description') + + try: + if round_no is not None: + next_round.round_no = round_no + if test_type is not None: + next_round.test_type = test_type + if test_date is not None: + next_round.test_date = test_date + if description is not None: + next_round.description = description + + next_round.save() + + return JsonResponse({"message": "Successfully Updated"}, status=200) + + except Exception as e: + print(f"Error updating round: {str(e)}") + return JsonResponse({"error": str(e)}, status=400) + + + + +class TrackStatus(APIView): + def get(self,request,id): + user = request.user + profile = get_object_or_404(ExtraInfo, user=user) + roll_no = profile.id + application = StudentApplication.objects.get(unique_id_id=roll_no, schedule_id_id=id) + data = [] + + if application.current_status != 'rejected': + rounds = NextRoundInfo.objects.filter(schedule_id_id=id).order_by('round_no') + round_count = rounds.count() + + for round_info in rounds[:round_count - 1]: + data.append({ + 'round_no': round_info.round_no, + 'test_name': round_info.test_type, + }) + + if round_count > 0: + last_round_info = rounds[round_count - 1] + data.append({ + 'round_no': last_round_info.round_no, + 'test_name': last_round_info.test_type, + 'test_date': last_round_info.test_date, + 'description': last_round_info.description, + }) + + return Response({'next_data': data}, status=200) + + + diff --git a/FusionIIIT/applications/placement_cell/migrations/0002_nextroundinfo_studentapplication.py b/FusionIIIT/applications/placement_cell/migrations/0002_nextroundinfo_studentapplication.py new file mode 100644 index 000000000..6c4b789ac --- /dev/null +++ b/FusionIIIT/applications/placement_cell/migrations/0002_nextroundinfo_studentapplication.py @@ -0,0 +1,38 @@ +# Generated by Django 3.1.5 on 2024-10-31 15:20 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('academic_information', '0001_initial'), + ('placement_cell', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='NextRoundInfo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('round_no', models.IntegerField(default=1)), + ('test_type', models.CharField(default='Interview', max_length=20)), + ('test_date', models.DateField(blank=True, null=True, verbose_name='Date')), + ('description', models.CharField(blank=True, max_length=200, null=True)), + ('schedule_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='placement_cell.placementschedule')), + ], + ), + migrations.CreateModel( + name='StudentApplication', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('current_status', models.CharField(default='Pending', max_length=20)), + ('schedule_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='placement_cell.placementschedule')), + ('unique_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.student')), + ], + options={ + 'unique_together': {('schedule_id', 'unique_id')}, + }, + ), + ] diff --git a/FusionIIIT/applications/placement_cell/models.py b/FusionIIIT/applications/placement_cell/models.py index 53f8d8ea4..25a51d334 100644 --- a/FusionIIIT/applications/placement_cell/models.py +++ b/FusionIIIT/applications/placement_cell/models.py @@ -399,3 +399,29 @@ class StudentPlacement(models.Model): def __str__(self): return self.unique_id.id.id + + + +class NextRoundInfo(models.Model): + schedule_id = models.ForeignKey(PlacementSchedule, on_delete=models.CASCADE) + round_no = models.IntegerField(default=1) + test_type = models.CharField(max_length=20,default="Interview") + test_date = models.DateField(_("Date"), null=True, blank=True) + description = models.CharField(max_length=200 ,null=True, blank=True) + + def __str__(self): + return f'Round {self.round_no}: {self.test_type} on {self.test_date}' + + +class StudentApplication(models.Model): + schedule_id = models.ForeignKey(PlacementSchedule, on_delete=models.CASCADE) + unique_id = models.ForeignKey(Student, on_delete=models.CASCADE) + current_status = models.CharField(max_length=20,default="Pending") + + class Meta: + unique_together = (('schedule_id', 'unique_id'),) + + def __str__(self): + return '{} - {}'.format(self.unique_id.id, self.schedule_id.title) + + From 7dec0c4534c871bc93d7889eebaf7765b9319d89 Mon Sep 17 00:00:00 2001 From: Codewizard-18 Date: Sun, 17 Nov 2024 00:24:12 +0530 Subject: [PATCH 5/5] made some changes while integration --- .../applications/placement_cell/api/views.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/FusionIIIT/applications/placement_cell/api/views.py b/FusionIIIT/applications/placement_cell/api/views.py index 919b5f670..4a6a17a9d 100644 --- a/FusionIIIT/applications/placement_cell/api/views.py +++ b/FusionIIIT/applications/placement_cell/api/views.py @@ -85,10 +85,6 @@ def post(self, request): time=schedule_at, ) - - - return redirect('placement') - return JsonResponse({"message": "Successfully Added Schedule"}, status=201) except Exception as e: @@ -134,7 +130,7 @@ def put(self, request, id): placement_schedule.location = location placement_schedule.attached_file = resume placement_schedule.time = schedule_at - placement_schedule.role = Role.objects.get(role=role) if role else placement_schedule.role + placement_schedule.role = Role.objects.get(id=role) if role else placement_schedule.role placement_schedule.save() return JsonResponse({"message": "Successfully Updated"}, status=200) @@ -302,7 +298,7 @@ def post(self,request): user = request.user profile = get_object_or_404(ExtraInfo, user=user) student = Student.objects.get(id_id=profile.id) - placement_id = request.data.get('placementId') + placement_id = request.data.get('jobId') placement = PlacementSchedule.objects.get(id=placement_id) print(f"User: {user}, Profile: {profile}, Student: {student}, Placement ID: {placement_id}") @@ -321,24 +317,27 @@ def post(self,request): return JsonResponse({"error": str(e)}, status=400) - def get(self, request, id): + def get(self, request,id): schedule = get_object_or_404(PlacementSchedule, id=id) - applications = StudentApplication.objects.filter(schedule_id=schedule) + applications = StudentApplication.objects.filter(schedule_id_id=schedule.id) + print(schedule.id) students_data = [] for application in applications: roll_no = application.unique_id_id + print(roll_no) student = get_object_or_404(Student, id_id=roll_no) user = get_object_or_404(User, username=roll_no) students_data.append({ + 'id':application.id, 'name': f"{user.first_name} {user.last_name}", 'roll_no': roll_no, 'email': user.email, 'cpi': student.cpi, 'status': application.current_status, }) - + print(students_data) return Response({'students': students_data}, status=200) def put(self, request, application_id):