From 40e20756177b4f275e8bdaad9e09c86786d43624 Mon Sep 17 00:00:00 2001 From: gowtham Date: Sun, 1 May 2022 22:51:14 +0530 Subject: [PATCH] AddPPO Api added serializers.py updated Modified Template with IF Cond --- CDC_Backend/APIs/admin.py | 13 ++++++++- CDC_Backend/APIs/adminUrls.py | 1 + CDC_Backend/APIs/adminViews.py | 29 +++++++++++++++++++ CDC_Backend/APIs/constants.py | 2 +- CDC_Backend/APIs/models.py | 2 +- CDC_Backend/APIs/serializers.py | 9 ++++++ .../student_application_submitted.html | 9 ++++-- 7 files changed, 59 insertions(+), 6 deletions(-) diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index a5a0a6d..3f5bb08 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -9,7 +9,8 @@ from .models import * admin.site.register(User) admin.site.register(Admin) -admin.site.register(PrePlacementOffer) + + admin.site.site_header = "CDC Recruitment Portal" @@ -49,3 +50,13 @@ class PlacementApplication(admin.ModelAdmin): return model_admin_url(obj.student) +@admin.register(PrePlacementOffer) +class PrePlacementOffer(admin.ModelAdmin): + list_display = ('company', 'Student', 'accepted') + search_fields = ('company',) + ordering = ('company',) + list_filter = ('accepted',) + + def Student(self, obj): + return model_admin_url(obj.student) + diff --git a/CDC_Backend/APIs/adminUrls.py b/CDC_Backend/APIs/adminUrls.py index bd3d6e5..d99c3e6 100644 --- a/CDC_Backend/APIs/adminUrls.py +++ b/CDC_Backend/APIs/adminUrls.py @@ -12,4 +12,5 @@ urlpatterns = [ path('getApplications/', adminViews.getApplications, name="Get Applications"), path("submitApplication/", adminViews.submitApplication, name="Submit Application"), path('generateCSV/', adminViews.generateCSV, name="Generate CSV"), + path('addPPO/', adminViews.addPPO, name="Add PPO"), ] diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 67d6671..4aeae91 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -305,3 +305,32 @@ def generateCSV(request, id, email, user_type): print(sys.exc_info()) return Response({'action': "Create csv", 'message': "Error Occurred"}, status=status.HTTP_400_BAD_REQUEST) + +@api_view(['POST']) +@isAuthorized(allowed_users=[ADMIN]) +@precheck(required_data=[COMPANY_NAME, COMPENSATION_GROSS, OFFER_ACCEPTED, STUDENT_ID, DESIGNATION, TIER]) +def addPPO(request, id, email, user_type): + try: + data = request.data + PPO = PrePlacementOffer() + PPO.company = data[COMPANY_NAME] + PPO.compensation = data[COMPENSATION_GROSS] + if data[OFFER_ACCEPTED] == "true": + PPO.accepted = True + elif data[OFFER_ACCEPTED] == "false": + PPO.accepted = False + else: + PPO.accepted = None + PPO.student = get_object_or_404(Student, id=data[STUDENT_ID]) + PPO.designation = data[DESIGNATION] + PPO.tier = data[TIER] + if COMPENSATION_DETAILS in data: + PPO.compensation_details = data[COMPENSATION_DETAILS] + PPO.save() + return Response({'action': "Add PPO", 'message': "PPO added"}, + status=status.HTTP_200_OK) + except: + logger.warning("Add PPO: " + str(sys.exc_info())) + print(sys.exc_info()) + return Response({'action': "Add PPO", 'message': "Error Occurred"}, + status=status.HTTP_400_BAD_REQUEST) diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 8197102..7f3d70d 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -50,7 +50,7 @@ EMAIL = "email" STUDENT = 'student' ADMIN = 'admin' COMPANY = '' - +TIER = 'tier' # To be Configured Properly FOURTH_YEAR = '2018' MAX_OFFERS_PER_STUDENT = 2 diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index 3545831..5ab67ff 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -130,7 +130,7 @@ class PlacementApplication(models.Model): class PrePlacementOffer(models.Model): id = models.AutoField(primary_key=True) student = models.ForeignKey(Student, on_delete=models.CASCADE, blank=False) - company = models.CharField(max_length=50, blank=False, default="") + company = models.CharField(max_length=50, blank=False, default="", verbose_name="Company Name") compensation = models.IntegerField(blank=False) # Job - Per Year compensation_details = models.CharField(blank=True, max_length=200) tier = models.CharField(blank=False, choices=TIERS, max_length=10) diff --git a/CDC_Backend/APIs/serializers.py b/CDC_Backend/APIs/serializers.py index 3c63961..b0296a2 100644 --- a/CDC_Backend/APIs/serializers.py +++ b/CDC_Backend/APIs/serializers.py @@ -19,6 +19,7 @@ class StudentSerializer(serializers.ModelSerializer): def get_offers(self, obj): selected_companies = PlacementApplication.objects.filter(student_id=obj.id, selected=True) + pre_placement_offers = PrePlacementOffer.objects.filter(student_id=obj.id) companies = [] for i in selected_companies: @@ -26,6 +27,14 @@ class StudentSerializer(serializers.ModelSerializer): ele['designation'] = i.placement.designation ele['company_name'] = i.placement.company_name ele['application_id'] = i.id + ele['placement_offer_type'] = 'Normal' + companies.append(ele) + for i in pre_placement_offers: + ele = {} + ele['designation'] = i.designation + ele['company_name'] = i.company + ele['application_id'] = i.id + ele['placement_offer_type'] = 'PPO' companies.append(ele) return companies diff --git a/CDC_Backend/templates/student_application_submitted.html b/CDC_Backend/templates/student_application_submitted.html index 05e5be8..87de410 100644 --- a/CDC_Backend/templates/student_application_submitted.html +++ b/CDC_Backend/templates/student_application_submitted.html @@ -42,11 +42,13 @@

Hello there, {{ name }}

+">Hello, {{ name }}

We have received your application for a {{ application_type }} offer at - {{ company_name }} - . We received these additional details
+ {{ company_name }}. + {% if additional_info_items %} + We received these additional details +

@@ -61,6 +63,7 @@ {% endfor %} + {% endif %}