Пример #1
0
def edit_profile():
    """ Edit users profile endpoint. """

    # Create the edit profile form.
    form = EditProfileForm()

    # POST Request
    if form.validate_on_submit():
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash("Your changes have been saved.")
        return redirect(url_for('main.edit_profile'))
    elif request.method == 'GET':
        form.about_me.data = current_user.about_me

    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #2
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.note = form.note.data
        res = mysql.Mod("user", {"id": current_user.id}, {
            "username": "******" % current_user.username,
            "note": "'%s'" % current_user.note
        })
        if res != 0:
            flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.note.data = current_user.note
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #3
0
def edit_profile():
    form = EditProfileForm(current_user.username)

    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()

        flash('Your changes have been saved')
        return redirect(url_for('edit_profile'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me

    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #4
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.data
        current_user.api_key = form.consumer_key.data
        current_user.api_secret = form.consumer_secret.data
        db.session.commit()
        flash('Your changes have been made')
        return redirect(request.referrer)
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
        form.consumer_key.data = current_user.api_key
        form.consumer_secret.data = current_user.api_secret
    return render_template('edit_profile.html', title='Edit Profile', form=form)
Пример #5
0
def edit_profile():
    form = EditProfileForm(original_username=current_user.username)
    if form.validate_on_submit():
        # If validation passes, update db with form contents (POST)
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()  # Again .add not needed since current_user called
        flash("Your changes have been saved.")
        return redirect(url_for('user', username=current_user.username))
    elif request.method == 'GET':
        # If we're just doing a GET for the initial form pre-submit,
        # then pre-pop with current info.
        # Otherwise this is a POST with failed validation: don't do anything.
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit-profile.html',
                           title='Edit Profile',
                           form=form)
Пример #6
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        username = form.username.data
        about_me = form.about_me.data
        u = User.query.filter(User.username == username).first()
        u.about_me = about_me
        db.session.commit()
        flash('Your changes have been saved.', 'yes')
        return redirect('/user/' + username)
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    data = {'username': current_user.username}
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form,
                           data=data)
Пример #7
0
def edit_profile():
    """
    Gives the user a form to edit their profile and updates the information in the database.
    """
    form = EditProfileForm()

    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data

        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user', username=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me

    return render_template('edit_profile.html', form=form)
Пример #8
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        if (form.male.data):
            current_user.gender = 'male'
        else:
            current_user.gender = 'female'
        current_user.name = form.name.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Ваши изменения были сохранены.')
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.name.data = current_user.name
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #9
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))

    # If the browser sent a GET request, we need to respond by providing initial version of the
    # form template. It can also be when the browser sends a POST request with form data, but some
    # in that is invalid.
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #10
0
def user(username):
    if CLOSE_WEBSITE:
        return redirect(url_for('index'))
    else:
        user = User.query.filter_by(username=username).first_or_404()

        form = EditProfileForm(current_user.username)
        if form.validate_on_submit():
            current_user.username = form.username.data
            current_user.comments = form.comments.data
            db.session.commit()
            flash('Your changes have been saved.')
            return redirect(url_for('user',username=current_user.username))
        elif request.method == 'GET':
            form.username.data = current_user.username
            form.comments.data = current_user.comments

        return render_template('user.html', user=user, form=form, debug=app.debug)
Пример #11
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    form.languages.choices = [(language.id, language.language)
                              for language in Language.query.all()]
    if form.validate_on_submit():
        if form.languages.data in current_user.languages:
            flash(_('The chosen language is already chosen'))
        else:
            current_user.username = form.username.data
            dictionary = Dictionary(user_id=current_user.id,
                                    language_id=form.languages.data)
            db.session.add(dictionary)
            db.session.commit()
            flash(_('Your changes have been saved!'))
        return redirect(url_for('edit_profile'))
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #12
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        # u=User.query.filter_by(username=form.username.data).first()
        # if(u is None):
        current_user.username = form.username.data
        # else:
        #     flash("This username is taken.\n Try another one.")

        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #13
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    # if profile is edited without any errors, submit and save to db.
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash(_("Your changes have been saved."))
        return redirect(url_for("edit_profile"))
    # if the user has just navigated to this page ("GET" request), display it
    # with the user's data in its current state (i.e., this "prefills" form).
    elif request.method == "GET":
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    # if the user tried to submit ("POST"), but there were errors, display a
    # blank profile editor page.
    return render_template("edit_profile.html",
                           title=_("Edit Profile"),
                           form=form)
Пример #14
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    #if submit was clicked
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
#if requesting the page for the first time
#retrieve current values from db
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me

#if something wrong then write nothing ie request.methon="POST"
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #15
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        connection = db.engine.raw_connection()
        cursor = connection.cursor()
        cursor.execute("update user set username = '******' where username = '******'")
        cursor.execute("update user set about_me = '" + form.about_me.data +
                       "' where username = '******'")
        connection.commit()
        connection.close()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #16
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.email = form.email.data
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        password = request.form.get('password', None)
        if password is None:
            db.session.commit()
        else:
            current_user.set_password(form.password.data)
            db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
        form.email.data = current_user.email
    return render_template('edit_profile.html', title='Edit Profile', form=form)
Пример #17
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        if not form.Profile_Pic.data == None:
            pp = form.Profile_Pic.data
            filename = str(current_user.id) + '.jpg'
            pp.save(os.path.join(app.config['PP_PATH'], filename))
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('你的提交已变更.')
        return redirect(url_for('user', username=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='个人资料编辑',
                           form=form,
                           user=current_user)
Пример #18
0
def edit_profile():
    form = EditProfileForm(request.form)
    if request.method == 'POST':
        current_user.username = form.username.data
        current_user.name = form.name.data
        current_user.email = form.email.data
        current_user.phone_num = form.phone_num.data

        db.session.commit()
        flash('Ваши изменения применены')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.name.data = current_user.name
        form.email.data = current_user.email
        form.phone_num.data = current_user.phone_num

    return render_template('edit_profile.html', title='Редактировать профиль',
                           form=form)
Пример #19
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    # 如果validate_on_submit()返回为True,将表单中的数据复制到用户对象中,然后将对象写入到数据库中
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash(
            'Your have changed your profile and Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    # 若validate_on_submit()返回为False:
    #   可能是因为浏览器刚刚发送了一个GET请求,我们需要通过提供表单模板的初始版本来响应
    #   也可能是因为浏览器发送带有表单数据的POST请求,但该数据中的某些内容无效
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #20
0
def edit_profile():
    """
    Here the edit profile page is handled.
    The user can change it's username and it's about page.
    """
    # We pass the current user to the form for the validation.
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #21
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    image_file = url_for('static',
                         filename='images/' + current_user.image_file)
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #22
0
def edit_profile():
    if current_user.type == 'student':
        return redirect(url_for('manage'))
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        current_user.name = form.name.data
        current_user.departments = form.departments.data
        db.session.commit()
        flash (_('Your changes have been saved.'))
        return redirect(url_for('manage'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
        form.name.data = current_user.name
        form.departments.data = current_user.departments

    return render_template('edit_profile.html', title=_('Edit Profile'), form=form)
Пример #23
0
def edit_profile():
    """!
    Обработчик маршрута страницы редактирования профиля пользователя (edit_profile).

    @return Страницу edit_profile.html.
    """
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Изменения были сохранены.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Редактирование профиля',
                           form=form)
Пример #24
0
def avatar_set(username):
    username = current_user.username
    form = EditProfileForm()
    if form.validate_on_submit():
        file = form.avatar.data

        # filename = secure_filename(file.filename)
        if file and allowed_file(file):
            upload_path = os.path.join(app.config['UPLOAD_FOLDER'],
                                       "{}.jpg".format(current_user.id))
            file.save(
                os.path.join(app.config['UPLOAD_FOLDER'],
                             "{}.jpg".format(current_user.id)))
            current_user.avatar = "{}.jpg".format(current_user.id)
            db.session.commit()
            # set_avatar(current_user.id, "{}.jpg".format(current_user.id))
            return redirect(url_for('userpage', username=username))

    return render_template('upload_avatar.html', title='上传你的头像把', form=form)
Пример #25
0
def edit_profile():

    #form表单中传入参数,用来验证当前编辑的用户名
    form = EditProfileForm(current_user.username)
    '''
    当我们点击了表单上的提交按钮时,form.validate_on_submit()判断会做下面两件事情:
    1、通过is_submitted()通过判断HTTP方法来确认是否提交了表单
    2、通过WTForms提供的validate()来验证表单数据(使用我们在下面的表单类里给每个字段传入的验证函数)
    '''
    if form.validate_on_submit():
        current_user.username=form.username.data
        current_user.about_me=form.about_me.data
        db.session.commit()
        flash('Your changes has been saved')
        return redirect(url_for('edit_profile'))
    elif request.method=='GET':
        form.username.data=current_user.username
        form.about_me.data=current_user.about_me
        return render_template('edit_profile.html',title='Edit Profile',form=form)
Пример #26
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        current_user.zipcode = form.zipcode.data
        filename = images.save(request.files['image'])
        current_user.image_filename = filename
        current_user.image_url = images.url(filename)
        db.session.commit()
        flash(_('Your changes have been saved!'))
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
        form.zipcode.data = current_user.zipcode
    return render_template('edit_profile.html',
                           title=_('Edit Profile'),
                           form=form)
Пример #27
0
def edit_profile():
    form = EditProfileForm(current_user.username)  # Fix duplicate username bug
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Yours changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)

    # follow user
    @app.route('/follow/<username>')
    @login_required
    def follow(username):
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('user {} not found.'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            flash('Do you really want to follow yourself?')
            return redirect(url_for('user', username=username))
        current_user.follow(user)
        db.session.commit()
        flash('You are now following {} <:'.format(username))

    # unfollow user
    def unfollow(username):
        user = User.query.filter_by(username=username).first()
        if user is None:
            flash('User {} not found.'.format(username))
            return redirect(url_for('index'))
        if user == current_user:
            flash('You cannot unfollow yourself!')
            return redirect(url_for('user', username=username))
        current_user.unfollow(user)
        db.session.commit()
        flash('You are no longer following {}.'.format(username))
        return redirect(url_for('user', username=username))
Пример #28
0
def edit_profile():
    '''
    Renders the edit_profile template. If validate_on_submit() returns True,
    database is updated with data from the form and a message is displayed. 
    If validate_on_submit() returns False, checks if it was a GET request in which 
    case the initial version of the form template is provided. 
    '''
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #29
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.phone = form.phone.data
        current_user.email = form.email.data
        current_user.alerts = form.alerts.data
        current_user.newsletter = form.alerts.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.phone.data = current_user.phone
        form.email.data = current_user.email
        form.alerts.data = current_user.alerts
        form.newsletter.data = current_user.newsletter
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Пример #30
0
def edit_profile():  # !!!!!!!!!

    #if current_user.is_authenticated:   # make sure that the user is not logged
     #   return redirect(url_for('edit_profile'))

    form_edit = EditProfileForm(current_user.username)
    if form_edit.validate_on_submit():
        current_user.username = form_edit.username.data
        current_user.about_me = form_edit.about_me.data
        new_user = User(username=form_edit.username.data, about_me=form_edit.username.data)
        db.session.add(new_user)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':

        form_edit.username.data = current_user.username
        form_edit.about_me.data = current_user.about_me
    return render_template('edit_profile.html', title='Edit Profile',
                           form=form_edit)