cdc-placement-website-backend/CDC_Backend/APIs/companyViews.py

638 lines
29 KiB
Python
Raw Permalink Normal View History

2021-10-15 20:47:23 +05:30
from rest_framework.decorators import api_view
from .utils import *
2023-06-02 22:44:07 +05:30
from .serializers import *
2021-10-15 20:47:23 +05:30
logger = logging.getLogger('db')
@api_view(['POST'])
2024-07-19 11:56:33 +05:30
@precheck([COMPANY_NAME, ADDRESS, COMPANY_TYPE, NATURE_OF_BUSINESS, TYPE_OF_ORGANISATION, WEBSITE, COMPANY_DETAILS,
IS_COMPANY_DETAILS_PDF, CONTACT_PERSON_NAME, PHONE_NUMBER, EMAIL, CITY, STATE, COUNTRY, PINCODE, DESIGNATION,
DESCRIPTION,
IS_DESCRIPTION_PDF, COMPENSATION_CTC, COMPENSATION_GROSS, COMPENSATION_TAKE_HOME, COMPENSATION_BONUS,
IS_COMPENSATION_DETAILS_PDF, ALLOWED_BRANCH, ELIGIBLESTUDENTS, SELECTION_PROCEDURE_ROUNDS,
SELECTION_PROCEDURE_DETAILS,
IS_SELECTION_PROCEDURE_DETAILS_PDF, TENTATIVE_DATE_OF_JOINING, TENTATIVE_NO_OF_OFFERS, OTHER_REQUIREMENTS,
2024-07-24 23:27:27 +05:30
RECAPTCHA_VALUE, JOB_LOCATION,PSYCHOMETRIC_TEST,MEDICAL_TEST,NUMBER_OF_EMPLOYEES,BACKLOG_ELIGIBLE,PWD_ELIGIBLE,CPI,EXPECTED_NO_OF_OFFERS])
2024-06-21 00:15:00 +05:30
def addPlacement(request):
2023-11-09 18:26:06 +05:30
logger.info("JNF filled by " + str(request.data['email']))
2023-11-11 03:35:29 +05:30
logger.info(request.data)
2021-10-15 20:47:23 +05:30
try:
data = request.data
files = request.FILES
opening = Placement()
2022-04-10 23:12:02 +05:30
if not verify_recaptcha(data[RECAPTCHA_VALUE]):
raise Exception("Recaptcha Failed")
2022-05-01 14:56:46 +05:30
2021-10-15 20:47:23 +05:30
opening.id = generateRandomString()
# Add a company details in the opening
opening.company_name = data[COMPANY_NAME]
opening.address = data[ADDRESS]
opening.company_type = data[COMPANY_TYPE]
opening.nature_of_business = data[NATURE_OF_BUSINESS]
opening.type_of_organisation = data[TYPE_OF_ORGANISATION]
opening.website = data[WEBSITE]
opening.company_details = data[COMPANY_DETAILS]
opening.is_company_details_pdf = data[IS_COMPANY_DETAILS_PDF]
2024-06-21 00:15:00 +05:30
# if data[RS_ELIGIBLE] == 'Yes':
# opening.rs_eligible = True
# else:
# opening.rs_eligible = False
2024-07-21 21:53:34 +05:30
2024-07-19 11:56:33 +05:30
if data[ELIGIBLESTUDENTS] is None:
raise ValueError('Eligible Students cannot be empty')
elif set(json.loads(data[ELIGIBLESTUDENTS])).issubset(ELIGIBLE):
opening.eligiblestudents = json.loads(data[ELIGIBLESTUDENTS])
else:
raise ValueError('Allowed Branch must be a subset of ' + str(ELIGIBLE))
2024-06-21 00:15:00 +05:30
if data[PWD_ELIGIBLE] == 'Yes':
opening.pwd_eligible = True
else:
2024-06-21 00:15:00 +05:30
opening.pwd_eligible = False
if data[BACKLOG_ELIGIBLE] == 'Yes':
opening.backlog_eligible = True
else:
opening.backlog_eligible = False
if data[PSYCHOMETRIC_TEST] == 'Yes':
opening.psychometric_test = True
else:
opening.psychometric_test = False
if data[MEDICAL_TEST] == 'Yes':
opening.medical_test = True
else:
opening.medical_test = False
2024-06-21 00:15:00 +05:30
opening.cpi_eligible = data[CPI]
if opening.is_company_details_pdf:
company_details_pdf = []
for file in files.getlist(COMPANY_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + opening.id + '/'
company_details_pdf.append(saveFile(file, file_location))
opening.company_details_pdf_names = company_details_pdf
2022-05-01 14:56:46 +05:30
if data[IS_COMPANY_DETAILS_PDF] == "true" and len(opening.company_details_pdf_names) > 0:
opening.is_company_details_pdf = True
elif data[IS_COMPANY_DETAILS_PDF] == "false" and len(opening.company_details_pdf_names) == 0:
opening.is_company_details_pdf = False
else:
raise ValueError('Invalid value for is_company_details_pdf')
# Add a contact person details in the opening
opening.contact_person_name = data[CONTACT_PERSON_NAME]
# Check if Phone number is Integer
2024-08-04 17:25:53 +05:30
opening.phone_number = data[PHONE_NUMBER]
opening.email = data[EMAIL]
2021-10-15 20:47:23 +05:30
# Add a company location in the opening
opening.city = data[CITY]
opening.state = data[STATE]
opening.country = data[COUNTRY]
2021-10-15 20:47:23 +05:30
# Check if Pincode is Integer
if data[PINCODE].isdigit():
opening.pin_code = int(data[PINCODE])
2021-10-15 20:47:23 +05:30
else:
raise ValueError('Pincode should be integer')
2021-10-15 20:47:23 +05:30
# If India then set city_type as Domestic else International
if opening.country.upper() == 'INDIA':
opening.city_type = 'Domestic'
else:
opening.city_type = 'International'
# Add a designation details in the opening
opening.designation = data[DESIGNATION]
2021-10-22 20:37:15 +05:30
opening.description = data[DESCRIPTION]
opening.job_location = data[JOB_LOCATION]
opening.is_description_pdf = data[IS_DESCRIPTION_PDF]
2021-10-15 20:47:23 +05:30
if opening.is_description_pdf:
description_pdf = []
for file in files.getlist(DESCRIPTION_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + opening.id + '/'
description_pdf.append(saveFile(file, file_location))
opening.description_pdf_names = description_pdf
2022-05-01 14:56:46 +05:30
# Check if is_description_pdf is boolean
if data[IS_DESCRIPTION_PDF] == "true" and len(opening.description_pdf_names) > 0:
opening.is_description_pdf = True
elif data[IS_DESCRIPTION_PDF] == "false" and len(opening.description_pdf_names) == 0:
opening.is_description_pdf = False
else:
raise ValueError('Invalid value for is_description_pdf')
# Add a compensation details in the opening
# Check if compensation_ctc is integer
if data[COMPENSATION_CTC].isdigit():
opening.compensation_CTC = int(data[COMPENSATION_CTC])
elif data[COMPENSATION_CTC] is None:
opening.compensation_CTC = None
2021-10-15 20:47:23 +05:30
else:
raise ValueError('Compensation CTC must be an integer')
2024-06-21 00:15:00 +05:30
# Newly added
2024-07-24 23:27:27 +05:30
2024-06-21 00:15:00 +05:30
if data[COMPANY_TURNOVER].isdigit():
opening.company_turnover = int(data[COMPANY_TURNOVER])
2024-07-24 23:27:27 +05:30
elif data[COMPANY_TURNOVER] is None or data[COMPANY_TURNOVER] == '':
2024-06-21 00:15:00 +05:30
opening.company_turnover = None
else:
2024-07-24 23:27:27 +05:30
# Handle the case where the data is not a valid number or None/empty
# You can raise an error, set a default value, or log a warning
opening.company_turnover = None # Or some default value or error handling
# Check if compensation_gross is integer
if data[COMPENSATION_GROSS].isdigit():
opening.compensation_gross = int(data[COMPENSATION_GROSS])
elif data[COMPENSATION_GROSS] is None:
opening.compensation_gross = None
2021-10-15 20:47:23 +05:30
else:
raise ValueError('Compensation Gross must be an integer')
# Check if compensation_take_home is integer
if data[COMPENSATION_TAKE_HOME].isdigit():
opening.compensation_take_home = int(data[COMPENSATION_TAKE_HOME])
elif data[COMPENSATION_TAKE_HOME] is None:
opening.compensation_take_home = None
2021-10-15 20:47:23 +05:30
else:
raise ValueError('Compensation Take Home must be an integer')
# Check if compensation_bonus is integer
if data[COMPENSATION_BONUS].isdigit():
opening.compensation_bonus = int(data[COMPENSATION_BONUS])
elif data[COMPENSATION_BONUS] is None:
opening.compensation_bonus = None
2021-10-15 20:47:23 +05:30
else:
raise ValueError('Compensation Bonus must be an integer')
2021-10-15 20:47:23 +05:30
opening.is_compensation_details_pdf = data[IS_COMPENSATION_DETAILS_PDF]
if opening.is_compensation_details_pdf:
compensation_details_pdf = []
for file in files.getlist(COMPENSATION_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + opening.id + '/'
compensation_details_pdf.append(saveFile(file, file_location))
opening.compensation_details_pdf_names = compensation_details_pdf
2021-10-15 20:47:23 +05:30
2022-05-01 14:56:46 +05:30
# Check if is_compensation_details_pdf is boolean
if data[IS_COMPENSATION_DETAILS_PDF] == "true" and len(opening.compensation_details_pdf_names) > 0:
opening.is_compensation_details_pdf = True
elif data[IS_COMPENSATION_DETAILS_PDF] == "false" and len(opening.compensation_details_pdf_names) == 0:
opening.is_compensation_details_pdf = False
else:
raise ValueError('Invalid value for is_compensation_details_pdf')
opening.bond_details = data[BOND_DETAILS]
# Check if selection_procedure_rounds is list
if data[SELECTION_PROCEDURE_ROUNDS] is None:
raise ValueError('Selection Procedure Rounds cannot be empty')
2021-10-15 20:47:23 +05:30
else:
try:
opening.selection_procedure_rounds = json.loads(data[SELECTION_PROCEDURE_ROUNDS])
except:
raise ValueError('Selection Procedure Rounds must be a list')
opening.selection_procedure_details = data[SELECTION_PROCEDURE_DETAILS]
opening.is_selection_procedure_details_pdf = data[IS_SELECTION_PROCEDURE_DETAILS_PDF]
2021-10-15 20:47:23 +05:30
2023-07-25 00:34:39 +05:30
if opening.is_selection_procedure_details_pdf == "true":
selection_procedure_details_pdf = []
for file in files.getlist(SELECTION_PROCEDURE_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + opening.id + '/'
selection_procedure_details_pdf.append(saveFile(file, file_location))
2021-10-15 20:47:23 +05:30
opening.selection_procedure_details_pdf_names = selection_procedure_details_pdf
2021-10-15 20:47:23 +05:30
2022-05-01 14:56:46 +05:30
# Check if is_selection_procedure_details_pdf is boolean
if data[IS_SELECTION_PROCEDURE_DETAILS_PDF] == "true" and len(
opening.selection_procedure_details_pdf_names) > 0:
opening.is_selection_procedure_details_pdf = True
elif data[IS_SELECTION_PROCEDURE_DETAILS_PDF] == "false" and len(
opening.selection_procedure_details_pdf_names) == 0:
opening.is_selection_procedure_details_pdf = False
else:
raise ValueError('Invalid value for is_selection_procedure_pdf')
stat, tier = getTier(opening.compensation_gross)
if stat:
opening.tier = tier
else:
raise ValueError('Invalid compensation gross')
# Convert to date object
2021-12-17 19:23:32 +05:30
opening.tentative_date_of_joining = datetime.datetime.strptime(data[TENTATIVE_DATE_OF_JOINING],
'%d-%m-%Y').date()
2024-07-25 12:25:49 +05:30
establishment_date_str = data.get('ESTABLISHMENT_DATE', '')
if establishment_date_str:
try:
opening.establishment_date = datetime.datetime.strptime(establishment_date_str, '%d-%m-%Y').date()
except ValueError:
opening.establishment_date = None
else:
opening.establishment_date = None
# Only Allowing Fourth Year for Placement
2023-06-11 00:06:36 +05:30
opening.allowed_batch = [FOURTH_YEAR,]
# Check if allowed_branch are valid
if data[ALLOWED_BRANCH] is None:
raise ValueError('Allowed Branch cannot be empty')
elif set(json.loads(data[ALLOWED_BRANCH])).issubset(BRANCHES):
opening.allowed_branch = json.loads(data[ALLOWED_BRANCH])
else:
raise ValueError('Allowed Branch must be a subset of ' + str(BRANCHES))
2021-10-15 20:47:23 +05:30
# 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])
2021-12-16 23:05:04 +05:30
elif data[TENTATIVE_NO_OF_OFFERS] == 'null':
opening.tentative_no_of_offers = None
else:
raise ValueError('Tentative No Of Offers must be an integer')
2024-06-21 00:15:00 +05:30
# newly added
if data[EXPECTED_NO_OF_OFFERS].isdigit():
opening.expected_no_of_offers = int(data[EXPECTED_NO_OF_OFFERS])
elif data[EXPECTED_NO_OF_OFFERS] == 'null':
opening.expected_no_of_offers = None
opening.other_requirements = data[OTHER_REQUIREMENTS]
2024-06-21 00:15:00 +05:30
# newly added
if data[NUMBER_OF_EMPLOYEES].isdigit():
opening.number_of_employees = int(data[NUMBER_OF_EMPLOYEES])
elif data[NUMBER_OF_EMPLOYEES] == 'null':
opening.number_of_employees = None
2021-10-15 20:47:23 +05:30
opening.save()
2021-12-17 17:15:56 +05:30
stat, link = generateOneTimeVerificationLink(opening.email, opening.id, "Placement")
if not stat:
raise RuntimeError("Error in generating one time verification link for placement")
2021-10-15 20:47:23 +05:30
data = {
"designation": opening.designation,
"one_time_link": link,
"opening_type": "Job"
2021-10-15 20:47:23 +05:30
}
2021-12-17 17:15:56 +05:30
sendEmail(opening.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data,
COMPANY_EMAIL_VERIFICATION_TEMPLATE)
2021-10-15 20:47:23 +05:30
return Response({'action': "Add Placement", 'message': "Placement Added Successfully"},
2021-10-15 20:47:23 +05:30
status=status.HTTP_200_OK)
except ValueError as e:
store_all_files(request)
logger.warning("ValueError in addPlacement: " + str(e))
logger.warning(traceback.format_exc())
return Response({'action': "Add Placement", 'message': str(e)},
2021-10-15 20:47:23 +05:30
status=status.HTTP_400_BAD_REQUEST)
2024-07-19 11:56:33 +05:30
except Exception as e:
store_all_files(request)
2024-07-19 11:56:33 +05:30
logger.warning("Add New Placement: " + str(e))
logger.warning(traceback.format_exc())
2024-07-19 11:56:33 +05:30
return Response({'action': "Add Placement", 'message': "Something went wrong: " + str(e)},
2021-10-15 20:47:23 +05:30
status=status.HTTP_400_BAD_REQUEST)
2021-12-17 17:15:56 +05:30
2021-12-17 19:23:32 +05:30
2024-07-19 11:56:33 +05:30
2021-12-17 17:15:56 +05:30
@api_view(['POST'])
@precheck([TOKEN])
def verifyEmail(request):
try:
data = request.data
send_email_to_company = None
2021-12-17 17:15:56 +05:30
token = data[TOKEN]
# decode token
decoded_token = jwt.decode(token, os.environ.get("EMAIL_VERIFICATION_SECRET_KEY"), algorithms=['HS256'])
# get email, opening_id, opening_type from token
email = decoded_token['email']
opening_id = decoded_token['opening_id']
opening_type = decoded_token['opening_type']
# get opening based on opening_type and opening_id
if opening_type == PLACEMENT:
opening = get_object_or_404(Placement, id=opening_id)
if email != opening.email:
raise ValueError("Invalid Email")
if not opening.email_verified:
opening.email_verified = True
send_email_to_company = True
else:
send_email_to_company = False
2021-12-17 17:15:56 +05:30
opening.save()
2023-07-25 00:34:39 +05:30
elif opening_type == INTERNSHIP:
opening = get_object_or_404(Internship, id=opening_id)
if email != opening.email:
raise ValueError("Invalid Email")
if not opening.email_verified:
opening.email_verified = True
send_email_to_company = True
else:
send_email_to_company = False
opening.save()
else:
raise ValueError('Invalid opening type')
if send_email_to_company:
# Email sending part.
2023-07-29 17:39:34 +05:30
send_email_for_opening(opening)
2021-12-17 17:15:56 +05:30
return Response({'action': "Verify Email", 'message': "Email Verified Successfully"},
status=status.HTTP_200_OK)
except Http404:
return Response({'action': "Verify Email", 'message': "Opening Not Found"},
status=status.HTTP_404_NOT_FOUND)
except ValueError as e:
return Response({'action': "Verify Email", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST)
except:
logger.warning("Verify Email: " + str(sys.exc_info()))
2023-10-11 07:18:28 +05:30
return Response({'action': "Verify Email", 'message': "Something went wrong"},
2022-05-01 14:56:46 +05:30
status=status.HTTP_400_BAD_REQUEST)
2023-06-02 22:44:07 +05:30
@api_view(['GET'])
@precheck([PLACEMENT_ID])
def autoFillJnf(request):
try:
data = request.GET
placement_id = data.get(PLACEMENT_ID)
opening = get_object_or_404(Placement, id=placement_id)
serializer = AutofillSerializers(opening)
return Response({'action': "Get AutoFill", 'message': 'Data Found', 'placement_data': serializer.data},
status=status.HTTP_200_OK)
except Http404:
return Response({'action': "Get AutoFill", 'message': 'Placement Not Found'},
status=status.HTTP_404_NOT_FOUND)
except Exception as e:
traceback_str = traceback.format_exc()
logger.warning("Get AutoFill: " + traceback_str)
return Response({'action': "Get AutoFill", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)
2023-07-24 19:00:52 +05:30
@api_view(['GET'])
2023-10-09 01:25:25 +05:30
@precheck([INTERNSHIP_ID])
def autoFillInf(request):
try:
data = request.GET
internship_id = data.get(INTERNSHIP_ID)
opening = get_object_or_404(Internship, id=internship_id)
serializer = AutofillSerializersInternship(opening)
return Response({'action': "Get AutoFill ", 'message': 'Data Found', 'internship_data': serializer.data},
status=status.HTTP_200_OK)
except Http404:
return Response({'action': "Get AutoFill", 'message': 'Internship Not Found'},
status=status.HTTP_404_NOT_FOUND)
except Exception as e:
traceback_str = traceback.format_exc()
logger.warning("Get AutoFill: " + traceback_str)
return Response({'action': "Get AutoFill", 'message': "Something went wrong"},
status=status.HTTP_400_BAD_REQUEST)
2023-07-24 19:00:52 +05:30
## Internships ##
@api_view(['POST'])
2024-07-19 11:56:33 +05:30
@precheck([COMPANY_NAME, WEBSITE, IS_COMPANY_DETAILS_PDF, COMPANY_DETAILS, ADDRESS,
CITY, STATE, COUNTRY, PINCODE, COMPANY_TYPE, NATURE_OF_BUSINESS, IS_DESCRIPTION_PDF,
DESIGNATION, INTERNSHIP_LOCATION, DESCRIPTION, SEASON, START_DATE, END_DATE, WORK_TYPE,
ALLOWED_BRANCH, ELIGIBLESTUDENTS, NUM_OFFERS, IS_STIPEND_DETAILS_PDF, STIPEND,
FACILITIES, OTHER_FACILITIES, SELECTION_PROCEDURE_ROUNDS, SELECTION_PROCEDURE_DETAILS, IS_SELECTION_PROCEDURE_DETAILS_PDF,
SELECTION_PROCEDURE_DETAILS, OTHER_REQUIREMENTS,
CONTACT_PERSON_NAME, PHONE_NUMBER, EMAIL, RECAPTCHA_VALUE ,ESTABLISHMENT_DATE,PWD_ELIGIBLE,BACKLOG_ELIGIBLE,PSYCHOMETRIC_TEST,MEDICAL_TEST,CPI,EXPECTED_NO_OF_OFFERS,NUMBER_OF_EMPLOYEES,COMPANY_TURNOVER])
2023-07-24 19:00:52 +05:30
def addInternship(request):
2023-07-25 00:34:39 +05:30
logger.info("INF filled by " + str(request.data['email']))
2023-11-11 03:35:29 +05:30
logger.info(request.data)
2023-07-25 00:34:39 +05:30
try:
data = request.data
files = request.FILES
internship = Internship()
if not verify_recaptcha(data[RECAPTCHA_VALUE]):
raise Exception("Recaptcha Failed")
internship.id = generateRandomString()
# Add a company details in the internship
internship.company_name = data[COMPANY_NAME]
internship.website = data[WEBSITE]
if data[IS_COMPANY_DETAILS_PDF] == "true":
internship.is_company_details_pdf = True
else:
internship.is_company_details_pdf = False
if internship.is_company_details_pdf:
company_details_pdf = []
for file in files.getlist(COMPANY_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + internship.id + '/'
company_details_pdf.append(saveFile(file, file_location))
internship.company_details_pdf_names = company_details_pdf
internship.company_details = data[COMPANY_DETAILS]
internship.address = data[ADDRESS]
internship.city = data[CITY]
internship.state = data[STATE]
internship.country = data[COUNTRY]
if internship.country.upper() == 'INDIA':
internship.city_type = 'Domestic'
else:
internship.city_type = 'International'
internship.pin_code = data[PINCODE]
internship.company_type = data[COMPANY_TYPE]
internship.nature_of_business = data[NATURE_OF_BUSINESS]
if data[IS_DESCRIPTION_PDF] == "true":
internship.is_description_pdf = True
else:
internship.is_description_pdf = False
if internship.is_description_pdf:
description_pdf = []
for file in files.getlist(DESCRIPTION_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + internship.id + '/'
description_pdf.append(saveFile(file, file_location))
internship.description_pdf_names = description_pdf
internship.designation = data[DESIGNATION]
internship.location = data[INTERNSHIP_LOCATION]
internship.description = data[DESCRIPTION]
if data[SEASON] == "":
raise ValueError('Season cannot be empty')
elif set(json.loads(data[SEASON])).issubset(SEASONS):
internship.season = json.loads(data[SEASON])
else:
raise ValueError('Season must be a subset of ' + str(SEASONS))
internship.interning_period_from = datetime.datetime.strptime(data[START_DATE], '%d-%m-%Y').date()
internship.interning_period_to = datetime.datetime.strptime(data[END_DATE], '%d-%m-%Y').date()
2024-07-24 23:27:27 +05:30
establishment_date_str = data.get('ESTABLISHMENT_DATE', '')
if establishment_date_str:
try:
internship.establishment_date = datetime.datetime.strptime(establishment_date_str, '%d-%m-%Y').date()
except ValueError:
internship.establishment_date = None
else:
internship.establishment_date = None
2023-07-25 00:34:39 +05:30
if data[WORK_TYPE] == 'Work from home':
2023-07-25 09:47:59 +05:30
internship.is_work_from_home = True
2023-07-25 00:34:39 +05:30
else:
2024-07-25 12:25:49 +05:30
internship.is_work_from_home = False
2023-11-09 19:44:57 +05:30
if ALLOWED_BATCH in data and (data[ALLOWED_BATCH] is None or json.loads(data[ALLOWED_BATCH]) == ""):
2023-11-09 18:37:36 +05:30
raise ValueError('Allowed Batches cannot be empty')
2023-11-09 19:44:57 +05:30
elif ALLOWED_BATCH in data and set(json.loads(data[ALLOWED_BATCH])).issubset(BATCHES):
internship.allowed_batch = json.loads(data[ALLOWED_BATCH])
else:
internship.allowed_batch = ['2021']
2023-11-09 19:44:57 +05:30
if data[ALLOWED_BRANCH] is None or json.loads(data[ALLOWED_BRANCH]) == "":
2023-07-25 00:34:39 +05:30
raise ValueError('Allowed Branch cannot be empty')
elif set(json.loads(data[ALLOWED_BRANCH])).issubset(BRANCHES):
internship.allowed_branch = json.loads(data[ALLOWED_BRANCH])
else:
raise ValueError('Allowed Branch must be a subset of ' + str(BRANCHES))
2024-06-21 00:15:00 +05:30
# if data[SOPHOMORES_ELIIGIBLE] == 'Yes':
# internship.sophomore_eligible = True
# else:
# internship.sophomore_eligible = False
2024-07-19 11:56:33 +05:30
if data[ELIGIBLESTUDENTS] is None:
raise ValueError('Eligible Students cannot be empty')
elif set(json.loads(data[ELIGIBLESTUDENTS])).issubset(ELIGIBLE):
internship.eligiblestudents = json.loads(data[ELIGIBLESTUDENTS])
else:
raise ValueError('Allowed Branch must be a subset of ' + str(ELIGIBLE))
2024-07-21 21:53:34 +05:30
2024-06-21 00:15:00 +05:30
if data[PWD_ELIGIBLE] == 'Yes':
internship.pwd_eligible = True
else:
internship.pwd_eligible = False
if data[BACKLOG_ELIGIBLE] == 'Yes':
internship.backlog_eligible = True
else:
internship.backlog_eligible = False
if data[PSYCHOMETRIC_TEST] == 'Yes':
internship.psychometric_test = True
2023-07-25 00:34:39 +05:30
else:
2024-06-21 00:15:00 +05:30
internship.psychometric_test = False
if data[MEDICAL_TEST] == 'Yes':
internship.medical_test = True
2023-07-25 00:34:39 +05:30
else:
2024-06-21 00:15:00 +05:30
internship.medical_test = False
internship.cpi_eligible = data[CPI]
2023-07-25 00:34:39 +05:30
if data[NUM_OFFERS].isdigit():
2023-07-25 09:47:59 +05:30
internship.tentative_no_of_offers = int(data[NUM_OFFERS])
2023-07-25 00:34:39 +05:30
else:
raise ValueError('Number of offers must be an integer')
if data[IS_STIPEND_DETAILS_PDF] == "true":
2023-07-25 09:47:59 +05:30
internship.is_stipend_description_pdf = True
2023-07-25 00:34:39 +05:30
else:
2023-07-25 09:47:59 +05:30
internship.is_stipend_description_pdf = False
2023-07-25 00:34:39 +05:30
2023-07-25 09:47:59 +05:30
if internship.is_stipend_description_pdf:
2023-07-25 00:34:39 +05:30
stipend_details_pdf = []
for file in files.getlist(STIPEND_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + internship.id + '/'
stipend_details_pdf.append(saveFile(file, file_location))
internship.stipend_description_pdf_names = stipend_details_pdf
if data[STIPEND].isdigit():
internship.stipend = int(data[STIPEND])
else:
raise ValueError('Stipend must be an integer')
2024-06-21 00:15:00 +05:30
# Newly added
if data[COMPANY_TURNOVER].isdigit():
internship.company_turnover = int(data[COMPANY_TURNOVER])
2024-07-24 23:27:27 +05:30
elif data[COMPANY_TURNOVER] is None or data[COMPANY_TURNOVER] == '':
2024-06-21 00:15:00 +05:30
internship.company_turnover = None
else:
2024-07-24 23:27:27 +05:30
# Handle the case where the data is not a valid number or None/empty
# You can raise an error, set a default value, or log a warning
internship.company_turnover = None # Or some default value or error handling
2024-06-21 00:15:00 +05:30
# newly added
if data[EXPECTED_NO_OF_OFFERS].isdigit():
internship.expected_no_of_offers = int(data[EXPECTED_NO_OF_OFFERS])
elif data[EXPECTED_NO_OF_OFFERS] == 'null':
internship.expected_no_of_offers = None
internship.other_requirements = data[OTHER_REQUIREMENTS]
# newly added
if data[NUMBER_OF_EMPLOYEES].isdigit():
internship.number_of_employees = int(data[NUMBER_OF_EMPLOYEES])
elif data[NUMBER_OF_EMPLOYEES] == 'null':
internship.number_of_employees = None
if data[FACILITIES] != "" :
if json.loads(data[FACILITIES]) == "":
internship.facilities_provided = []
elif set(json.loads(data[FACILITIES])).issubset(FACILITIES_CHOICES):
2023-07-25 09:47:59 +05:30
internship.facilities_provided = json.loads(data[FACILITIES])
2023-07-25 00:34:39 +05:30
else:
raise ValueError('Facilities must be a subset of ' + str(FACILITIES_CHOICES))
else:
internship.facilities_provided = []
2023-07-25 00:34:39 +05:30
internship.other_facilities = data[OTHER_FACILITIES]
if data[SELECTION_PROCEDURE_ROUNDS] is None:
raise ValueError('Selection Procedure Rounds cannot be empty')
else:
try:
internship.selection_procedure_rounds = json.loads(data[SELECTION_PROCEDURE_ROUNDS])
except:
raise ValueError('Selection Procedure Rounds must be a list')
internship.selection_procedure_details = data[SELECTION_PROCEDURE_DETAILS]
2023-07-25 09:47:59 +05:30
2023-07-25 00:34:39 +05:30
if data[IS_SELECTION_PROCEDURE_DETAILS_PDF] == "true":
internship.is_selection_procedure_details_pdf = True
else:
internship.is_selection_procedure_details_pdf = False
if internship.is_selection_procedure_details_pdf:
selection_procedure_details_pdf = []
for file in files.getlist(SELECTION_PROCEDURE_DETAILS_PDF):
file_location = STORAGE_DESTINATION_COMPANY_ATTACHMENTS + internship.id + '/'
selection_procedure_details_pdf.append(saveFile(file, file_location))
internship.selection_procedure_details_pdf_names = selection_procedure_details_pdf
2023-07-25 09:47:59 +05:30
internship.additional_facilities = data[OTHER_FACILITIES]
#add additional info
# Only Allowing Fourth Year for Placement
2023-07-25 09:47:59 +05:30
internship.academic_requirements = data[OTHER_REQUIREMENTS]
2023-07-25 00:34:39 +05:30
internship.contact_person_name = data[CONTACT_PERSON_NAME]
internship.phone_number = data[PHONE_NUMBER]
internship.email = data[EMAIL]
internship.save()
stat, link = generateOneTimeVerificationLink(internship.email, internship.id, "Internship")
if not stat:
raise RuntimeError("Error in generating one time verification link for internship")
data = {
"designation": internship.designation,
"one_time_link": link,
"opening_type": "Internship"
2023-07-25 00:34:39 +05:30
}
sendEmail(internship.email, COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT, data,
COMPANY_EMAIL_VERIFICATION_TEMPLATE)
return Response({'action': "Add Internship", 'message': "Internship Added Successfully"},
status=status.HTTP_200_OK)
except ValueError as e:
store_all_files(request)
2023-07-25 09:47:59 +05:30
logger.warning("ValueError in addInternship: " + str(e))
logger.warning(traceback.format_exc())
2023-07-25 00:34:39 +05:30
return Response({'action': "Add Internship", 'message': str(e)},
status=status.HTTP_400_BAD_REQUEST)
2024-07-19 11:56:33 +05:30
except Exception as e:
2023-07-25 00:34:39 +05:30
store_all_files(request)
2024-07-19 11:56:33 +05:30
logger.warning("Add New Internship: " + str(e))
logger.warning(traceback.format_exc())
2024-07-19 11:56:33 +05:30
return Response({'action': "Add Internship", 'message': "Something went wrong: " + str(e)},
2023-07-25 00:34:39 +05:30
status=status.HTTP_400_BAD_REQUEST)
2024-07-19 11:56:33 +05:30