Esempio n. 1
0
def editprofile():

    # create a form object from the UserForm Class
    form = UserForm()
    # get the user object that is going to be edited which will be the current user so we user the
    # googleId from the active session to load the right record
    editUser = User.objects.get(gid=session['gid'])

    # If the user has already submitted the edit form and it is valid the the method form.validate_on_submit()
    # will be True and we can take the values from the form object and use them to update the database record
    # for that user
    if form.validate_on_submit():
        editUser.update(
            # the values to the left are the data attributes from the User data class
            # the values to the right are the values the user submitted via the form
            # that wtforms puts in to the form object
            fname=form.fname.data,
            lname=form.lname.data,
            pronouns=form.pronouns.data,
            birthdate=form.birthdate.data,
            personalemail=form.personalemail.data,
            mobile=form.mobile.data,
            address=form.address.data,
            city=form.city.data,
            state=form.state.data,
            zipcode=form.zipcode.data,
            socmedia=form.socmedia.data,
            nextyr=form.nextyr.data)
        print('valid form')
        if form.image.data:
            print('image data in form')
            print(editUser.image.delete())
            editUser.image.delete()
            editUser.image.put(form.image.data, content_type='image/jpeg')
            editUser.save()

        # after the profile is updated, send the user to the profile page
        return redirect(url_for('profile'))

    # if form.validate_on_submit() was false then we need to present the form back to the user pre-populated
    # with the values that the user is allowed to change
    # The values on the left are the values for each field in the form object
    # The values on the right are the values for the user object that was retrieved ealier in this function
    form.fname.data = editUser.fname
    form.lname.data = editUser.lname
    form.pronouns.data = editUser.pronouns
    form.image.data = editUser.image
    form.birthdate.data = editUser.birthdate
    form.personalemail.data = editUser.personalemail
    form.mobile.data = editUser.mobile
    form.address.data = editUser.address
    form.city.data = editUser.city
    form.state.data = editUser.state
    form.zipcode.data = editUser.zipcode
    form.socmedia.data = editUser.socmedia
    form.nextyr.data = editUser.nextyr

    # render the editprofile template and send the pre-populated form object.
    return render_template('editprofile.html', form=form, currUser=editUser)
Esempio n. 2
0
def editprofile():

    # create a form object from the UserForm Class
    form = UserForm()
    # get the user object that is going to be edited which will be the current user so we user the 
    # googleId from the active session to load the right record
    editUser = User.objects.get(gid=session['gid'])

    # If the user has already submitted the edit form and it is valid the the method form.validate_on_submit()
    # will be True and we can take the values from the form object and use them to update the database record 
    # for that user
    if form.validate_on_submit():
        editUser.update(
            # the values to the left are the data attributes from the User data class
            # the values to the right are the values the user submitted via the form 
            # that wtforms puts in to the form object
            fname = form.fname.data,
            lname = form.lname.data,
            pronouns = form.pronouns.data,
            image = form.image.data,
            birthdate = form.birthdate.data
        )

        # after the profile is updated, send the user to the profile page
        return redirect(url_for('profile'))

    # if form.validate_on_submit() was false then we need to present the form back to the user pre-populated
    # with the values that the user is allowed to change
    # The values on the left are the values for each field in the form object
    # The values on the right are the values for the user object that was retrieved ealier in this function
    form.fname.data = editUser.fname
    form.lname.data = editUser.lname
    form.pronouns.data = editUser.pronouns
    form.image.data = editUser.image
    form.birthdate.data = editUser.birthdate

    # render the editprofile template and send the pre-populated form object.
    return render_template('editprofile.html', form=form)
Esempio n. 3
0
def profile():
    
    currUser=User.objects.get(gid=session['gid'])
    form = UserForm()
    pform = ProfileForm()
    editUser = User.objects.get(gid=session['gid'])
    
    if pform.validate_on_submit():
        editUser.update(
            skills = pform.skills.data,
            country = pform.country.data,
            biography = pform.biography.data
        )
        
        return redirect(url_for('profile'))

    pform.skills.data = editUser.skills
    pform.biography.data = editUser.biography
    pform.country.data = editUser.country

    if form.validate_on_submit():
        editUser.update(
            fname = form.fname.data,
            lname = form.lname.data,
            pronouns = form.pronouns.data,
            birthday = form.birthday.data,
            gfname = session['gdata']['names'][0]['givenName'],
        )
        
        return redirect(url_for('profile'))

        form.fname.data = editUser.fname
        form.lname.data = editUser.lname
        form.pronouns.data = editUser.pronouns
        form.birthday.data = editUser.birthday
    
    return render_template("profile.html", currUser=currUser, data=session['gdata'], pform=pform, form=form, isIndex=False,isProfile=True)
Esempio n. 4
0
def editprofile(aeriesid=None):

    # create a form object from the UserForm Class
    form = UserForm()
    # get the user object that is going to be edited which will be the current user so we user the
    # googleId from the active session to load the right record

    if session['role'].lower() != 'student' and aeriesid:
        print('bob')
        editUser = User.objects.get(aeriesid=aeriesid)
    else:
        editUser = User.objects.get(gid=session['gid'])

    # first see if the form was posted and then reformat the phone numbers
    if request.method == 'POST':
        phvalid = []

        if form.mobile.data:
            response = phstr2int(form.mobile.data)
            if response[0]:
                form.mobile.data = response[1]
                phvalid.append(True)
            else:
                flash(
                    f"Mobile phone number {form.mobile.data} is not a phone number."
                )
                phvalid.append(False)
        else:
            form.mobile.data = None

        if form.altphone.data:
            response = phstr2int(form.altphone.data)
            if response[0]:
                form.altphone.data = response[1]
                phvalid.append(True)
            else:
                flash(
                    f"Other phone number {form.altphone.data} is not a phone number."
                )
                phvalid.append(False)
        else:
            form.altphone.data = None

    if form.validate_on_submit() and not False in phvalid:

        editUser.update(ufname=form.fname.data,
                        ulname=form.lname.data,
                        pronouns=form.pronouns.data,
                        ustreet=form.ustreet.data,
                        ucity=form.ucity.data,
                        ustate=form.ustate.data,
                        uzipcode=form.uzipcode.data,
                        mobile=form.mobile.data,
                        altphone=form.altphone.data,
                        personalemail=form.personalemail.data,
                        ugender=form.ugender.data,
                        uethnicity=form.uethnicity.data,
                        uethnicityother=form.uethnicityother.data,
                        linkedin=form.linkedin.data,
                        shirtsize=form.shirtsize.data)
        # Record edit datetime to user record
        userModified(editUser)

        if form.image.data:
            editUser.image.delete()
            editUser.image.put(form.image.data, content_type='image/jpeg')
            editUser.save()

        if editUser.ufname:
            fname = editUser.ufname
        else:
            fname = editUser.afname

        if editUser.ulname:
            lname = editUser.ulname
        else:
            lname = editUser.alname

        if fname != editUser.fname or lname != editUser.lname:
            editUser.update(fname=fname, lname=lname)

        # after the profile is updated, send the user to the profile page
        return redirect(url_for('profile', aeriesid=aeriesid))

    #if their is an expressed preferred value prefill the form with that otherwise use the one from aeries
    if editUser.ufname:
        form.fname.data = editUser.ufname
    else:
        form.fname.data = editUser.afname

    if editUser.ufname:
        form.lname.data = editUser.ulname
    else:
        form.lname.data = editUser.alname

    if editUser.ustreet:
        form.ustreet.data = editUser.ustreet
    else:
        form.ustreet.data = editUser.astreet

    if editUser.ustate:
        form.ustate.data = editUser.ustate
    else:
        form.ustate.data = editUser.astate

    if editUser.uzipcode:
        form.uzipcode.data = editUser.uzipcode
    else:
        form.uzipcode.data = editUser.azipcode

    if editUser.ucity:
        form.ucity.data = editUser.ucity
    else:
        form.ucity.data = editUser.acity

    form.pronouns.data = editUser.pronouns
    form.image.data = editUser.image
    form.personalemail.data = editUser.personalemail
    form.mobile.data = editUser.mobile
    form.altphone.data = editUser.altphone
    form.uethnicity.data = editUser.uethnicity
    form.uethnicityother.data = editUser.uethnicityother
    form.ugender.data = editUser.ugender
    form.linkedin.data = editUser.linkedin
    form.shirtsize.data = editUser.shirtsize

    # render the editprofile template and send the pre-populated form object.
    return render_template('editprofile.html', form=form, editUser=editUser)