def create_author(publication, name): if not publication.author: fname, mname, lname = split_name(name) hits = 0 emp = None institute = Institution.objects.get(name='Memorial Sloan-Kettering Cancer Center') hits = Employee.objects.filter(last_name__iexact=lname, first_name__istartswith=fname[:1]).count() if hits == 0: # No employee record found if publication.institution: emp = Employee.objects.create(first_name=fname, middle_name=mname, last_name=lname, currently_employed=False) elif hits == 1: # Suitable employee emp = Employee.objects.get(last_name__iexact=lname, first_name__istartswith=fname[:1]) elif hits > 1: # Too many hits -- punt to human, don't guess return None if emp: publication.author = emp if not publication.institution: publication.institution = institute publication.save()
def create_author(publication, name): if not publication.author: fname, mname, lname = split_name(name) hits = 0 emp = None institute = Institution.objects.get( name='Memorial Sloan-Kettering Cancer Center') hits = Employee.objects.filter( last_name__iexact=lname, first_name__istartswith=fname[:1]).count() if hits == 0: # No employee record found if publication.institution: emp = Employee.objects.create(first_name=fname, middle_name=mname, last_name=lname, currently_employed=False) elif hits == 1: # Suitable employee emp = Employee.objects.get(last_name__iexact=lname, first_name__istartswith=fname[:1]) elif hits > 1: # Too many hits -- punt to human, don't guess return None if emp: publication.author = emp if not publication.institution: publication.institution = institute publication.save()
def create_new_employees(self): """creates any employees that are not already in the database""" for row in self.get_reader(): fname, mname, lname = split_name(row['NAME']) employee, employee_created = Employee.objects.get_or_create(emp_id=row['EMPLID'], defaults={'first_name': fname, 'middle_name':mname, 'last_name': lname, 'job_title': row['JOB_TITLE']}) print "Employee:", employee print "Employee Created: ", employee_created department = Department.objects.get(cost_center=row['DEPTID']) EmployeeDepartment.objects.get_or_create(employee=employee, department=department) return None
def create_new_employees(self): """creates any employees that are not already in the database""" for row in self.get_reader(): fname, mname, lname = split_name(row['NAME']) employee, employee_created = Employee.objects.get_or_create( emp_id=row['EMPLID'], defaults={ 'first_name': fname, 'middle_name': mname, 'last_name': lname, 'job_title': row['JOB_TITLE'] }) print "Employee:", employee print "Employee Created: ", employee_created department = Department.objects.get(cost_center=row['DEPTID']) EmployeeDepartment.objects.get_or_create(employee=employee, department=department) return None