[docs]classCommand(BaseCommand):help="Update counselor information"defadd_arguments(self,parser):parser.add_argument("filename",type=str,help="Path to SIS import CSV with a Student ID and Counselor column")parser.add_argument("--run",action="store_true",dest="run",default=False,help="Actually modifies the DB")defhandle(self,*args,**kwargs):data=[]# We assume that the provided file has up-to-date information.# DO NOT RUN IF YOU DON'T HAVE UP-TO-DATE INFORMATIONfilename=kwargs["filename"]to_run=kwargs["run"]ifnotto_run:sys.stdout.write("This script is running in pretend mode.\n")sys.stdout.write("Pass --run to actually run this script.\n")sys.stdout.write("Please MAKE SURE you have updated info before running this script.\n")sys.stdout.write("Actually running is a destructive operation.\n")withopen(filename,encoding="utf-8")asf:contents=csv.DictReader(f)data=list(contents)counselors=get_user_model().objects.filter(user_type="counselor")forrowindata:sid=row["Student ID"].strip()# We assume that every single counselor has a unique last name# If this is not true, please edit this filecounselor=row["Counselor"].split(",")[0].strip()counselor=counselors.get(last_name=counselor)u=get_user_model().objects.user_with_student_id(sid)ifuisNone:sys.stdout.write(f"There is no Ion account found for SID {sid}\n")continueifcounselor!=u.counselor:sys.stdout.write(f"Switching counselor for SID {sid} from {u.counselor} to {counselor}\n")ifto_run:u.counselor=counseloru.save()