Ejemplo n.º 1
0
def add_cs():
    '''
    创建解题员和客服
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    if current_user.type == Admin.ADMIN_TYPE.ADMIN:
        form = RegisterForm()
        if not form.validate_on_submit():
            print form.errors
            return render_template('admin/add_cs.html',
                                   form=form,
                                   nav_user_manage='active')
        try:
            if form.user_type.data == '0':
                cs = Admin(form.email.data, form.passwd.data, form.qq.data)
                ret = AdminBiz.add_CS(cs)
            else:
                solver = Admin(form.email.data, form.passwd.data, form.qq.data)
                ret = AdminBiz.add_solver(solver)
            success(ret)
        except DaixieError as e:
            fail(e)
            return render_template('admin/add_cs.html',
                                   form=form,
                                   nav_user_manage='active')
        return render_template('admin/add_cs.html',
                               form=form,
                               nav_user_manage='active')
    else:
        return redirect(url_for('general.index'))
Ejemplo n.º 2
0
def add_cs():
    '''
    创建解题员和客服
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    if current_user.type == Admin.ADMIN_TYPE.ADMIN:
        form = RegisterForm()
        if not form.validate_on_submit():
            print form.errors
            return render_template('admin/add_cs.html', form=form, nav_user_manage='active')
        try:
            if form.user_type.data=='0':
                cs = Admin(form.email.data, form.passwd.data, form.qq.data)
                ret = AdminBiz.add_CS(cs)
            else:
                solver = Admin(form.email.data, form.passwd.data, form.qq.data)
                ret = AdminBiz.add_solver(solver)
            success(ret)
        except DaixieError as e:
            fail(e)
            return render_template('admin/add_cs.html', form=form, nav_user_manage='active')
        return render_template('admin/add_cs.html', form=form, nav_user_manage='active')     
    else:
        return redirect(url_for('general.index'))
Ejemplo n.º 3
0
def delete_cs(id):
    '''
    delete cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    cs = AdminBiz.get_admin_by_id(id)
    try:
        ret = AdminBiz.delete_CS(cs=cs)
    except DaixieError as e:
        fail(e) 
    success(ret)
    return redirect(url_for('.cs_list'))
Ejemplo n.º 4
0
def delete_cs(id):
    '''
    delete cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    cs = AdminBiz.get_admin_by_id(id)
    try:
        ret = AdminBiz.delete_CS(cs=cs)
    except DaixieError as e:
        fail(e)
    success(ret)
    return redirect(url_for('.cs_list'))
Ejemplo n.º 5
0
def delete_solver(id):
    '''
    delete cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    solver = UserBiz.get_user_by_id(id)
    try:
        ret = UserBiz.delete_solver(solver)
        success(ret)
    except DaixieError as e:
        fail(e) 
    
    return redirect(url_for('.cs_list'))
Ejemplo n.º 6
0
def create_order():
    '''
    创建订单
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    form = OrderForm()
    if not form.validate_on_submit():
        return render_template('order/create.html', form=form, nav_order_manage='active')

    
    file = request.files['supp_info'] 
    if file :   
        if not allowed_file(file.filename):
            fail("file type error")
            return render_template('order/create.html', form=form, nav_order_manage='active')

    user = UserBiz.get_user_by_email(form.user_email.data)

    cs = AdminBiz.get_admin_by_email(form.cs_email.data)
    solverid = 0
    if form.solver_email.data:
        solver = AdminBiz.get_solver_by_email(form.solver_email.data)
        solverid = solver.id


    order = Order(user.id, cs.id, solverid, form.require_time.data, form.expect_time.data, 
        form.title.data, form.expect_hour.data, form.expect_order_price.data, form.grade.data, 0, \
        form.description.data, form.extra_item.data, form.extra_money.data, form.log.data)

    
    try:
        ret = OrderBiz.create_order(order)
    except DaixieError as e:
        fail(e)
        return render_template('order/create.html', form=form, nav_order_manage='active')   

    if file :
        order_id = order.id
        save_file_with_order_id(order_id, file)
        order.supp_info = secure_filename(file.filename)
    
    try:
        OrderBiz.edit_order(order)
    except DaixieError as e:
        fail(e)
        return render_template('order/create.html', form=form, nav_order_manage='active')

    success(ret)
    return redirect(url_for('.my_list'))
Ejemplo n.º 7
0
def delete_solver(id):
    '''
    delete cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    solver = UserBiz.get_user_by_id(id)
    try:
        ret = UserBiz.delete_solver(solver)
        success(ret)
    except DaixieError as e:
        fail(e)

    return redirect(url_for('.cs_list'))
Ejemplo n.º 8
0
def profile():
    '''
	个人信息
	'''
    form = ProfileForm(obj=current_user)
    if not form.validate_on_submit():
        return render_template('user/setting.html', form=form)
    user = current_user
    form.populate_obj(user)
    #修改个人信息
    try:
        ret = UserBiz.edit_user_profile(user)
        success(ret)
    except DaixieError as e:
        fail(e)
    return redirect(url_for('.profile'))
Ejemplo n.º 9
0
def profile():
	'''
	个人信息
	'''
	form = ProfileForm(obj=current_user)
	if not form.validate_on_submit():
		return render_template('user/setting.html', form=form)
	user = current_user
	form.populate_obj(user)
	#修改个人信息
	try:
		ret = UserBiz.edit_user_profile(user)
		success(ret)
	except DaixieError as e:
		fail(e)
	return redirect(url_for('.profile'))
Ejemplo n.º 10
0
def edit_order_for_admin(id):
    if not current_user.is_authenticated() :
        return redirect(url_for('general.index'))    
    if current_user.type != Admin.ADMIN_TYPE.ADMIN:
        fail(u"用户权限不足")
        return redirect(url_for('general.index'))

    order = OrderBiz.get_order_by_id(id).first()
    form = AdminEditOrderForm(obj=order)
    if not form.validate_on_submit():
        return render_template('order/edit_order_for_admin.html', form=form, id=id, order=order, nav_order_manage='active')
    
    file = request.files['supp_info']    
    
    cs = AdminBiz.get_admin_by_email(form.cs_email.data)
    solver = AdminBiz.get_solver_by_email(form.solver_email.data)

    order.cs_id = cs.id
    order.solver_id = solver.id
    print "order status:", order.status, "form status :", form.status.data
    if order.status>=1 and order.status <= form.status.data:
        order.status = form.status.data
    order.require_time = form.require_time.data
    order.expect_time = form.expect_time.data
    order.title = form.title.data
    order.description = form.description.data
    order.log = form.log.data
    order.grade = form.grade.data
    order.expect_hour = form.expect_hour.data
    order.actual_hour = form.actual_hour.data
    order.extra_item = form.extra_item.data
    if order.status == '3' and form.actual_order_price.data != 0 and form.actual_order_price.data is not None:
        order.actual_order_price = form.actual_order_price.data

    if file:
        save_file_with_order_id(id, file)
        order.supp_info = secure_filename(file.filename)

    #修改订单
    try:
        ret = OrderBiz.edit_order(order)
        success(ret)
    except DaixieError as e:
        fail(e)
        return render_template('order/edit_order_for_admin.html', form=form, id=id, order=order, nav_order_manage='active')

    return redirect(url_for('admin.home'))
Ejemplo n.º 11
0
def update_solver(id):
    '''
    update solver
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    solver=UserBiz.get_user_by_id(id);
    form = AccountForm();
    if not form.validate_on_submit():
        return render_template('admin/update.html', form=form, id=id, type="SOLVER", nav_user_manage='active')
    try:
        solver.passwd = form.passwd.data
        ret = UserBiz.solver_commit_update(solver=solver)
    except DaixieError as e:
        fail(e)
        return redirect(url_for('.cs_list'))     
    success(ret)
    return redirect(url_for('.cs_list')) 
Ejemplo n.º 12
0
def update_cs(id):
    '''
    update cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))    
    cs=AdminBiz.get_admin_by_id(id);
    form = AccountForm();
    if not form.validate_on_submit():
        return render_template('admin/update.html', form=form, id=id, type="CS", nav_user_manage='active')
    try:
        cs.passwd = form.passwd.data
        ret = AdminBiz.cs_commit_update(cs=cs)
    except DaixieError as e:
        fail(e)
        return redirect(url_for('.cs_list'))     
    success(ret)
    return redirect(url_for('.cs_list')) 
Ejemplo n.º 13
0
def login():
    '''
    登录
    '''
    form = LoginForm()
    if not form.validate_on_submit():
        return render_template('general/login.html', form=form, nav_login='******')
    email = form.email.data
    passwd = form.passwd.data
    auto = form.auto.data

    admin = Admin(email, passwd)
    try:
        ret = AdminBiz.admin_login(admin, auto)
    except DaixieError as e:
        fail(e)
        return render_template('general/login.html', form=form, nav_login='******')
    success(ret)
    return redirect(url_for('.index'))
Ejemplo n.º 14
0
def edit_order_for_cs(id):
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    if current_user.type != Admin.ADMIN_TYPE.CS:
        fail(u"用户权限不足")
        return redirect(url_for('general.index'))

    order = OrderBiz.get_order_by_id(id).first()
    form = CSEditOrderForm(obj=order)
    form.log.data = ''
    if not form.validate_on_submit():
        print "show order editing"
        return render_template('order/edit_order_for_cs.html', form=form, id=   id, order=order, nav_order_manage='active')
    
    file = request.files['supp_info']    
    if order.status>='1' and order.status <= form.status.data:
        order.status = form.status.data
    order.expect_time = form.expect_time.data
    order.title = form.title.data
    order.description = form.description.data
    order.log = order.log+form.log.data
    order.grade = form.grade.data
    order.expect_hour = form.expect_hour.data
    order.actual_hour = form.actual_hour.data

    if order.status == '3' and form.actual_order_price.data != 0 and form.actual_order_price is not None:
        order.actual_order_price = form.actual_order_price.data

    if file:
        save_file_with_order_id(id, file)
        print file.name
        order.supp_info = secure_filename(file.filename)

    #修改订单
    try:
        ret = OrderBiz.edit_order(order)
        success(ret)
    except DaixieError as e:
        fail(e)
        return render_template('order/edit_order_for_cs.html', form=form, id=id, order=order, nav_order_manage='active')

    return redirect(url_for('admin.home'))
Ejemplo n.º 15
0
def update_cs(id):
    '''
    update cs
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    cs = AdminBiz.get_admin_by_id(id)
    form = AccountForm()
    if not form.validate_on_submit():
        return render_template('admin/update.html',
                               form=form,
                               id=id,
                               type="CS",
                               nav_user_manage='active')
    try:
        cs.passwd = form.passwd.data
        ret = AdminBiz.cs_commit_update(cs=cs)
    except DaixieError as e:
        fail(e)
        return redirect(url_for('.cs_list'))
    success(ret)
    return redirect(url_for('.cs_list'))
Ejemplo n.º 16
0
def update_solver(id):
    '''
    update solver
    '''
    if not current_user.is_authenticated():
        return redirect(url_for('general.index'))
    solver = UserBiz.get_user_by_id(id)
    form = AccountForm()
    if not form.validate_on_submit():
        return render_template('admin/update.html',
                               form=form,
                               id=id,
                               type="SOLVER",
                               nav_user_manage='active')
    try:
        solver.passwd = form.passwd.data
        ret = UserBiz.solver_commit_update(solver=solver)
    except DaixieError as e:
        fail(e)
        return redirect(url_for('.cs_list'))
    success(ret)
    return redirect(url_for('.cs_list'))