Example #1
0
def account_settings():
    '''账户设置,包括改密码等'''
    user = current_user
    form = ProfileForm(formdata=request.form, obj=user)
    errors = []
    if form.validate_on_submit():
        username = form['username'].data.strip()
        if username == user.username:
            pass
        elif User.query.filter_by(username=username).all():
            errors.append(
                _("Sorry, the username " + username + " has been taken!"))
        else:
            user.username = username

        user.homepage = form['homepage'].data.strip()
        if not user.homepage.startswith('http'):
            user.homepage = 'http://' + user.homepage
        user.description = form['description'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok, info = handle_upload(avatar, 'image')
            if ok:
                user.set_avatar(resize_avatar(info))
            else:
                errors.append(_("Avatar upload failed"))
        user.save()
    return render_template('settings.html',
                           user=user,
                           form=form,
                           errors=errors)
Example #2
0
def edit_profile(teacher_id):
    if not current_user.is_admin:
       abort(403)
    teacher = Teacher.query.get(teacher_id)
    form = TeacherProfileForm(request.form, teacher)
    errors = []
    if form.validate_on_submit():
        #teacher.gender = form['gender'].data
        form['homepage'].data = form['homepage'].data.strip()
        if not form['homepage'].data.startswith('http'):
            form['homepage'].data = 'http://' + form['homepage'].data
        teacher.homepage = form['homepage'].data.strip()
        teacher.description = form['description'].data.strip()
        teacher.research_interest = form['research_interest'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok,info = handle_upload(avatar,'image')
            if ok:
                teacher.set_image(info)
            else:
                errors.append(_("Avatar upload failed"))
        teacher.save()
        db.session.commit()
        return redirect(url_for('teacher.view_profile', teacher_id=teacher.id))
    return render_template('teacher-settings.html', teacher=teacher, errors=errors, form=form)
Example #3
0
def edit_profile(teacher_id):
    teacher = Teacher.query.get(teacher_id)
    form = TeacherProfileForm(formdata=request.form, obj=teacher)
    errors = []
    if form.validate_on_submit():
        #teacher.gender = form['gender'].data
        form['homepage'].data = form['homepage'].data.strip()
        if not form['homepage'].data.startswith('http'):
            form['homepage'].data = 'http://' + form['homepage'].data
        teacher.homepage = form['homepage'].data.strip()
        teacher.description = form['description'].data.strip()
        teacher.research_interest = form['research_interest'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok, info = handle_upload(avatar, 'image')
            if ok:
                teacher.set_image(info)
            else:
                errors.append(_("Avatar upload failed"))
        teacher.save()

        info_history = TeacherInfoHistory()
        info_history.save(teacher, current_user)

        return redirect(url_for('teacher.view_profile', teacher_id=teacher.id))
    return render_template('teacher-settings.html',
                           teacher=teacher,
                           errors=errors,
                           form=form)
Example #4
0
def generic_upload(file, type):
    ok, message = handle_upload(file, type)
    script_head = '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction(2,'
    script_tail = ');</script>'
    if ok:
        url = '/uploads/' + type + 's/' + message
        return script_head + '"' + url + '"' + script_tail
    else:
        return script_head + '""' + ',' + '"' + message + '"' + script_tail
Example #5
0
def generic_upload(file, type):
    ok,message = handle_upload(file, type)
    script_head = '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction(2,'
    script_tail = ');</script>'
    if ok:
        url = '/uploads/' + type + 's/' + message
        return script_head + '"' + url + '"' + script_tail
    else:
        return script_head + '""' + ',' + '"' + message + '"' + script_tail
Example #6
0
def account_settings():
    '''账户设置,包括改密码等'''
    user = current_user
    form = ProfileForm(request.form, user)
    if form.validate_on_submit():
        #user.username = form['username'].data
        #user.gender = form['gender'].data
        user.homepage = form['homepage'].data.strip()
        if not user.homepage.startswith('http'):
            user.homepage = 'http://' + user.homepage
        user.description = form['description'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok,info = handle_upload(avatar,'image')
            if ok:
                user.set_avatar(info)
            else:
                errors.append(_("Avatar upload failed"))
        user.save()
    return render_template('settings.html', user=user, form=form)