Modified APIs

This commit is contained in:
Gowtham 2021-12-16 23:05:04 +05:30
parent d99c8ab5d9
commit 95fd24a776
8 changed files with 55 additions and 27 deletions

View File

@ -8,10 +8,7 @@ from django.utils.safestring import SafeText
from .models import *
admin.site.register(User)
# admin.site.register(Student)
admin.site.register(Admin)
# admin.site.register(Placement)
admin.site.register(PlacementApplication)
admin.site.register(PrePlacementOffer)
admin.site.site_header = "CDC Recruitment Portal"
@ -38,4 +35,17 @@ class Placement(admin.ModelAdmin):
list_filter = ('tier',)
@admin.register(PlacementApplication)
class PlacementApplication(admin.ModelAdmin):
list_display = ('id', 'Placement', 'Student', 'selected')
search_fields = ('id',)
ordering = ('id',)
list_filter = ('selected',)
def Placement(self, obj):
return model_admin_url(obj.placement)
def Student(self, obj):
return model_admin_url(obj.student)

View File

@ -53,13 +53,15 @@ def markStatus(request, id, email, user_type):
def getDashboard(request, id, email, user_type):
try:
placements = Placement.objects.all().order_by('-created_at')
ongoing = placements.filter(deadline_datetime__gt=datetime.now())
previous = placements.exclude(deadline_datetime__gt=datetime.now())
ongoing = placements.filter(deadline_datetime__gt=datetime.now(), offer_accepted__isnull=False)
previous = placements.exclude(deadline_datetime__gt=datetime.now()).filter(offer_accepted__isnull=False)
new = placements.filter(offer_accepted__isnull=True)
ongoing = PlacementSerializerForAdmin(ongoing, many=True).data
previous = PlacementSerializerForAdmin(previous, many=True).data
new = PlacementSerializerForAdmin(new, many=True).data
return Response(
{'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous},
{'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous, "new": new},
status=status.HTTP_200_OK)
except Http404:
return Response({'action': "Get Dashboard - Admin", 'message': 'Student Not Found'},

View File

@ -193,6 +193,8 @@ def addPlacement(request):
# Check if tentative_no_of_offers is integer
if data[TENTATIVE_NO_OF_OFFERS].isdigit():
opening.tentative_no_of_offers = int(data[TENTATIVE_NO_OF_OFFERS])
elif data[TENTATIVE_NO_OF_OFFERS] == 'null':
opening.tentative_no_of_offers = None
else:
raise ValueError('Tentative No Of Offers must be an integer')

View File

@ -22,6 +22,9 @@ class Student(models.Model):
resumes = ArrayField(models.CharField(null=True, default=None, max_length=100), size=10, default=list, blank=True)
cpi = models.DecimalField(decimal_places=2, max_digits=4)
def __str__(self):
return str(self.roll_no)
class Admin(models.Model):
id = models.CharField(blank=False, max_length=15, primary_key=True)
@ -81,7 +84,7 @@ class Placement(models.Model):
size=TOTAL_BRANCHES,
default=list
)
tentative_no_of_offers = models.IntegerField(blank=False, default=1)
tentative_no_of_offers = models.IntegerField(blank=False, default=None, null=True)
other_requirements = models.CharField(blank=True, max_length=200, default="")
additional_info = ArrayField(models.CharField(blank=True, max_length=200), size=15, default=list, blank=True)
email_verified = models.BooleanField(blank=False, default=False)
@ -96,6 +99,9 @@ class Placement(models.Model):
return super(Placement, self).save(*args, **kwargs)
def __str__(self):
return self.company_name + " - " + self.id
class PlacementApplication(models.Model):
id = models.CharField(blank=False, primary_key=True, max_length=15)
placement = models.ForeignKey(Placement, blank=False, on_delete=models.RESTRICT, default=None, null=True)
@ -116,6 +122,9 @@ class PlacementApplication(models.Model):
verbose_name_plural = "Placement Applications"
unique_together = ('placement_id', 'student_id')
def __str__(self):
return self.placement.company_name + " - " + self.student.name
class PrePlacementOffer(models.Model):
id = models.AutoField(primary_key=True)

View File

@ -154,8 +154,11 @@ class PlacementApplicationSerializer(serializers.ModelSerializer):
return data
def get_resume_link(self, obj):
link = LINK_TO_STORAGE_RESUME + urllib.parse.quote_plus(obj.id + "/" + obj.resume)
return link
ele = {}
ele['link'] = LINK_TO_STORAGE_RESUME + urllib.parse.quote_plus(obj.id + "/" + obj.resume)
ele['name'] = obj.resume
return ele
class Meta:
model = PlacementApplication

View File

@ -44,7 +44,7 @@ def addResume(request, id, email, user_type):
files = request.FILES
file = files['file']
destination_path = STORAGE_DESTINATION_RESUMES + id + "/"
destination_path = STORAGE_DESTINATION_RESUMES + str(student.roll_no) + "/"
file_name = saveFile(file, destination_path)
student.resumes.append(file_name)

View File

@ -1,6 +1,7 @@
import logging
import os
import random
import re
import string
import sys
from os import path, remove
@ -113,8 +114,10 @@ def saveFile(file, location):
prefix = generateRandomString()
file_name = prefix + "_" + file.name
file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name)
if not path.isdir(location):
os.mkdir(location)
os.makedirs(location)
destination_path = location + str(file_name)
if path.exists(destination_path):
@ -123,7 +126,6 @@ def saveFile(file, location):
with open(destination_path, 'wb+') as destination:
for chunk in file.chunks():
destination.write(chunk)
return file_name

View File

@ -83,23 +83,23 @@ WSGI_APPLICATION = 'CDC_Backend.wsgi.application'
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ.get("DB_NAME"),
'USER': os.environ.get("DB_USER"),
'PASSWORD': os.environ.get("DB_PASSWORD"),
'HOST': os.environ.get("DB_HOST"),
'PORT': os.environ.get("DB_PORT"),
},
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'd84i5cbjig5rrf',
# 'USER': 'hbkullcdjbxuwh',
# 'PASSWORD': '45d990da00e2cc96d7d4e2e5e308d4b07a387883f70c40e090a6252175cb634e',
# 'HOST': 'ec2-54-163-97-228.compute-1.amazonaws.com',
# 'PORT': '5432',
# }
# 'NAME': os.environ.get("DB_NAME"),
# 'USER': os.environ.get("DB_USER"),
# 'PASSWORD': os.environ.get("DB_PASSWORD"),
# 'HOST': os.environ.get("DB_HOST"),
# 'PORT': os.environ.get("DB_PORT"),
# },
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'd84i5cbjig5rrf',
'USER': 'hbkullcdjbxuwh',
'PASSWORD': '45d990da00e2cc96d7d4e2e5e308d4b07a387883f70c40e090a6252175cb634e',
'HOST': 'ec2-54-163-97-228.compute-1.amazonaws.com',
'PORT': '5432',
}
}
# Password validation