コード例 #1
0
def studentUpdate(email):
    conn = clickDatabase.getConn('clickdb')
    studentInfo = clickDatabase.getStudent(conn, email)
    skills = clickDatabase.studentSkills(conn, email)
    #if GET, renders page with given information as default values in form
    if request.method == 'GET':
        return render_template('studentUpdate.html',
                               name=studentInfo['name'],
                               email=studentInfo['email'],
                               active=studentInfo['active'],
                               skills=skills)
    #if POST, updates profile
    else:
        # if student updates name, email, or active status
        if request.form['submit'] == 'Update Personal Information':
            newName = request.form.get('studentName')
            newEmail = request.form.get('studentEmail')
            newActive = request.form.get('studentActive')
            clickDatabase.updateStudentProfile(conn, email, newEmail, newName,
                                               newActive)
            flash("Profile successfully updated")
            return redirect(url_for('studentUpdate', email=newEmail))
        # if student removes a skill
        elif request.form['submit'] == 'Remove':
            skill = request.form.get('skill')
            clickDatabase.removeSkill(conn, email, skill)
            return redirect(
                url_for('studentUpdate', email=studentInfo['email']))
        #adding skill
        elif request.form['submit'] == 'Add skill':
            #try and except to handle errors if user tries to enter a
            #skill they've already added to their profile
            try:
                newSkill = request.form.get('newSkill')
                clickDatabase.addSkill(conn, email, newSkill)
                return redirect(
                    url_for('studentUpdate', email=studentInfo['email']))
            except:
                flash("Error. Skill may already be in your profile.")
                return redirect(
                    url_for('studentUpdate', email=studentInfo['email']))
        else:
            return redirect(
                url_for('studentProfile', email=studentInfo['email']))
コード例 #2
0
def studentProfile(email):
    studentInfo = clickDatabase.getStudent(conn, email)
    skills = clickDatabase.studentSkills(conn, email)
    #if GET, renders page with all information about student in database
    if request.method == 'GET':
        return render_template('studentProfile.html',
                            name = studentInfo['name'],
                            email = studentInfo['email'],
                            skills = skills)
    #if POST, either adding or removing a skill
    else:
        #removing skill
        if request.form['submit'] == 'Remove':
            skill = request.form.get('skill')
            clickDatabase.removeSkill(conn, email, skill)
            return redirect(url_for('studentProfile',
                            email = studentInfo['email']))
        #adding skill
        else:
            newSkill = request.form.get('newSkill')
            clickDatabase.addSkill(conn, email, newSkill)
            return redirect(url_for('studentProfile',
                            email = studentInfo['email']))