Exemplo n.º 1
0
def j_search_user():
    email = request.args.get('email', '')
    query = request.args.get('query', '')
    page = get_arg('page', 1)
    type = request.args.get('type', '')
    #print "query is ",query

    if (type == 'user'):
        type = User.USER_TYPE.USER

    try:
        if email:
            user = UserBiz.get_user_by_email(email, type)
            users_pager = Pagination(None, 1, 1, 1, [user])
        else:
            users_pager = UserBiz.get_by_like(query, type, page, per_page=10)
    except DaixieError as e:
        return j_err(e)

    users = [{
        'id': user.email,
        'text': user.email,
        'account': user.account
    } for user in users_pager.items if user]

    return j_ok(u'搜索成功', items=users, pages=users_pager.pages)
Exemplo n.º 2
0
	def edit_order(order):
		o = OrderBiz.get_order_by_id(order.id).first()
		user = UserBiz.get_user_by_id(order.user_id)

		if o is None:
			raise DaixieError(ORDER_NOT_EXIST)

		if o.status >= '1' and order.actual_order_price != 0:
			try:
				amount = float(o.expect_order_price)-float(order.actual_order_price)
				if amount>0:
					UserBiz.refund(o.user_id, abs(amount), type=Transaction.TYPE.REFUND, description=u'订单最终价格调整')
				else:
					if user.account < abs(amount):
						raise DaixieError(u'用户的余额不足,无法填写订单实际价格,修改失败')
					UserBiz.recharge(o.user_id, abs(amount), type=Transaction.TYPE.PAY, description=u'订单最终价格调整')
			except DaixieError as e:
				raise e

		try:
			db_session.add(order)
			db_session.commit()
		except:
			raise DaixieError(EDIT_ORDER_FAIL)
		return EDIT_ORDER_OK
Exemplo n.º 3
0
def j_search_user():
	email = request.args.get('email', '')
	query = request.args.get('query', '')
	page = get_arg('page', 1)
	type = request.args.get('type', '')
	#print "query is ",query

	if(type == 'user'):
		type = User.USER_TYPE.USER

	try:
		if email:
			user = UserBiz.get_user_by_email(email, type)
			users_pager = Pagination(None, 1, 1, 1, [user])
		else:
			users_pager = UserBiz.get_by_like(query, type, page, per_page=10)
	except DaixieError as e:
		return j_err(e)

	users = [{
	'id': user.email,
	'text': user.email,
	'account': user.account
	} for user in users_pager.items if user]

	return j_ok(u'搜索成功', items=users, pages=users_pager.pages)
Exemplo n.º 4
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'))
Exemplo 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'))
Exemplo n.º 6
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')) 
Exemplo n.º 7
0
def cs_list():
    '''
    
    '''
    if current_user.type == Admin.ADMIN_TYPE.ADMIN:
        all_cs = AdminBiz.get_all_CS();
        all_user = UserBiz.get_all_user();
        return render_template('admin/cs_list.html', cs_list=all_cs, user_list=all_user, nav_user_manage='active')
    else:
        return redirect(url_for('general.index'))
Exemplo n.º 8
0
def cs_list():
    '''
    
    '''
    if current_user.type == Admin.ADMIN_TYPE.ADMIN:
        all_cs = AdminBiz.get_all_CS()
        all_user = UserBiz.get_all_user()
        return render_template('admin/cs_list.html',
                               cs_list=all_cs,
                               user_list=all_user,
                               nav_user_manage='active')
    else:
        return redirect(url_for('general.index'))
Exemplo n.º 9
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'))
Exemplo n.º 10
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'))
Exemplo n.º 11
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'))
Exemplo n.º 12
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'))
Exemplo n.º 13
0
 def __call__(self, form, field):
     user = UserBiz.get_user_by_email(field.data)
     if not user:
         raise ValidationError(self.message)
Exemplo n.º 14
0
 def user_email(self):
     from daixieadmin.biz.user import UserBiz
     user = UserBiz.get_user_by_id(self.user_id)
     return user.email
Exemplo n.º 15
0
 def __call__(self, form, field):
     user = UserBiz.get_user_by_email(field.data)
     if not user:
         raise ValidationError(self.message)
Exemplo n.º 16
0
 def user_email(self):
     from daixieadmin.biz.user import UserBiz
     user = UserBiz.get_user_by_id(self.user_id)
     return user.email