def priority_user_import(sender, **kwargs): user = kwargs['instance'] if user.priority == PRIORITY_IMMEDIATE: post_save.disconnect(priority_user_import, sender=User) try: imp = Import(priority=user.priority, csv_type='user') imp.save() user.priority = PRIORITY_DEFAULT user.queue_id = imp.pk user.save() try: imp.csv_path = UserBuilder([user]).build() except: imp.csv_errors = traceback.format_exc() if imp.csv_path: imp.import_csv() else: user.queue_id = None user.priority = PRIORITY_HIGH user.save() imp.delete() except Exception, err: log.error('Immediate user provision failed: %s' % (err)) user.priority = PRIORITY_HIGH user.save() post_save.connect(priority_user_import, sender=User)
def priority_user_import(sender, **kwargs): user = kwargs['instance'] if user.priority == user.PRIORITY_IMMEDIATE: post_save.disconnect(priority_user_import, sender=User) try: imp = Import(priority=user.priority, csv_type='user') imp.save() user.priority = user.PRIORITY_DEFAULT user.queue_id = imp.pk user.save() try: imp.csv_path = UserBuilder([user]).build() except Exception: imp.csv_errors = traceback.format_exc() if imp.csv_path: imp.import_csv() else: user.queue_id = None user.priority = user.PRIORITY_HIGH user.save() imp.delete() except Exception as err: log.error('Immediate user provision failed: {}'.format(err)) user.priority = user.PRIORITY_HIGH user.save() post_save.connect(priority_user_import, sender=User)
def handle(self, *args, **options): imp = Import(csv_type="account") try: imp.csv_path = AccountBuilder().build() except Exception: imp.csv_errors = traceback.format_exc() imp.save() if imp.csv_path: imp.import_csv() self.update_job()
def handle(self, *args, **options): file_path = options.get('file_path') workshop_name = options.get('workshop_name') term_sis_id = options.get('term_sis_id') account_sis_id = options.get('account_sis_id') with open(file_path, 'r') as infile: file_data = infile.read() netids = file_data.splitlines() csvdata = Collector() for netid in netids: try: person = get_person_by_netid(netid.strip()) except UserPolicyException as err: print("Skipped user '{}': {}".format(netid, err)) continue if not csvdata.add(UserCSV(person)): continue course_sis_id = '-'.join([ term_sis_id, re.sub(r'[^\w]', '-', workshop_name.lower()), person.uwnetid ]) short_name = '{} {}'.format(date.today().year, workshop_name) long_name = '{} Sandbox'.format(short_name) csvdata.add( CourseCSV(course_id=course_sis_id, short_name=short_name, long_name=long_name, account_id=account_sis_id, term_id=term_sis_id, status='active')) csvdata.add( EnrollmentCSV(course_id=course_sis_id, person=person, role=get_instructor_sis_import_role(), status=ENROLLMENT_ACTIVE)) csv_path = csvdata.write_files() if csv_path: imp = Import(priority=Course.PRIORITY_DEFAULT, csv_type='course', csv_path=csv_path) imp.save() imp.import_csv()
def handle(self, *args, **options): if not len(args): raise CommandError("Usage: create_workshop_courses <path> " "<workshop_name><term_sis_id>") file_path = args[0] workshop_name = args[1] term_sis_id = args[2] account_sis_id = 'course-request-sandbox' with open(file_path, 'r') as infile: file_data = infile.read() netids = file_data.splitlines() csvdata = Collector() for netid in netids: try: person = get_person_by_netid(netid.strip()) except UserPolicyException as err: print "Skipped user %s: %s" % (netid, err) continue if not csvdata.add(UserCSV(person)): continue course_sis_id = '%s-%s-%s' % ( term_sis_id, re.sub(r'[^\w]', '-', workshop_name.lower()), person.uwnetid) short_name = '%s %s' % (workshop_name, date.today().year) long_name = '%s Sandbox' % short_name csvdata.add(CourseCSV( course_id=course_sis_id, short_name=short_name, long_name=long_name, account_id=account_sis_id, term_id=term_sis_id, status='active')) csvdata.add(EnrollmentCSV( course_id=course_sis_id, person=person, role=Enrollment.INSTRUCTOR_ROLE, status='active')) csv_path = csvdata.write() if csv_path: imp = Import(priority=PRIORITY_DEFAULT, csv_type='course', csv_path=csv_path) imp.save() imp.import_csv()