Constants Update

This commit is contained in:
gowtham3105 2021-10-22 20:37:15 +05:30
parent 94c0cf018f
commit 8b22171327
4 changed files with 79 additions and 75 deletions

View File

@ -10,10 +10,10 @@ logger = logging.getLogger('db')
@api_view(['POST']) @api_view(['POST'])
@precheck([OPENING_DESIGNATION, OPENING_DESCRIPTION, OPENING_TYPE, OPENING_CITY, OPENING_CITY_TYPE, @precheck([DESIGNATION, DESCRIPTION, OPENING_TYPE, CITY, CITY_TYPE,
OPENING_COMPENSATION, OPENING_COMPENSATION_DETAILS, OPENING_ALLOWED_BATCH, OPENING_ALLOWED_BRANCH, COMPENSATION, COMPENSATION_DETAILS, ALLOWED_BATCH, ALLOWED_BRANCH,
OPENING_ROUNDS, OPENING_CO_OP, OPENING_START_DATE, OPENING_ADDITIONAL_INFO, ROUNDS, CO_OP, START_DATE, ADDITIONAL_INFO,
OPENING_DURATION, OPENING_ROUND_DETAILS]) DURATION, ROUND_DETAILS])
def addOpening(request): def addOpening(request):
try: try:
data = request.data data = request.data
@ -28,61 +28,61 @@ def addOpening(request):
# Some new code above # Some new code above
if data[OPENING_DESIGNATION] != "": if data[DESIGNATION] != "":
opening.designation = data[OPENING_DESIGNATION] opening.designation = data[DESIGNATION]
else: else:
raise ValueError(OPENING_DESIGNATION + " Not Found") raise ValueError(DESIGNATION + " Not Found")
opening.description = data[OPENING_DESCRIPTION] opening.description = data[DESCRIPTION]
if data[OPENING_START_DATE] != "": if data[START_DATE] != "":
opening.description = data[OPENING_START_DATE] opening.description = data[START_DATE]
else: else:
raise ValueError(OPENING_START_DATE + " Not Found") raise ValueError(START_DATE + " Not Found")
if data[OPENING_START_DATE] != "": if data[START_DATE] != "":
opening.start_date = datetime.strptime(data[OPENING_START_DATE], '%d-%m-%Y') opening.start_date = datetime.strptime(data[START_DATE], '%d-%m-%Y')
else: else:
raise ValueError(OPENING_START_DATE + " Not Found") raise ValueError(START_DATE + " Not Found")
if data[OPENING_CITY] != "": if data[CITY] != "":
opening.city = data[OPENING_CITY] opening.city = data[CITY]
else: else:
raise ValueError(OPENING_CITY + " Not Found") raise ValueError(CITY + " Not Found")
if data[OPENING_CITY_TYPE] != "": if data[CITY_TYPE] != "":
opening.city_type = data[OPENING_CITY_TYPE] opening.city_type = data[CITY_TYPE]
else: else:
raise ValueError(OPENING_CITY_TYPE + " Not Found") raise ValueError(CITY_TYPE + " Not Found")
if data[OPENING_COMPENSATION] != "": if data[COMPENSATION] != "":
opening.compensation = data[OPENING_COMPENSATION] opening.compensation = data[COMPENSATION]
else: else:
raise ValueError(OPENING_COMPENSATION + " Not Found") raise ValueError(COMPENSATION + " Not Found")
opening.compensation_details = data[OPENING_COMPENSATION_DETAILS] opening.compensation_details = data[COMPENSATION_DETAILS]
if data[OPENING_ALLOWED_BATCH] != "": if data[ALLOWED_BATCH] != "":
if set(json.loads(data[OPENING_ALLOWED_BATCH])).issubset(BATCHES): if set(json.loads(data[ALLOWED_BATCH])).issubset(BATCHES):
opening.allowed_batch = json.loads(data[OPENING_ALLOWED_BATCH]) opening.allowed_batch = json.loads(data[ALLOWED_BATCH])
else: else:
raise ValueError(OPENING_ALLOWED_BATCH + " is Invalid") raise ValueError(ALLOWED_BATCH + " is Invalid")
else: else:
raise ValueError(OPENING_ALLOWED_BATCH + " Not Found") raise ValueError(ALLOWED_BATCH + " Not Found")
if data[OPENING_ALLOWED_BRANCH] != "": if data[ALLOWED_BRANCH] != "":
if set(json.loads(data[OPENING_ALLOWED_BRANCH])).issubset(BRANCHES): if set(json.loads(data[ALLOWED_BRANCH])).issubset(BRANCHES):
opening.allowed_branch = json.loads(data[OPENING_ALLOWED_BRANCH]) opening.allowed_branch = json.loads(data[ALLOWED_BRANCH])
else: else:
raise ValueError(OPENING_ALLOWED_BATCH + " is Invalid") raise ValueError(ALLOWED_BATCH + " is Invalid")
else: else:
raise ValueError(OPENING_ALLOWED_BRANCH + " Not Found") raise ValueError(ALLOWED_BRANCH + " Not Found")
opening.rounds = json.loads(data[OPENING_ROUNDS]) opening.rounds = json.loads(data[ROUNDS])
opening.additional_info = json.loads(data[OPENING_ADDITIONAL_INFO]) opening.additional_info = json.loads(data[ADDITIONAL_INFO])
opening.status = STATUS_ACCEPTING_APPLICATIONS opening.status = STATUS_ACCEPTING_APPLICATIONS
opening.rounds_details = json.loads(data[OPENING_ROUND_DETAILS]) opening.rounds_details = json.loads(data[ROUND_DETAILS])
opening.created_at = make_aware(datetime.now()) opening.created_at = make_aware(datetime.now())
files = request.FILES.getlist(OPENING_ATTACHMENTS) files = request.FILES.getlist(ATTACHMENTS)
attachments = [] attachments = []
for file in files: for file in files:
attachments.append(saveFile(file, STORAGE_DESTINATION_COMPANY_ATTACHMENTS)) attachments.append(saveFile(file, STORAGE_DESTINATION_COMPANY_ATTACHMENTS))

View File

@ -38,15 +38,16 @@ EMAIL = "email"
STUDENT = 'student' STUDENT = 'student'
ADMIN = 'Admin' ADMIN = 'Admin'
COMPANY = '' COMPANY = ''
STORAGE_DESTINATION = "./Storage/Resumes/" STORAGE_DESTINATION = "./Storage/Resumes/"
STORAGE_DESTINATION_COMPANY_ATTACHMENTS = './Storage/Company_Attachments/' STORAGE_DESTINATION_COMPANY_ATTACHMENTS = './Storage/Company_Attachments/'
RESUME_FILE_NAME = 'resume_file_name' RESUME_FILE_NAME = 'resume_file_name'
APPLICATION_ID = "application_id" APPLICATION_ID = "application_id"
APPLICATION_OPENING_TYPE = "opening_type" OPENING_ID = "opening_id"
APPLICATION_OPENING_ID = "opening_id" STUDENT_ID = "student_id"
APPLICATION_ADDITIONAL_INFO = "additional_info" ADDITIONAL_INFO = "additional_info"
STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications" STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications"
@ -54,25 +55,27 @@ PLACEMENT = "Placement"
COMPANY_WEBSITE = 'website' COMPANY_WEBSITE = 'website'
COMPANY_ADDRESS = 'address' COMPANY_ADDRESS = 'address'
COMPANY_PHONE_NUMBER = 'phone_number' PHONE_NUMBER = 'phone_number'
COMPANY_CONTACT_PERSON_NAME = 'contact_person_name' CONTACT_PERSON_NAME = 'contact_person_name'
OPENING_DESIGNATION = 'designation' DESIGNATION = 'designation'
OPENING_DESCRIPTION = 'description' DESCRIPTION = 'description'
OPENING_TYPE = 'opening_type' OPENING_TYPE = 'opening_type'
OPENING_CITY = 'city' CITY = 'city'
OPENING_CITY_TYPE = 'city_type' CITY_TYPE = 'city_type'
OPENING_COMPENSATION = 'compensation' COMPENSATION = 'compensation'
OPENING_COMPENSATION_DETAILS = 'compensation_details' COMPENSATION_DETAILS = 'compensation_details'
OPENING_ALLOWED_BATCH = 'allowed_batch' ALLOWED_BATCH = 'allowed_batch'
OPENING_ALLOWED_BRANCH = 'allowed_branch' ALLOWED_BRANCH = 'allowed_branch'
OPENING_ATTACHMENTS = 'attachments' ATTACHMENTS = 'attachments'
OPENING_ROUNDS = 'rounds' ROUNDS = 'rounds'
OPENING_ADDITIONAL_INFO = 'additional_info' ROUND_DETAILS = 'round_details'
OPENING_ROUND_DETAILS = 'round_details' DURATION = 'duration'
OPENING_DURATION = 'duration' CO_OP = 'co_op'
OPENING_CO_OP = 'co_op' START_DATE = "start_date"
OPENING_START_DATE = 'start_date'
STUDENT_LIST = "student_list"
STUDENT_STATUS = "student_status"
BRANCHES = [ BRANCHES = [
"CSE", "CSE",

View File

@ -28,12 +28,12 @@ class Admin(models.Model):
class Placement(models.Model): class Placement(models.Model):
id = models.CharField(blank=False, primary_key=True, max_length=15) id = models.CharField(blank=False, primary_key=True, max_length=15)
name = models.CharField(blank=False, max_length=50) name = models.CharField(blank=False, max_length=50, default="")
address = models.CharField(blank=False, max_length=150) address = models.CharField(blank=False, max_length=150, default="")
companyType = models.CharField(blank=False, max_length=50) companyType = models.CharField(blank=False, max_length=50, default="")
website = models.CharField(blank=True, max_length=50) website = models.CharField(blank=True, max_length=50, default="")
contact_person_name = models.CharField(blank=False, max_length=50) contact_person_name = models.CharField(blank=False, max_length=50, default="")
phone_number = models.PositiveBigIntegerField(blank=False) phone_number = models.PositiveBigIntegerField(blank=False, default=0)
designation = models.CharField(blank=False, max_length=25, default=None, null=True) designation = models.CharField(blank=False, max_length=25, default=None, null=True)
description = models.CharField(blank=False, max_length=200) description = models.CharField(blank=False, max_length=200)
start_date = models.DateField(blank=False, verbose_name="Start Date") start_date = models.DateField(blank=False, verbose_name="Start Date")
@ -90,12 +90,13 @@ class PlacementApplication(models.Model):
class Meta: class Meta:
verbose_name_plural = "Placement Applications" verbose_name_plural = "Placement Applications"
unique_together = ('placement_id', 'student_id')
class PrePlacementOffer(models.Model): class PrePlacementOffer(models.Model):
id = models.AutoField(primary_key=True) id = models.AutoField(primary_key=True)
student = models.ForeignKey(Student, on_delete=models.CASCADE, blank=False) student = models.ForeignKey(Student, on_delete=models.CASCADE, blank=False)
company = models.CharField(max_length=50, blank=False) company = models.CharField(max_length=50, blank=False, default="")
compensation = models.IntegerField(blank=False) # Job - Per Year compensation = models.IntegerField(blank=False) # Job - Per Year
compensation_details = models.CharField(blank=True, max_length=200) compensation_details = models.CharField(blank=True, max_length=200)
tier = models.CharField(blank=False, choices=TIERS, max_length=10) tier = models.CharField(blank=False, choices=TIERS, max_length=10)

View File

@ -132,18 +132,18 @@ def deleteResume(request, id, email, user_type):
@api_view(['POST']) @api_view(['POST'])
@isAuthorized(allowed_users=[STUDENT]) @isAuthorized(allowed_users=[STUDENT])
@precheck(required_data=[APPLICATION_OPENING_TYPE, APPLICATION_OPENING_ID, RESUME_FILE_NAME, @precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME,
APPLICATION_ADDITIONAL_INFO]) ADDITIONAL_INFO])
def submitApplication(request, id, email, user_type): def submitApplication(request, id, email, user_type):
try: try:
data = request.data data = request.data
student = get_object_or_404(Student, id=id) student = get_object_or_404(Student, id=id)
if data[APPLICATION_OPENING_TYPE] == PLACEMENT: if data[OPENING_TYPE] == PLACEMENT:
if not len(PlacementApplication.objects.filter( if not len(PlacementApplication.objects.filter(
student_id=id, placement_id=data[APPLICATION_OPENING_ID])): student_id=id, placement_id=data[OPENING_ID])):
application = PlacementApplication() application = PlacementApplication()
opening = get_object_or_404(Placement, id=data[APPLICATION_OPENING_ID], opening = get_object_or_404(Placement, id=data[OPENING_ID],
status=STATUS_ACCEPTING_APPLICATIONS) status=STATUS_ACCEPTING_APPLICATIONS)
cond_stat, cond_msg = PlacementApplicationConditions(student, opening) cond_stat, cond_msg = PlacementApplicationConditions(student, opening)
print(cond_stat, cond_msg) print(cond_stat, cond_msg)
@ -153,7 +153,7 @@ def submitApplication(request, id, email, user_type):
else: else:
raise PermissionError("Application is already Submitted") raise PermissionError("Application is already Submitted")
else: else:
raise ValueError(APPLICATION_OPENING_TYPE + " is Invalid") raise ValueError(OPENING_TYPE + " is Invalid")
if data[RESUME_FILE_NAME] in student.resumes: if data[RESUME_FILE_NAME] in student.resumes:
application.resume = data[RESUME_FILE_NAME] application.resume = data[RESUME_FILE_NAME]
@ -163,13 +163,13 @@ def submitApplication(request, id, email, user_type):
application.student = student application.student = student
application.id = generateRandomString() application.id = generateRandomString()
for i in opening.additional_info: for i in opening.additional_info:
if i not in data[APPLICATION_ADDITIONAL_INFO]: if i not in data[ADDITIONAL_INFO]:
print(i) print(i)
raise AttributeError(i + " not found in Additional Info") raise AttributeError(i + " not found in Additional Info")
application.additional_info = data[APPLICATION_ADDITIONAL_INFO] application.additional_info = data[ADDITIONAL_INFO]
if not sendApplicationEmail(email, student.name, opening.company.name, data[APPLICATION_OPENING_TYPE], if not sendApplicationEmail(email, student.name, opening.company.name, data[OPENING_TYPE],
data[APPLICATION_ADDITIONAL_INFO]): data[ADDITIONAL_INFO]):
logger.error("Submit Application: Unable to Send Email") logger.error("Submit Application: Unable to Send Email")
# raise RuntimeError("Unable to Send Email") # raise RuntimeError("Unable to Send Email")