def import_alumni_note(self, sheet): from ecwsp.alumni.models import Alumni, AlumniNote, AlumniNoteCategory x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items, try_secondary=True) category = note = date = user = None if hasattr(student, 'alumni'): alumni = student.alumni else: alumni = Alumni(student=student) alumni.save() for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name == "category": category = AlumniNoteCategory.objects.get_or_create( name=value)[0] elif name == "note": note = value elif name == "date": date = self.convert_date(value) elif name == "user": user = User.objects.get(username=value) note, created = AlumniNote.objects.get_or_create( alumni=alumni, category=category, note=note, date=date, user=user, ) if created: self.log_and_commit(note, addition=created) inserted += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated
def import_alumni_note(self, sheet): from ecwsp.alumni.models import Alumni, AlumniNote, AlumniNoteCategory x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items,try_secondary=True) category = note = date = user = None if hasattr(student, 'alumni'): alumni = student.alumni else: alumni = Alumni(student=student) alumni.save() for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name == "category": category = AlumniNoteCategory.objects.get_or_create(name=value)[0] elif name == "note": note = value elif name == "date": date = self.convert_date(value) elif name == "user": user = User.objects.get(username=value) note, created = AlumniNote.objects.get_or_create( alumni=alumni, category=category, note=note, date=date, user=user, ) if created: self.log_and_commit(note, addition=created) inserted += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated
def import_alumni_number(self, sheet): from ecwsp.alumni.models import Alumni, AlumniPhoneNumber x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items, try_secondary=True) phone_number = phone_number_type = None if hasattr(student, 'alumni'): alumni = student.alumni else: alumni = Alumni(student=student) alumni.save() for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name in ["phone number", 'number']: phone_number = AlumniEmail.objects.get_or_create( email=value)[0] elif name == "type": phone_number_type = value note, created = AlumniPhoneNumber.objects.get_or_create( alumni=alumni, phone_number=phone_number, type=phone_number_type, ) if created: self.log_and_commit(note, addition=created) inserted += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated
def import_alumni_number(self, sheet): from ecwsp.alumni.models import Alumni, AlumniPhoneNumber x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items,try_secondary=True) phone_number = phone_number_type = None if hasattr(student, 'alumni'): alumni = student.alumni else: alumni = Alumni(student=student) alumni.save() for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name in ["phone number", 'number']: phone_number = AlumniEmail.objects.get_or_create(email=value)[0] elif name == "type": phone_number_type = value note, created = AlumniPhoneNumber.objects.get_or_create( alumni=alumni, phone_number=phone_number, type=phone_number_type, ) if created: self.log_and_commit(note, addition=created) inserted += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated
def import_college_enrollment(self, sheet): from ecwsp.alumni.models import Alumni, College, CollegeEnrollment x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items,try_secondary=True) search_date = code = college_name = state = year = type = begin = end = None status = graduated = graduation_date = degree_title = major = record_found = None if hasattr(student, 'alumni'): alumni = student.alumni alumni_created = False else: alumni = Alumni(student=student) alumni.save() alumni_created = True for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name == "search date": search_date = self.convert_date(value) elif name in ["college code", 'college code/branch','college_code/branch']: code = value elif name in ['name', 'college name','college_name']: college_name = value elif name in ['state', 'college state', 'college_state']: state = value elif name in ['year', '2-year/4-year', '2-year / 4-year']: if value == "4-year": value = "4" elif value == "2-year": value = "2" year = value elif name in ['type', 'public/private', 'public / private']: type = value elif name in ['begin', 'enrollment begin','enrollment_begin']: begin = self.convert_date(value) elif name in ['end', 'enrollment end','enrollment_end']: end = self.convert_date(value) elif name in ['status', 'enrollment status','enrollment_status']: status = value.strip() elif name in ['graduated', 'graduated?']: graduated = self.determine_truth(value) elif name in ['graduation date', 'graduation_date']: graduation_date = self.convert_date(value) elif name in ['degree_title', 'degree title']: degree_title = value elif name in ['major']: major = value elif name in ['record_found', 'record_found_y/n']: record_found = self.determine_truth(value) if record_found: # First get or create college college, c_created = College.objects.get_or_create(code=code) if c_created: college.name = college_name college.state = state college.type = type college.save() if not graduated and begin: # Get or create enrollment based on secondary key model, created = CollegeEnrollment.objects.get_or_create( college=college, program_years=year, begin=begin, end=end, status=status, alumni=alumni, ) model.search_date = search_date model.graduated = graduated model.graduation_date = graduation_date model.degree_title = degree_title model.major = major model.full_clean() model.save() self.log_and_commit(model, addition=created) if created: inserted += 1 else: updated += 1 elif not alumni.college_override: # Graduated but no enrollment data alumni.graduated = graduated alumni.graduation_date = graduation_date if not alumni.college: alumni.college = college alumni.full_clean() alumni.save() self.log_and_commit(alumni, addition=alumni_created) if alumni_created: inserted += 1 else: updated += 1 else: self.log_and_commit(alumni, addition=alumni_created) if alumni_created: inserted += 1 else: updated += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated
def import_college_enrollment(self, sheet): from ecwsp.alumni.models import Alumni, College, CollegeEnrollment x, header, inserted, updated = self.import_prep(sheet) name = None while x < sheet.nrows: with transaction.commit_manually(): try: name = None row = sheet.row(x) items = zip(header, row) student = self.get_student(items, try_secondary=True) search_date = code = college_name = state = year = type = begin = end = None status = graduated = graduation_date = degree_title = major = record_found = None if hasattr(student, 'alumni'): alumni = student.alumni alumni_created = False else: alumni = Alumni(student=student) alumni.save() alumni_created = True for (name, value) in items: is_ok, name, value = self.sanitize_item(name, value) if is_ok: if name == "search date": search_date = self.convert_date(value) elif name in [ "college code", 'college code/branch', 'college_code/branch' ]: code = value elif name in [ 'name', 'college name', 'college_name' ]: college_name = value elif name in [ 'state', 'college state', 'college_state' ]: state = value elif name in [ 'year', '2-year/4-year', '2-year / 4-year' ]: if value == "4-year": value = "4" elif value == "2-year": value = "2" year = value elif name in [ 'type', 'public/private', 'public / private' ]: type = value elif name in [ 'begin', 'enrollment begin', 'enrollment_begin' ]: begin = self.convert_date(value) elif name in [ 'end', 'enrollment end', 'enrollment_end' ]: end = self.convert_date(value) elif name in [ 'status', 'enrollment status', 'enrollment_status' ]: status = value.strip() elif name in ['graduated', 'graduated?']: graduated = self.determine_truth(value) elif name in [ 'graduation date', 'graduation_date' ]: graduation_date = self.convert_date(value) elif name in ['degree_title', 'degree title']: degree_title = value elif name in ['major']: major = value elif name in ['record_found', 'record_found_y/n']: record_found = self.determine_truth(value) if record_found: # First get or create college college, c_created = College.objects.get_or_create( code=code) if c_created: college.name = college_name college.state = state college.type = type college.save() if not graduated and begin: # Get or create enrollment based on secondary key model, created = CollegeEnrollment.objects.get_or_create( college=college, program_years=year, begin=begin, end=end, status=status, alumni=alumni, ) model.search_date = search_date model.graduated = graduated model.graduation_date = graduation_date model.degree_title = degree_title model.major = major model.full_clean() model.save() self.log_and_commit(model, addition=created) if created: inserted += 1 else: updated += 1 elif not alumni.college_override: # Graduated but no enrollment data alumni.graduated = graduated alumni.graduation_date = graduation_date if not alumni.college: alumni.college = college alumni.full_clean() alumni.save() self.log_and_commit(alumni, addition=alumni_created) if alumni_created: inserted += 1 else: updated += 1 else: self.log_and_commit(alumni, addition=alumni_created) if alumni_created: inserted += 1 else: updated += 1 except: if hasattr(sheet, 'name'): self.handle_error(row, name, sys.exc_info(), sheet.name) else: self.handle_error(row, name, sys.exc_info(), "Unknown") x += 1 return inserted, updated