From 9e30cf10c526812a0636dbd0bab294fb20a3fef0 Mon Sep 17 00:00:00 2001 From: Jaswanth Meda Date: Fri, 18 Oct 2024 00:02:39 +0530 Subject: [PATCH] Adding api's (#1) * fix: Resolved System Check errors (#1630) - fix: Changed one line bugs * Resolved system check errors * Changed some fields in IWD Module * Fixes creation of unwanted migration files - chore: migration files for the previous commit changes * added api views for placement shedule --------- Co-authored-by: ramGopal <129493911+ramG-reddy@users.noreply.github.com> --- .../migrations/0002_auto_20241012_1459.py | 23 ++ .../applications/central_mess/models.py | 2 +- FusionIIIT/applications/globals/models.py | 4 +- .../applications/hostel_management/urls.py | 2 +- .../hr2/migrations/0002_auto_20241012_1459.py | 64 ++++++ FusionIIIT/applications/hr2/models.py | 20 +- .../migrations/0002_auto_20241012_1459.py | 89 ++++++++ FusionIIIT/applications/iwdModuleV2/models.py | 24 +-- FusionIIIT/applications/iwdModuleV2/views.py | 6 +- .../migrations/0002_auto_20241012_1459.py | 40 ++++ .../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 +- .../migrations/0002_auto_20241012_1459.py | 19 ++ .../research_procedures/models.py | 2 +- 16 files changed, 479 insertions(+), 32 deletions(-) create mode 100644 FusionIIIT/applications/central_mess/migrations/0002_auto_20241012_1459.py create mode 100644 FusionIIIT/applications/hr2/migrations/0002_auto_20241012_1459.py create mode 100644 FusionIIIT/applications/iwdModuleV2/migrations/0002_auto_20241012_1459.py create mode 100644 FusionIIIT/applications/online_cms/migrations/0002_auto_20241012_1459.py create mode 100644 FusionIIIT/applications/placement_cell/api/urls.py create mode 100644 FusionIIIT/applications/placement_cell/api/views.py create mode 100644 FusionIIIT/applications/research_procedures/migrations/0002_auto_20241012_1459.py diff --git a/FusionIIIT/applications/central_mess/migrations/0002_auto_20241012_1459.py b/FusionIIIT/applications/central_mess/migrations/0002_auto_20241012_1459.py new file mode 100644 index 000000000..fd5b1d205 --- /dev/null +++ b/FusionIIIT/applications/central_mess/migrations/0002_auto_20241012_1459.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.5 on 2024-10-12 14:59 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('central_mess', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='payments', + name='payment_date', + field=models.DateField(default=datetime.date.today), + ), + migrations.AlterUniqueTogether( + name='payments', + unique_together=set(), + ), + ] diff --git a/FusionIIIT/applications/central_mess/models.py b/FusionIIIT/applications/central_mess/models.py index ae96e8f82..3e6030952 100644 --- a/FusionIIIT/applications/central_mess/models.py +++ b/FusionIIIT/applications/central_mess/models.py @@ -154,7 +154,7 @@ class Payments(models.Model): amount_paid = models.IntegerField(default=0) payment_month = models.CharField(max_length=20, default=current_month) payment_year = models.IntegerField(default = current_year) - payment_date = models.DateField(default= datetime.date.today()) + payment_date = models.DateField(default= datetime.date.today) # class Meta: # unique_together = (('student_id', 'payment_date')) diff --git a/FusionIIIT/applications/globals/models.py b/FusionIIIT/applications/globals/models.py index b5d7df426..6a924ceff 100644 --- a/FusionIIIT/applications/globals/models.py +++ b/FusionIIIT/applications/globals/models.py @@ -65,10 +65,10 @@ class Constants: ('academic', 'Academic Designation'), ('administrative', 'Administrative Designation'), ) - USER_STATUS = { + USER_STATUS = ( ("NEW", "NEW"), ("PRESENT", "PRESENT"), - } + ) class Designation(models.Model): diff --git a/FusionIIIT/applications/hostel_management/urls.py b/FusionIIIT/applications/hostel_management/urls.py index 95fcdeeb8..28c1915c2 100644 --- a/FusionIIIT/applications/hostel_management/urls.py +++ b/FusionIIIT/applications/hostel_management/urls.py @@ -12,7 +12,7 @@ path('admin/', admin.site.urls), #Home path('', views.hostel_view, name="hostel_view"), - path('/hello', views.hostel_view, name="hello"), + path('hello', views.hostel_view, name="hello"), #Notice Board path('notice_form/', views.notice_board, name="notice_board"), diff --git a/FusionIIIT/applications/hr2/migrations/0002_auto_20241012_1459.py b/FusionIIIT/applications/hr2/migrations/0002_auto_20241012_1459.py new file mode 100644 index 000000000..be4738fe2 --- /dev/null +++ b/FusionIIIT/applications/hr2/migrations/0002_auto_20241012_1459.py @@ -0,0 +1,64 @@ +# Generated by Django 3.1.5 on 2024-10-12 14:59 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hr2', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='appraisalform', + name='employeeId', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='cpdaadvanceform', + name='amountRequired', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='cpdaadvanceform', + name='employeeId', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='cpdaadvanceform', + name='pfNo', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='cpdareimbursementform', + name='employeeId', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='cpdareimbursementform', + name='pfNo', + field=models.IntegerField(), + ), + migrations.AlterField( + model_name='empconfidentialdetails', + name='aadhar_no', + field=models.BigIntegerField(default=0, validators=[django.core.validators.MaxValueValidator(999999999999), django.core.validators.MinValueValidator(99999999999)]), + ), + migrations.AlterField( + model_name='leaveform', + name='employeeId', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='leaveform', + name='pfNo', + field=models.IntegerField(null=True), + ), + migrations.AlterField( + model_name='ltcform', + name='pfNo', + field=models.IntegerField(), + ), + ] diff --git a/FusionIIIT/applications/hr2/models.py b/FusionIIIT/applications/hr2/models.py index 01ca223c7..e225ca076 100644 --- a/FusionIIIT/applications/hr2/models.py +++ b/FusionIIIT/applications/hr2/models.py @@ -78,7 +78,7 @@ class EmpConfidentialDetails(models.Model): table for employee confidential details """ extra_info = models.OneToOneField(ExtraInfo, on_delete=models.CASCADE) - aadhar_no = models.BigIntegerField(default=0, max_length=12, + aadhar_no = models.BigIntegerField(default=0, validators=[MaxValueValidator(999999999999),MinValueValidator(99999999999)]) maritial_status = models.CharField( @@ -149,7 +149,7 @@ class LTCform(models.Model): employeeId = models.IntegerField() name = models.CharField(max_length=100, null=True) blockYear = models.TextField() # - pfNo = models.IntegerField(max_length=50) + pfNo = models.IntegerField() basicPaySalary = models.IntegerField(null=True) designation = models.CharField(max_length=50) departmentInfo = models.CharField(max_length=50) @@ -181,12 +181,12 @@ class LTCform(models.Model): class CPDAAdvanceform(models.Model): id = models.AutoField(primary_key=True) - employeeId = models.IntegerField(max_length=22, null=True) + employeeId = models.IntegerField(null=True) name = models.CharField(max_length=40,null=True) designation = models.CharField(max_length=40,null=True) - pfNo = models.IntegerField(max_length=30,null=True) + pfNo = models.IntegerField(null=True) purpose = models.TextField(max_length=40, null=True) - amountRequired = models.IntegerField(max_length=30,null=True) + amountRequired = models.IntegerField(null=True) advanceDueAdjustment = models.DecimalField(max_digits=10, decimal_places=2, null=True,blank=True) submissionDate = models.DateField(blank=True, null=True) @@ -202,11 +202,11 @@ class CPDAAdvanceform(models.Model): class LeaveForm(models.Model): id = models.AutoField(primary_key=True) - employeeId = models.IntegerField(max_length=22,null=True) + employeeId = models.IntegerField(null=True) name = models.CharField(max_length=40,null=True) designation = models.CharField(max_length=40,null=True) submissionDate = models.DateField(blank=True, null=True) - pfNo = models.IntegerField(max_length=30,null=True) + pfNo = models.IntegerField(null=True) departmentInfo = models.CharField(max_length=40,null=True) natureOfLeave = models.TextField(max_length=40,null=True) leaveStartDate = models.DateField(blank=True, null=True) @@ -237,7 +237,7 @@ class LeaveBalance(models.Model): class Appraisalform(models.Model): id = models.AutoField(primary_key=True) - employeeId = models.IntegerField(max_length=22,null=True) + employeeId = models.IntegerField(null=True) name = models.CharField(max_length=22) designation = models.CharField(max_length=50) disciplineInfo = models.CharField(max_length=22, null=True) @@ -273,10 +273,10 @@ class Appraisalform(models.Model): class CPDAReimbursementform(models.Model): id = models.AutoField(primary_key=True) - employeeId = models.IntegerField(max_length=22,null=True) + employeeId = models.IntegerField(null=True) name = models.CharField(max_length=50) designation = models.CharField(max_length=50) - pfNo = models.IntegerField(max_length=20) + pfNo = models.IntegerField() advanceTaken = models.IntegerField() purpose = models.TextField() adjustmentSubmitted = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True) diff --git a/FusionIIIT/applications/iwdModuleV2/migrations/0002_auto_20241012_1459.py b/FusionIIIT/applications/iwdModuleV2/migrations/0002_auto_20241012_1459.py new file mode 100644 index 000000000..546d6c629 --- /dev/null +++ b/FusionIIIT/applications/iwdModuleV2/migrations/0002_auto_20241012_1459.py @@ -0,0 +1,89 @@ +# Generated by Django 3.1.5 on 2024-10-12 14:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('iwdModuleV2', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='pageonedetails', + name='page_id', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AddField( + model_name='pagethreedetails', + name='page_id', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AddField( + model_name='pagetwodetails', + name='page_id', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='addendum', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='agreement', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='corrigendumtable', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='financialbiddetails', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='letterofintentdetails', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='nooftechnicalbidtimes', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='pageonedetails', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='pagethreedetails', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='pagetwodetails', + name='id', + field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='prebiddetails', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='technicalbiddetails', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + migrations.AlterField( + model_name='workorderform', + name='key', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='iwdModuleV2.projects'), + ), + ] diff --git a/FusionIIIT/applications/iwdModuleV2/models.py b/FusionIIIT/applications/iwdModuleV2/models.py index 9a3337987..9c79aa21c 100644 --- a/FusionIIIT/applications/iwdModuleV2/models.py +++ b/FusionIIIT/applications/iwdModuleV2/models.py @@ -9,7 +9,7 @@ class Projects(models.Model): class PageOneDetails(models.Model): - id = models.ForeignKey(Projects, on_delete=models.CASCADE, primary_key=True) + page_id = models.OneToOneField(Projects, on_delete=models.CASCADE, null=True) aESFile = models.FileField(null=True) dASA = models.DateField(null=True) nitNiqNo = models.IntegerField(null=True) @@ -31,7 +31,7 @@ class AESDetails(models.Model): class PageTwoDetails(models.Model): - id = models.ForeignKey(Projects, on_delete=models.CASCADE, primary_key=True) + page_id = models.OneToOneField(Projects, on_delete=models.CASCADE, null=True) corrigendum = models.FileField(null=True) addendum = models.FileField(null=True) preBidMeetingDetails = models.FileField(null=True) @@ -46,7 +46,7 @@ class PageTwoDetails(models.Model): class CorrigendumTable(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) issueDate = models.DateField() nitNo = models.IntegerField() name = models.CharField(max_length=200) @@ -59,7 +59,7 @@ class CorrigendumTable(models.Model): class Addendum(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) issueDate = models.DateField() nitNiqNo = models.IntegerField() name = models.CharField(max_length=200) @@ -68,7 +68,7 @@ class Addendum(models.Model): class PreBidDetails(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) sNo = models.CharField(max_length=200) nameOfParticipants = models.CharField(max_length=200) issuesRaised = models.CharField(max_length=200) @@ -76,7 +76,7 @@ class PreBidDetails(models.Model): class TechnicalBidDetails(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) sNo = models.CharField(max_length=200) requirements = models.CharField(max_length=200) @@ -88,7 +88,7 @@ class TechnicalBidContractorDetails(models.Model): class FinancialBidDetails(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) sNo = models.CharField(max_length=200) description = models.CharField(max_length=200) @@ -103,7 +103,7 @@ class FinancialContractorDetails(models.Model): class LetterOfIntentDetails(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) nitNiqNo = models.IntegerField() dateOfOpening = models.DateField() agency = models.CharField(max_length=200) @@ -112,7 +112,7 @@ class LetterOfIntentDetails(models.Model): class WorkOrderForm(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) issueDate = models.DateField() nitNiqNo = models.IntegerField() agency = models.CharField(max_length=200) @@ -127,7 +127,7 @@ class WorkOrderForm(models.Model): class Agreement(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) date = models.DateField() agencyName = models.CharField(max_length=200) workName = models.CharField(max_length=200) @@ -143,7 +143,7 @@ class Milestones(models.Model): class PageThreeDetails(models.Model): - id = models.ForeignKey(Projects, on_delete=models.CASCADE, primary_key=True) + page_id = models.OneToOneField(Projects, on_delete=models.CASCADE, null=True) extensionOfTime = models.FileField() actualCostOfBuilding = models.IntegerField() @@ -157,7 +157,7 @@ class ExtensionOfTimeDetails(models.Model): class NoOfTechnicalBidTimes(models.Model): - key = models.ForeignKey(Projects, on_delete=models.CASCADE, unique=True) + key = models.OneToOneField(Projects, on_delete=models.CASCADE) number = models.IntegerField() class Requests(models.Model): diff --git a/FusionIIIT/applications/iwdModuleV2/views.py b/FusionIIIT/applications/iwdModuleV2/views.py index 1f999ebd9..be7042499 100644 --- a/FusionIIIT/applications/iwdModuleV2/views.py +++ b/FusionIIIT/applications/iwdModuleV2/views.py @@ -360,13 +360,13 @@ def page1View(request): if request.POST: request.session['projectId'] = request.POST['id'] projectPageOne = PageOneDetails.objects.get( - id=Projects.objects.get(id=request.session['projectId'])) + id=Projects.objects.get(page_id=request.session['projectId'])) return render(request, 'iwdModuleV2/Page1.html', {'x': projectPageOne}) def page2View(request): projectPageTwo = PageTwoDetails.objects.get( - id=Projects.objects.get(id=request.session['projectId'])) + id=Projects.objects.get(page_id=request.session['projectId'])) return render(request, 'iwdModuleV2/Page2.html', {'x': projectPageTwo}) @@ -445,7 +445,7 @@ def milestoneView(request): def page3View(request): pageThreeDetails = PageThreeDetails.objects.get( - id=Projects.objects.get(id=request.session['projectId'])) + id=Projects.objects.get(page_id=request.session['projectId'])) return render(request, 'iwdModuleV2/Page3.html', {'x': pageThreeDetails}) diff --git a/FusionIIIT/applications/online_cms/migrations/0002_auto_20241012_1459.py b/FusionIIIT/applications/online_cms/migrations/0002_auto_20241012_1459.py new file mode 100644 index 000000000..d689e8177 --- /dev/null +++ b/FusionIIIT/applications/online_cms/migrations/0002_auto_20241012_1459.py @@ -0,0 +1,40 @@ +# Generated by Django 3.1.5 on 2024-10-12 14:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('academic_information', '0001_initial'), + ('online_cms', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='attendance', + name='no_of_attendance', + field=models.IntegerField(default=1), + ), + migrations.AlterField( + model_name='attendance', + name='present', + field=models.IntegerField(default=0), + ), + migrations.AlterField( + model_name='gradingscheme', + name='type_of_evaluation', + field=models.CharField(max_length=100), + ), + migrations.CreateModel( + name='StudentEvaluation', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('marks', models.DecimalField(decimal_places=2, max_digits=10, null=True)), + ('total_marks', models.DecimalField(decimal_places=2, default=0, max_digits=10)), + ('evaluation_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='online_cms.gradingscheme')), + ('student_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.student')), + ], + ), + ] 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')), ] diff --git a/FusionIIIT/applications/research_procedures/migrations/0002_auto_20241012_1459.py b/FusionIIIT/applications/research_procedures/migrations/0002_auto_20241012_1459.py new file mode 100644 index 000000000..eebc5845e --- /dev/null +++ b/FusionIIIT/applications/research_procedures/migrations/0002_auto_20241012_1459.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2024-10-12 14:59 + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('research_procedures', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='staff_allocations', + name='start_date', + field=models.DateField(default=datetime.date.today), + ), + ] diff --git a/FusionIIIT/applications/research_procedures/models.py b/FusionIIIT/applications/research_procedures/models.py index a02aad5e3..3a653e374 100644 --- a/FusionIIIT/applications/research_procedures/models.py +++ b/FusionIIIT/applications/research_procedures/models.py @@ -77,7 +77,7 @@ class staff_allocations(models.Model): year=models.IntegerField() stipend=models.IntegerField() staff_type=models.CharField(max_length=100,default="research") - start_date=models.DateField(default=datetime.date.today()) #default=datetime.date.today() + start_date=models.DateField(default=datetime.date.today) end_date=models.DateField(null=True, blank=True) def __str__(self):