Esempio n. 1
0
def index():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    title = profile_user.name + u'的主页'
    statistic = user_server.get_statistic(profile_user)
    user_modify_form = form.UserModifyForm()
    user_modify_form.id.data = profile_user.id
    user_modify_form.name.data = profile_user.name
    user_modify_form.stu_id.data = profile_user.stu_id
    user_modify_form.email.data = profile_user.email
    user_modify_form.phone.data = profile_user.phone
    user_modify_form.motto.data = profile_user.remark
    user_modify_form.situation.data = profile_user.situation
    user_modify_form.school.data = profile_user.school
    user_modify_form.college.data = profile_user.college
    user_modify_form.grade.data = profile_user.grade
    user_modify_form.gender.data = '1' if profile_user.gender else '0'
    user_modify_form.active.data = '1' if profile_user.active else '0'
    pwd_modify_form = form.PasswordModifyForm()
    pwd_modify_form.id.data = profile_user.id
    return render_template('index.html',
                           title = title,
                           user = profile_user,
                           user_modify_form = user_modify_form,
                           pwd_modify_form = pwd_modify_form,
                           statistic = statistic,
                           school_mapper = SCHOOL_MAP,
                           college_mapper = SCHOOL_COLLEGE_MAP)
Esempio n. 2
0
def account_manager():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    account_form = form.AccountForm()
    if current_user != profile_user and\
            (not current_user.is_admin and not current_user.is_coach_of(profile_user)):
        return u"没有权限"
    if account_form.validate_on_submit():
        try:
            has_account = Account.query\
                    .filter_by(user=profile_user, oj_name=account_form.oj_name.data)\
                    .first()
            if has_account:
                account_server.modify_account(has_account, account_form)
                return u"ok"
            else:
                account_server.add_account(profile_user, account_form)
                return u"ok"
        except AccountUpdatingException, e:
            current_app.logger.error(traceback.format_exc())
            return 'ERROR: ' + e.message
        except AccountExistException, e:
            current_app.logger.error(traceback.format_exc())
            return 'ERROR: ' + e.message
Esempio n. 3
0
def account_info_list():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    account_info_list = account_server.get_account_info_list(profile_user)
    return jsonify(account_list = [get_account_item(account_info, profile_user) for account_info in account_info_list],
                   length = len(account_info_list))
Esempio n. 4
0
def update_account():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    if current_user == profile_user or current_user.is_admin or current_user.is_coach:
        general.update_all_account_status(profile_user)
    return redirect(url_for('profile.index', username=profile_user.username))
Esempio n. 5
0
def manage_account():
    try:
        profile_user = user_server.get_by_username_or_404(request.args["username"])
    except:
        profile_user = current_user
    if current_user != profile_user and (not current_user.is_admin and not current_user.is_coach_of(profile_user)):
        return u"没有权限"
    account_form = form.AccountForm()
    return render_template("manage_account.html", title=u"OJ 账号管理", form=account_form, user=profile_user)
Esempio n. 6
0
def manage_account():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    if current_user != profile_user and (not current_user.is_admin and not current_user.is_coach_of(profile_user)):
        return u"没有权限"
    account_form = form.AccountForm()
    return render_template('manage_account.html',
                           title = u'OJ 账号管理',
                           form = account_form,
                           user = profile_user)
Esempio n. 7
0
def solution_manager():
    try:
        profile_user = user_server.get_by_username_or_404(request.args['username'])
    except:
        profile_user = current_user
    solution_form = form.SolutionForm()
    if solution_form.validate_on_submit():
        try:
            is_draft = int(request.args['draft'])
            article_server.post(solution_form, profile_user, is_draft)
            return u"发表成功!"
        except Exception, e:
            return u"发表文章失败" + e.message