def signup_au_get(req): ''' handles signup form submission. Add a new signup instance to the db using utils.create_signup ''' form = req.GET # get static fields firstname = form.get('firstname') lastname = form.get('lastname') username = form.get('username') email = form.get('email') courses = [] for c in settings.COURSES: if form.get(c): courses.append(form.get(c)) for c in settings.COURSES_MANDATORY: courses.append(c) utils.create_signup(firstname, lastname, email, username, courses) # get a thank-you message to the user return redirect('/thanks/')
def courseman_courses_post(req): ''' create a new course from a template, enroll a user as teacher (and possibly create the user) ''' form = req.POST tmpl = form['tmpl_selector'] site = form['tbx_site'] shortname = form['field_shortname'] title = form['tbx_title'] m = re.match('\-\-\sselect\sfrom', shortname) if site != '' and shortname != '' and title != '' and not m: (backupname, courseid, status) = mu.create_course_from_template(templatename=tmpl, shortname=shortname, fullname=title) else: req.session['message'] = 'Please select a proper template and a course name.' return redirect('/coursemanage/courses') username = form['tbx_username'] firstname = form['tbx_firstname'] lastname = form['tbx_lastname'] email = form['tbx_email'] if username == '': req.session['message'] = 'Please assign a teacher for the course.' return redirect('/coursemanage/courses') if firstname != '' or email != '': if firstname == '' or email == '': req.session['message'] = 'New user creation requires a name and an email.' return redirect('/coursemanage/courses') teacher = utils.create_signup(firstname, lastname, email, username, []) utils.adduser(teacher, ldap_password=req.session['ldap_password']) # TODO: implement error handling for this case, if the user doesn't exist and no info was provided mu.enroll_user(username=username, course_sn=shortname, teacher=True) req.session['message'] = 'Course %s created with teacher %s. Restoring contents in background...' % (shortname, username) return redirect('/coursemanage/courses')