diff --git a/scripts/create_faculty.py b/scripts/create_faculty.py new file mode 100644 index 0000000..041ef68 --- /dev/null +++ b/scripts/create_faculty.py @@ -0,0 +1,33 @@ +import datetime +from shell.models import * +from pseudoc.constants import CATEGORIES, DESIGNATION_DICT, DEPTS, CENTRES +def create_faculty(data, person_object): + """ + Function to create faculty for a person + :param data: data from ACAD API + :param person_object: the person whose faculty role to define + :return: faculty instance created + """ + + try: + content_object = Department.objects.get( + code=DEPTS[data['DepartmentAlphaCode'].lower()] + ) + except KeyError: + content_object = Centre.objects.get( + code=CENTRES[data['DepartmentAlphaCode'].lower()] + ) + + faculty = FacultyMember.objects.get_or_create( + employee_id=int(data['EmployeeNo']), + defaults={ + 'content_object': content_object, + 'start_date': datetime.datetime.now(), + 'person': person_object, + 'designation': DESIGNATION_DICT.get( + data['Designation'].lower().strip() + ), + } + ) + + return faculty diff --git a/scripts/create_faculty_pseudoc_framework.py b/scripts/create_faculty_pseudoc_framework.py new file mode 100644 index 0000000..2b92251 --- /dev/null +++ b/scripts/create_faculty_pseudoc_framework.py @@ -0,0 +1,31 @@ +from scripts.create_user import create_user +from scripts.create_faculty import create_faculty +from scripts.populate_details import populate_details +from scripts.make_request import make_request +def create_faculty_pseudoc_framework(data:dict): + employee_id = data.get('employee_id', None) + + if employee_id is None: + return "Enter a valid employee id" , 400 + + data_acad = make_request(employee_id, True) + + if data_acad is None: + return "Data on ACAD profile doesn't exist for this user", 400 + + user, person = create_user(employee_id, data_acad) + + try: + if 'Contract' in data_acad['Designation']: + data_acad['Designation'] = 'Assistant Professor (contract)' + elif 'Assistant Professor' in data_acad['Designation']: + data_acad['Designation'] = 'Assistant Professor' + elif 'Visiting Faculty' in data_acad['Designation']: + data_acad['Designation'] = 'Visiting Professor' + faculty = create_faculty(data_acad, person) + except: + return "Error creating faculty", 417 + + populate_details(person, data_acad) + + return "Successfully created Faculty", 200 diff --git a/scripts/create_new_student.py b/scripts/create_new_student.py new file mode 100644 index 0000000..96888dc --- /dev/null +++ b/scripts/create_new_student.py @@ -0,0 +1,40 @@ +import datetime +from registration.models.student import NewStudent + +from core.kernel.models import * + + +def create_new_student(data, person_object): + """ + Function to create student for a person + :param data: data from ACAD API + :param person_object: the person whose student role to be defined + :return: student instance created + """ + sem_id = str(data['SemesterID']) + try: + student = NewStudent( + start_date=datetime.datetime.now(), + person=person_object, + enrolment_number=int(data['EnrollmentNo']), + branch=Branch.objects.get(code=data['ProgramID']), + current_year=int(sem_id[1]), + current_semester=(int(sem_id[1]) - 1) * 2 + int( + sem_id[2]) + 1 + ) + except: + return None + try: + father = person_object.parents.create() + father.contact_information.create() + father.save() + mother = person_object.parents.create() + mother.contact_information.create() + mother.save() + person_object.save() + except: + pass + student.save() + + return student + diff --git a/scripts/create_staff_pseudoc_framework.py b/scripts/create_staff_pseudoc_framework.py new file mode 100644 index 0000000..cd1efcb --- /dev/null +++ b/scripts/create_staff_pseudoc_framework.py @@ -0,0 +1,12 @@ + +def create_staff_pseudoc_framework(data:dict): + errors_uname = create() + + if len(errors_uname) == 0: + return "Succesfully created all staff", 200 + unames = '' + + for uname in errors_uname: + unames += f'{uname} ' + return f'Error creating following employees {unames}', 417 + diff --git a/scripts/create_student.py b/scripts/create_student.py new file mode 100644 index 0000000..17af074 --- /dev/null +++ b/scripts/create_student.py @@ -0,0 +1,41 @@ +import datetime +from core.kernel.models import * +from scripts.get_semester_from_id import get_semester_from_id + +def create_student(data, person_object): + """ + Function to create student for a person + :param data: data from ACAD API + :param person_object: the person whose student role to be defined + :return: student instance created + """ + sem_id = str(data['SemesterID']) + + try: + student = Student.objects.get(person=person_object) + except: + student = Student( + start_date=datetime.datetime.now(), + person=person_object, + enrolment_number=int(data['EnrollmentNo']), + branch=Branch.objects.get(code=data['ProgramID']), + current_semester=get_semester_from_id(sem_id) + ) + student.save() + + try: + local_guardian = person_object.local_guardians.create() + local_guardian.contact_information.create() + father = Person.objects.create( + full_name=data['Fathersname'].title() + ) + mother = Person.objects.create( + full_name=data['MotherName'].title(), + ) + person_object.parents.add(father) + person_object.parents.add(mother) + person_object.save() + except: + pass + + return student \ No newline at end of file diff --git a/scripts/create_student_pseudoc_framework.py b/scripts/create_student_pseudoc_framework.py new file mode 100644 index 0000000..d4ab360 --- /dev/null +++ b/scripts/create_student_pseudoc_framework.py @@ -0,0 +1,36 @@ +from scripts.create_user import create_user +from scripts.create_student import create_student +from scripts.populate_details import populate_details +from scripts.make_request import make_request + +def create_student_pseudoc_framework(data:dict): + enrolment_number = data.get('enrolment_number', None) + + if enrolment_number is None: + return "Enter a valid enrolment number" , 400 + + data_acad = make_request(enrolment_number, False) + + if data_acad is None: + return "Data on ACAD profile doesn't exist for this user", 400 + + + user, person = create_user(enrolment_number, data_acad) + + try: + student = create_student(data_acad, person) + except: + return "Error creating student", 417 + + populate_details(person, data_acad) + contact = person.contact_information.get() + + if contact.institute_webmail_address is None: + contact.institute_webmail_address = data_acad['IITREmailID'] + print(enrolment_number) + contact.save() + + print(f'{person} ::: {person.contact_information.get()}') + + return "Successfully created Student", 200 + diff --git a/scripts/create_user.py b/scripts/create_user.py new file mode 100644 index 0000000..4ad28f7 --- /dev/null +++ b/scripts/create_user.py @@ -0,0 +1,31 @@ + +from django.db import IntegrityError + +from core.kernel.models import * +from formula_one.models import * +from shell.models import * +from core.base_auth.models import User + +def create_user(username, acad_data): + """ + Function to create a user and person instancec for omniport + :param username: Username of the user to be created + :param acad_data: Data from the acad API, which we use to create user + :return: user and person instance created + """ + user, _ = User.objects.get_or_create( + username=username, + ) + try: + person, person_created = Person.objects.get_or_create( + user=user, + full_name=acad_data['Name'].title(), + ) + except IntegrityError: + person = Person.objects.get( + user=user + ) + person.full_name = acad_data['Name'].title() + person.save() + + return user, person diff --git a/scripts/get_semester_from_id.py b/scripts/get_semester_from_id.py new file mode 100644 index 0000000..e9abf39 --- /dev/null +++ b/scripts/get_semester_from_id.py @@ -0,0 +1,20 @@ + +mba_map = { + '310': 1, + '320': 2, + '331': 3, + '341': 4, + '350': 5, + '360': 6, + '371': 7, + '381': 8 +} +mba_sem_id = [int(id) for id in mba_map.keys()] + +def get_semester_from_id(semester_id): + semester_id = int(semester_id) + if semester_id in mba_sem_id: + return mba_map[str(semester_id)] + else: + semester_id = str(semester_id) + return (int(semester_id[1])-1)*2+int(semester_id[2])+1 \ No newline at end of file diff --git a/scripts/make_request.py b/scripts/make_request.py new file mode 100644 index 0000000..aee41df --- /dev/null +++ b/scripts/make_request.py @@ -0,0 +1,27 @@ +import requests +from pseudoc.secrets import ACAD_URL_FACULTY, ACAD_URL_STUDENT, HEADER, NEW_ACAD_URL_STUDENT, NEW_ACAD_URL_FACULTY +def make_request(username, is_faculty=False): + """ + :param username: username for whom data to be fetched + :param is_faculty: True if user is a faculty + :return: dat on success, None otherwise + """ + try: + r = requests.get( + url=f'{NEW_ACAD_URL_STUDENT}{username}' if not is_faculty + else f'{NEW_ACAD_URL_FACULTY}{username}', + headers=HEADER, + ) + data = r.json() + if isinstance(data, list): + data = data[0] if len(data)==1 else None + if not (data or is_faculty): + r = requests.get( + url=f'{ACAD_URL_STUDENT}{username}' if not is_faculty + else f'{ACAD_URL_FACULTY}{username}', + headers=HEADER, + ) + data = r.json() + return data + except requests.ConnectionError: + return None \ No newline at end of file diff --git a/scripts/populate_contact_info.py b/scripts/populate_contact_info.py new file mode 100644 index 0000000..adbe4ac --- /dev/null +++ b/scripts/populate_contact_info.py @@ -0,0 +1,42 @@ + +from django.db import IntegrityError + +from core.base_auth.managers.get_user import get_user + +def populate_contact_info(contact_information, details): + """ + Function to populate the contact info of a person based on ACAD API data + :param contact_information: location information instance + :param details: data from ACAD API + :return: True if successful, False otherwise + """ + try: + contact_information.primary_phone_number = details.get( + 'Mobileno', None + ) + contact_information.secondary_phone_number = details.get( + 'ContactNo', None + ) + if contact_information.secondary_phone_number == '': + contact_information.secondary_phone_number = None + contact_information.email_address = details.get('EmailID', None) + + institute_email_id = details['IITREmailID'] + if not contact_information.institute_webmail_address or contact_information.institute_webmail_address != institute_email_id: + try: + contact_information.institute_webmail_address = institute_email_id + except IntegrityError: + person2 = get_user(institute_email_id).person + contact2 = person2.contact_information.get() + contact2.institute_webmail_address = None + contact2.save() + + contact_information.institute_webmail_address = institute_email_id + except Exception as e: + return False + + contact_information.save() + return True + except: + return False + diff --git a/scripts/populate_details.py b/scripts/populate_details.py new file mode 100644 index 0000000..2c4438a --- /dev/null +++ b/scripts/populate_details.py @@ -0,0 +1,206 @@ +import datetime + +from django_countries.data import COUNTRIES + + +from core.kernel.models import * +from formula_one.models import * + +from core.base_auth.models import User +from shell.constants import residences +from scripts.populate_location_info import populate_location_info +from pseudoc.constants import CATEGORIES +from scripts.populate_contact_info import populate_contact_info + +def populate_details(person_object, details, update_residential_info = False): + """ + One function which handles the creation and population of biological info, + location info, contact info, residential and political info of a person + :param person_object: person object for whom model instances to be created + :param details: data from ACAD API + :return: None + """ + # --------------------------LocationInfo Creation--------------------------# + try: + location_queryset = person_object.location_information.all() + if len(location_queryset) == 0: + location_information = LocationInformation.objects.create( + entity=person_object + ) + else: + location_information = location_queryset[0] + + populate_location_info(location_information, details) + + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# + + # --------------------------ContactInfo Creation---------------------------# + try: + contact_informations = person_object.contact_information.all() + if len(contact_informations) == 0: + contact_information = ContactInformation.objects.create( + entity=person_object + ) + elif len(contact_informations) == 1: + contact_information = contact_informations[0] + + populate_contact_info(contact_information, details) + + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# + + # --------------------------PoliticalInfo Creation-------------------------# + try: + category_code = "oth" # Default is 'other' + country_code = "IN" + religion = (details.get('Religion', "") or '').title() + try: + category_code = CATEGORIES.get(details.get("Category", "other"), + 'oth') + nationality = details.get('Nationality', '') or \ + details.get('Pcountry', '') or '' + for c, v in COUNTRIES.items(): + if v.lower() == nationality.lower(): + country_code = c + break + except: + pass + + political_informations = PoliticalInformation.objects.filter(person=person_object) + if len(political_informations) == 0: + _ = PoliticalInformation.objects.create( + person=person_object, + nationality=country_code, + religion=religion, + reservation_category=category_code, + ) + else: + political_information = political_informations[0] + political_information.nationality = country_code + political_information.religion = religion + political_information.reservation_category = category_code + + try: + political_information.save() + except Exception as e: + # print(str(e)) + pass + + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# + + # ---------------------------BiologicalInfo Creation-----------------------# + try: + + all_blood_groups = ['O+', 'O-', 'A+', 'A-', 'B+', 'B-', 'AB+', 'AB-'] + + # Default = 'O+' + blood_group = (details.get("BloodGroup", 'O+') or 'O+').upper().\ + strip().replace( + ' ', '') + if blood_group not in all_blood_groups: + blood_group = 'O+' + + # If DoB is not found, mark today's date as Birth Date. + if details.get("DateofBirth", False): + dob = datetime.datetime.strptime(details["DateofBirth"], "%d-%m-%Y").date() + else: + dob = datetime.datetime.now().date() + + # If gender is not found, mark default sex as non-disclosure + sex = 'n-dis' + if details.get('Gender', False): + sex = details['Gender'].lower() + + # If gender is not found, mark default gender as non-disclosure + gender = 'n-dis' + if details.get('Gender', False): + if details['Gender'].lower().startswith('f'): + gender = 'woman' + elif details['Gender'].lower().startswith('m'): + gender = 'man' + + # If gender is not found, mark default pronoun as 'They/them/their' + pronoun = 't' + if details.get('Gender', False): + if details['Gender'].lower().startswith('f'): + pronoun = 's' + elif details['Gender'].lower().startswith('m'): + pronoun = 'h' + + biological_informations = BiologicalInformation.objects.filter(person=person_object) + if len(biological_informations) == 0: + _ = BiologicalInformation.objects.create( + person=person_object, + date_of_birth=dob, + blood_group=blood_group, + sex=sex, + gender=gender, + pronoun=pronoun, + impairment='n' + ) + else: + biological_information = biological_informations[0] + biological_information.date_of_birth=dob + biological_information.blood_group=blood_group + biological_information.sex=sex + biological_information.gender=gender + biological_information.pronoun=pronoun + biological_information.impairment='n' + + try: + biological_information.save() + except Exception as e: + # print(str(e)) + pass + + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# + + # ---------------------------FinancialInfo Creation------------------------# + try: + _ = FinancialInformation.objects.create( + person=person_object, + ) + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# + + # ---------------------------ResidentialInfo Creation----------------------# + try: + if update_residential_info: + # default bhawan as 'not a resident' + bhawan_code = "nor" + if details.get('Bhawan', False): + for rr in residences.RESIDENCES: + if rr[1].lower() == details['Bhawan'].lower(): + bhawan_code = rr[0] + break + + residential_informations = ResidentialInformation.objects.filter(person=person_object) + if bhawan_code == "nor" and len(residential_informations) == 0: + _ = ResidentialInformation.objects.create( + person=person_object, + residence=Residence.objects.get_or_create(code=bhawan_code)[0], + room_number="NIL" + ) + else: + _ = ResidentialInformation.objects.create( + person=person_object, + residence=Residence.objects.get_or_create(code=bhawan_code)[0], + room_number=details.get('RoomNo', "NIL") + ) + except Exception as e: + # print(str(e)) + pass + # -------------------------------------------------------------------------# \ No newline at end of file diff --git a/scripts/populate_location_info.py b/scripts/populate_location_info.py new file mode 100644 index 0000000..b1d5ecf --- /dev/null +++ b/scripts/populate_location_info.py @@ -0,0 +1,32 @@ + + +from django_countries.data import COUNTRIES + +def populate_location_info(location_information, details): + """ + Function to populate the location info of a person based on ACAD API data + :param location_information: location information instance + :param details: data from ACAD API + :return: True if successful, False otherwise + """ + try: + country_code = "IN" + nationality = details.get('Nationality', '') or \ + details.get('Pcountry', '') or '' + for c, v in COUNTRIES.items(): + if v.lower() == nationality.lower(): + country_code = c + break + + location_information.address = details.get( + 'PermanentAddress', '' + ) or '' + location_information.state = details.get('State', '') or '' + location_information.city = details.get('City', '') or '' + location_information.country = country_code + + location_information.save() + + return True + except: + return False diff --git a/scripts/populate_new_details.py b/scripts/populate_new_details.py new file mode 100644 index 0000000..2146e1c --- /dev/null +++ b/scripts/populate_new_details.py @@ -0,0 +1,75 @@ +import datetime + +from django_countries.data import COUNTRIES +from pseudoc.constants import CATEGORIES +from registration.models.biological_information import NewBiologicalInformation +from registration.models.political_information import NewPoliticalInformation +def populate_new_details(details, new_person): + + try: + category_code = "oth" # Default is 'other' + country_code = "IN" + try: + category_code = CATEGORIES.get(details.get("Category", "other"), + 'oth') + nationality = details.get('Nationality', '') or \ + details.get('Pcountry', '') or '' + for c, v in COUNTRIES.items(): + if v.lower() == nationality.lower(): + country_code = c + break + except: + pass + + _ = NewPoliticalInformation.objects.create( + person=new_person, + nationality=country_code, + religion=(details.get('Religion', "") or '').title(), + reservation_category=category_code, + ) + except: + pass + + try: + + all_blood_groups = ['O+', 'O-', 'A+', 'A-', 'B+', 'B-', 'AB+', 'AB-'] + + # Default = 'O+' + blood_group = (details.get("BloodGroup", 'O+') or 'O+').upper().\ + strip().replace( + ' ', '') + if blood_group not in all_blood_groups: + blood_group = 'O+' + + _ = NewBiologicalInformation.objects.create( + person=new_person, + + # If DoB is not found, mark today's date as Birth Date. + date_of_birth=datetime.datetime.strptime( + details["DateofBirth"], "%Y-%m-%dT%H:%M:%S" + ).date() \ + if details.get("DateofBirth", False) else + datetime.datetime.now().date(), + + blood_group=blood_group, + + # If gender is not found, mark default sex as male + sex=details['Gender'].lower() \ + if details.get('Gender', False) else 'male', + + # If gender is not found, mark default gender as man + gender='woman' \ + if (details.get('Gender', False) + and details['Gender'].lower().startswith('f')) \ + else 'man', + + # If gender is not found, mark default pronoun as 'he/his/him' + pronoun='s' \ + if (details.get('Gender', False) + and details['Gender'].lower().startswith('f')) \ + else 'h', + + impairment='n' + ) + except: + pass diff --git a/scripts/send_mail_create_user.py b/scripts/send_mail_create_user.py new file mode 100644 index 0000000..de2f51c --- /dev/null +++ b/scripts/send_mail_create_user.py @@ -0,0 +1,75 @@ + +from services.categories.models import Category +from omniport.settings.configuration.base import CONFIGURATION +from formula_one.utils.verification_token import send_token + +from core.kernel.models import * + +from services.categories.models import Category +from omniport.settings.configuration.base import CONFIGURATION +from formula_one.utils.verification_token import send_token + + + +def send_mail_create_user(username, user_id, person_id): + """ + Function to send success mail on user creation + :param user_id: user id to send the mail to + :param person_id: person id to send the mail to + :return: True on success, False otherwise + """ + site_name = CONFIGURATION.site.nomenclature.verbose_name + site_url = CONFIGURATION.allowances.hosts[0] + + token_type = 'RECOVERY_TOKEN' + url = f'https://channeli.in/auth/reset_password/?token={token_type}' + subject = f'{site_name} account creation' + body = f''' + Your Channeli account has been created. + To reset your {site_name} account password, please visit url' + ''' + category, _ = Category.objects.get_or_create(name="Auth", slug="auth") + person_name = Person.objects.get(id=person_id).full_name + new_account_body = f"""Hi! +

+ Please ignore this mail if you're already using channeli +

+ Welcome to {site_name}! Pay a visit by logging in at https://channeli.in/ with username as {username} and the account password. To set your account password, please visit the following link. +

+ url +

+ If the link doesn't work with the username as provided in the mail above, please refer resetting your password from the link: https://iitr.ac.in/channeli/assets/guide.pdf If the link is expired, generate a new link by clicking on the reset password button on the login screen. Please feel free to contact IMG or Website-Support if you face any issue during password reset, login, or any other functionality. +

+ Regards, +
+ Information Management Group""" + + new_student_account_body = f"""Hello {person_name}. +

+ Information Management Group welcomes you to IIT Roorkee! +

+ Let us introduce you to {site_name}! Your one stop portal for everything related to R-Land. Pay a visit by logging in at https://channeli.in/ with username as {username} and the account password. To set your account password, please visit the following link. +

+ url +

+ Please refer resetting your password from the link: https://iitr.ac.in/channeli/assets/guide.pdf if the link doesn't work with the username as provided in the mail above. If the link is expired, generate a new link by clicking on the reset password button on the login screen. Please feel free to contact IMG if you face any issue during password reset, login, or any other functionality. +

+ Regards, +
+ Information Management Group""" + + + try: + send_token( + user_id=user_id, + person_id=person_id, + token_type=token_type, + email_body=new_student_account_body, + email_subject=subject, + url=url, + category=category + ) + return True + except: + return False + diff --git a/scripts/send_mail_registration.py b/scripts/send_mail_registration.py new file mode 100644 index 0000000..cd37009 --- /dev/null +++ b/scripts/send_mail_registration.py @@ -0,0 +1,162 @@ +import datetime + +from django_countries.data import COUNTRIES +from services.categories.models import Category +from omniport.settings.configuration.base import CONFIGURATION +from django.utils.crypto import get_random_string +from scripts.make_request import make_request +from shell.registration.scripts.auth.create_staff_old import * +from services.emails.actions import email_push +from pseudoc.constants import CATEGORIES +from registration.models.biological_information import NewBiologicalInformation +from registration.models.political_information import NewPoliticalInformation +from registration.models.new_person import NewPerson +from scripts.create_new_student import create_new_student +from scripts.populate_contact_info import populate_contact_info +from scripts.populate_location_info import populate_location_info +def send_mail_registration(username, secret_key, person_object, email_address): + """ + Function to send success mail on user updation + :param person_object: person to send the mail to + :return: True on success, False otherwise + """ + site_name = CONFIGURATION.site.nomenclature.verbose_name + category, _ = Category.objects.get_or_create(name="Auth", slug="auth") + email_subject = f'Welcome to {site_name}!' + email_body = f""" + Greeting {person_object.full_name}! +

+ Now that you are officially a part of the R-Land family we welcome you to the official + intranet(and for unforseen times like COVID-19, internet) portal of IIT Roorkee, Channel i. +

+ Channel i is the name you'll be hearing quite a lot during your stay at R-Land, so let's get + started! Please visit this URL https://internet.channeli.in/registration/register_student and use your enrolment number with the following registration key to register yourself: +

+ Registration Key: {secret_key} +

+ Why Channeli? Read here: https://medium.com/img-iit-roorkee/channeli-with-love-11cc10dfb6e1 +

+ Please feel free to contact IMG if you face any further issues. +

+ Regards, +
+ Information Management Group + """ + + try: + email_push(subject_text=email_subject, body_text=email_body, + category=category, has_custom_user_target=True, + email_ids=[email_address], + target_app_name=None, + target_app_url=None) + return True + except: + return False + + +def create_new_omniport_student(enrolment_number, err_list): + + details = make_request(enrolment_number, False) + + if details is None: + err_list.append(enrolment_number) + return False + secret = get_random_string(8) + new_person = NewPerson.objects.create(full_name=details['Name'].title(), secret_code=secret) + + contact_info = new_person.contact_information.create() + location_info = new_person.location_information.create() + + local_guardian = new_person.local_guardians.create() + local_guardian.contact_information.create() + + if not populate_contact_info(contact_info, details): + err_list.append(enrolment_number) + return False + + if not populate_location_info(location_info, details): + err_list.append(enrolment_number) + return False + + email_address = details.get( + 'PRIEMAIL', + details['IITREmailID'] + ) + try: + category_code = "oth" # Default is 'other' + country_code = "IN" + try: + category_code = CATEGORIES.get(details.get("Category", "other"), + 'oth') + nationality = details.get('Nationality', '') or \ + details.get('Pcountry', '') or '' + for c, v in COUNTRIES.items(): + if v.lower() == nationality.lower(): + country_code = c + break + except: + pass + + _ = NewPoliticalInformation.objects.create( + person=new_person, + nationality=country_code, + religion=(details.get('Religion', "") or '').title(), + reservation_category=category_code, + ) + except: + err_list.append(enrolment_number) + return False + + try: + + all_blood_groups = ['O+', 'O-', 'A+', 'A-', 'B+', 'B-', 'AB+', 'AB-'] + + # Default = 'O+' + blood_group = (details.get("BloodGroup", 'O+') or 'O+').upper().\ + strip().replace( + ' ', '') + if blood_group not in all_blood_groups: + blood_group = 'O+' + + _ = NewBiologicalInformation.objects.create( + person=new_person, + + # If DoB is not found, mark today's date as Birth Date. + date_of_birth=datetime.datetime.strptime( + details["DateofBirth"], "%Y-%m-%dT%H:%M:%S" + ).date() \ + if details.get("DateofBirth", False) else + datetime.datetime.now().date(), + + blood_group=blood_group, + + # If gender is not found, mark default sex as male + sex=details['Gender'].lower() \ + if details.get('Gender', False) else 'male', + + # If gender is not found, mark default gender as man + gender='woman' \ + if (details.get('Gender', False) + and details['Gender'].lower().startswith('f')) \ + else 'man', + + # If gender is not found, mark default pronoun as 'he/his/him' + pronoun='s' \ + if (details.get('Gender', False) + and details['Gender'].lower().startswith('f')) \ + else 'h', + + impairment='n' + ) + except: + err_list.append(enrolment_number) + return False + + if create_new_student(details, new_person) is None: + err_list.append(enrolment_number) + return False + + send_mail_registration(enrolment_number, secret, new_person, email_address) + + return True + diff --git a/scripts/send_mail_update_user.py b/scripts/send_mail_update_user.py new file mode 100644 index 0000000..3b860a1 --- /dev/null +++ b/scripts/send_mail_update_user.py @@ -0,0 +1,49 @@ + +from omniport.settings.configuration.base import CONFIGURATION +from services.categories.models import Category +from services.emails.actions import email_push + +mba_map = { + '310': 1, + '320': 2, + '331': 3, + '341': 4, + '350': 5, + '360': 6, + '371': 7, + '381': 8 +} +mba_sem_id = [int(id) for id in mba_map.keys()] + +def send_mail_update_user(person_object): + """ + Function to send success mail on user updation + :param person_object: person to send the mail to + :return: True on success, False otherwise + """ + site_name = CONFIGURATION.site.nomenclature.verbose_name + category, _ = Category.objects.get_or_create(name="Auth", slug="auth") + email_subject = f'{site_name} account information updation' + email_body = f''' + Hello {person_object.full_name}. +

+ Your {site_name} account's information has been updated, + Please recheck the updated changes by logging into your + account at https://newchanneli.iitr.ac.in +

+ Please feel free to contact IMG if you face any further issues. +

+ Regards, +
+ Information Management Group + ''' + + try: + email_push(subject_text=email_subject, body_text=email_body, + category=category, has_custom_user_target=True, + persons=[person_object.id], + target_app_name=None, + target_app_url=None) + return True + except: + return False \ No newline at end of file diff --git a/scripts/update_contact_info_pseudoc_framework.py b/scripts/update_contact_info_pseudoc_framework.py new file mode 100644 index 0000000..f67de61 --- /dev/null +++ b/scripts/update_contact_info_pseudoc_framework.py @@ -0,0 +1,32 @@ + +from core.kernel.models import * +from formula_one.models import * +from shell.models import * +from scripts.populate_contact_info import populate_contact_info +from scripts.make_request import make_request + +from core.base_auth.managers.get_user import get_user + + + +def update_contact_info_pseudoc_framework(data:dict): + username = data.get('username', None) + + if username is None: + return "Enter a valid enrolment number/employee id", 400 + + data_acad = make_request(username, True) + + if data_acad is None: + data_acad = make_request(username, False) + + if data_acad is None: + return "Data on ACAD Profile doesn't exist", 417 + + try: + contact_info = get_user(username).person.contact_information.get() + except: + return "Error retrieving contact info", 417 + if populate_contact_info(contact_info, data_acad): + return "Info updated successfully", 200 + return "Error updating contact info", 417 diff --git a/scripts/update_email_addr.py b/scripts/update_email_addr.py new file mode 100644 index 0000000..7aa7f64 --- /dev/null +++ b/scripts/update_email_addr.py @@ -0,0 +1,17 @@ +from core.base_auth.managers.get_user import get_user + + +def update_email_addr(data:dict): + email_updated = data.get('email_address', None) + + if email_updated is '' or None: + return "Enter a valid email address", 400 + + username = data.get('username', None) + + c = get_user(username).person.contact_information.get() + + c.email_address = email_updated + c.save() + + return "Successfully updated email address", 200 \ No newline at end of file diff --git a/scripts/update_webmail_addr.py b/scripts/update_webmail_addr.py new file mode 100644 index 0000000..efc4c94 --- /dev/null +++ b/scripts/update_webmail_addr.py @@ -0,0 +1,19 @@ + +from core.base_auth.managers.get_user import get_user + + + +def update_webmail_addr(data:dict): + webmail_updated = data.get('email_address', None) + + if webmail_updated is '' or None: + return "Enter a valid institute email address", 400 + + username = data.get('username', None) + + c = get_user(username).person.contact_information.get() + + c.institute_webmail_address = webmail_updated + c.save() + + return "Institute Email updated successfully", 200