def submit_enroll(): """ Enroll someone in this course. """ username = request.form['username'] rolename = request.form['submit_enroll'] print_debug(' submit_enroll: user={}, role={}'.format(username, rolename)) user = Person.by_username(username) request.page.course.enroll(user, rolename, create_work=(rolename == 'student')) return request.page.url
def make_courses(csvfilename='courses_jan2018.csv'): """ create courses from a .csv file defining them """ # csvfile : name, name_as_title, path, faculty for row in csv.DictReader(open(csvfilename)): course = Course.create_course(name=row['name'], name_as_title=row['name_as_title'], path=row['path'], start=term, copy_generic=True) faculty = Person.by_username(row['faculty']) course.enroll(faculty, 'faculty', spring2018)
def submit_login(): """ handle <input name='submit_login' ...> form submission. """ # invoked from handle_post() print_debug(' submit_login: username = "******" '.format( request.form['username'])) user = Person.by_username(request.form['username']) print_debug(' submit_login: user = "******"'.format(user)) if user.is_anonymous() or \ not user.check_password(request.form['password']): flash('Oops: wrong username or password.', 'login') return url_for('mainroute', pagepath=request.page.path, action='login') else: user.logged_in = True login_user(user) return url_for('mainroute', pagepath=request.page.path)
def load_user(user_session_id): """ Return Person corresponding to unicode session id, or None. """ # see flask-login.readthedocs.org/en/latest/#flask.ext.login.LoginManager user = Person.by_username(user_session_id) # TODO : set logged_in and role correctly ... save in database?? return user