AddPPO Api added

serializers.py updated
Modified Template with IF Cond
This commit is contained in:
gowtham 2022-05-01 22:51:14 +05:30
parent d052e51df1
commit cf5a618523
7 changed files with 59 additions and 6 deletions

View File

@ -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)

View File

@ -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"),
]

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -42,11 +42,13 @@
<tr>
<td style="padding:0 0 36px 0;color:#153643;">
<h1 style="font-size:24px;margin:0 0 20px 0;font-family: 'Roboto', sans-serif;
">Hello there, {{ name }}</h1>
">Hello, {{ name }}</h1>
<p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family: 'Roboto', sans-serif;">
We have received your application for a <b>{{ application_type }}</b> offer at <b>
{{ company_name }}</b>
. We received these additional details<br>
{{ company_name }}</b>.
{% if additional_info_items %}
We received these additional details
<br>
<p style="margin:0 0 12px 0;font-size:16px;line-height:24px;font-family:
'Roboto', sans-serif;text-align: center">
@ -61,6 +63,7 @@
</tr>
{% endfor %}
</table>
{% endif %}
</p>
</p>