Exemple #1
0
def ajax_add_user():
    add_user_form = AddUserForm()
    if add_user_form.data['id']:
        add_user_form.password.validators = []
        add_user_form.confirm_password.validators = []
    if add_user_form.validate():
        permission = {}
        for item in add_user_form.permission.data:
            permission[item] = api_permission[item]
        if add_user_form.data['id']:
            data = Api.put(
                '/admin/user/' + urllib2.quote(add_user_form.id.data), {
                    'uid': add_user_form.uid.data,
                    'password': add_user_form.password.data,
                    'permission': permission
                })
        else:
            data = Api.post(
                '/admin/user', {
                    'uid': add_user_form.uid.data,
                    'password': add_user_form.password.data,
                    'permission': permission
                })
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, add_user_form.errors)
Exemple #2
0
def order():
    setting_form = OrderSettingForm()
    if request.method == 'POST':
        print setting_form.data
        if setting_form.validate():
            params = setting_form.data

            params['order_sell_rate'] = str(
                params['order_sell_rate'] if params['order_sell_rate'] else 0)
            params['order_amount_min'] = str(params['order_amount_min'] if
                                             params['order_amount_min'] else 0)
            params['order_amount_max'] = str(params['order_amount_max'] if
                                             params['order_amount_max'] else 0)
            params['order_fee_rate'] = str(
                params['order_fee_rate'] if params['order_fee_rate'] else 0)
            params['order_price_min'] = str(
                params['order_price_min'] if params['order_price_min'] else 0)
            params['order_price_max'] = str(
                params['order_price_max'] if params['order_price_max'] else 0)

            print params
            return jsonify(Api.put('/admin/setting/sys', params))
        else:
            raise AppError.invalid_request(setting_form.errors)
    else:
        data = Api.get('/admin/setting/sys')['value']

        setting_form.process(data=data)
        return render_template('setting/order.html', setting_form=setting_form)
Exemple #3
0
def ajax_change_role():
    change_role_form = ChangeRoleForm()
    if change_role_form.validate():
        data = Api.put(
            '/admin/user/' + urllib2.quote(change_role_form.user_id.data),
            {'role': change_role_form.role.data})
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, change_role_form.errors)
Exemple #4
0
def ajax_change_password():
    change_password_form = ChangePasswordForm()
    if change_password_form.validate():
        data = Api.put(
            '/admin/user/' + urllib2.quote(change_password_form.id.data),
            {'password': change_password_form.password.data})
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, change_password_form.errors)
Exemple #5
0
def ajax_save():
    form = MessageForm()
    if form.validate():
        data = form.data
        message_id = data.pop('id')
        result = Api.put('/admin/message/detail/' + urllib2.quote(message_id),
                         data)
        return jsonify(result)
    else:
        raise ApiError(AppError.INVALID_REQUEST, form.errors)
Exemple #6
0
def ajax_change_profile():
    change_profile_form = ChangeProfileForm()
    if change_profile_form.validate():
        data = Api.put(
            '/admin/member/detail/' +
            urllib2.quote(change_profile_form.id.data),
            change_profile_form.data)
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, change_profile_form.errors)
Exemple #7
0
def ajax_change_security():
    change_security_form = ChangeSecurityForm()
    if change_security_form.validate():
        data = Api.put(
            '/admin/member/detail/' +
            urllib2.quote(change_security_form.security_id.data),
            {'security_password': change_security_form.security_password.data})
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, change_security_form.errors)
Exemple #8
0
def ajax_product_modify():
    product_form = ResellerForm()
    if product_form.validate():
        params = product_form.data
        if product_form.id.data:
            data = Api.put('/admin/reseller/' + urllib2.quote(product_form.id.data), params)
        else:
            data = Api.post('/admin/reseller', params)
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, product_form.errors)
Exemple #9
0
def ajax_change_status():
    change_status_form = ChangeStatusForm()
    if change_status_form.validate():
        data = Api.put(
            '/admin/mall/order/' + urllib2.quote(change_status_form.id.data), {
                'express_company': change_status_form.express_company.data,
                'express_code': change_status_form.express_code.data,
                'status': change_status_form.status.data
            })
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, change_status_form.errors)
Exemple #10
0
def ajax_save():
    form = NewsForm()
    if form.validate():
        data = form.data
        news_id = data.pop('id')
        # detail_data = data['details']
        # details_hash = utils.md5hex(detail_data)
        # data['details'] = upload.put_oss('news/%s.html' % details_hash, detail_data)
        if news_id:
            result = Api.put('/admin/news/details/' + urllib2.quote(news_id),
                             data)
        else:
            result = Api.post('/admin/news', data)
        return jsonify(result)
    else:
        raise ApiError(AppError.INVALID_REQUEST, form.errors)
Exemple #11
0
def ajax_product_modify():
    product_form = ProductForm()
    if product_form.validate():
        params = {
            'name': product_form.name.data,
            'front_cover': product_form.front_cover.data,
            'category': product_form.category.data,
            'detail_cover_0': product_form.detail_cover_0.data,
            'detail_cover_1': product_form.detail_cover_1.data,
            'detail_cover_2': product_form.detail_cover_2.data,
            'description': product_form.description.data,
            'price': product_form.price.data,
            'sequence': product_form.sequence.data,
            'status': product_form.status.data
        }
        if product_form.id.data:
            data = Api.put(
                '/admin/mall/' + urllib2.quote(product_form.id.data), params)
        else:
            data = Api.post('/admin/mall/product_add', params)
        return jsonify(data)
    else:
        raise ApiError(AppError.INVALID_REQUEST, product_form.errors)
Exemple #12
0
def ajax_priority_order():
    params = request.get_json()
    number = str(params.pop('number'))
    data = Api.put('/admin/order/priority/' + urllib2.quote(number), params)
    return jsonify(data)
Exemple #13
0
def ajax_lock():
    params = request.get_json()
    user_id = params.pop('id')
    data = Api.put('/admin/user/' + urllib2.quote(user_id), params)
    return jsonify(data)
Exemple #14
0
def index():
    setting_form = SettingForm()
    if request.method == 'POST':
        print setting_form.data
        if setting_form.validate():
            params = setting_form.data

            recommend_reward_amount = []
            for i in range(10):
                if params['recommend_reward_amount_' + str(i + 1)]:
                    recommend_reward_amount.append(
                        str(params['recommend_reward_amount_' + str(i + 1)]))
                params.pop('recommend_reward_amount_' + str(i + 1))
            params['recommend_reward_amount'] = recommend_reward_amount

            transaction_time_begin = []
            for i in range(2):
                if params['transaction_time_begin_' + str(i + 1)]:
                    transaction_time_begin.append(
                        str(params['transaction_time_begin_' + str(i + 1)]))
                params.pop('transaction_time_begin_' + str(i + 1))
            params['transaction_time_begin'] = transaction_time_begin

            transaction_time_end = []
            for i in range(2):
                if params['transaction_time_end_' + str(i + 1)]:
                    transaction_time_end.append(
                        str(params['transaction_time_end_' + str(i + 1)]))
                params.pop('transaction_time_end_' + str(i + 1))
            params['transaction_time_end'] = transaction_time_end

            community_total_balance = []
            for i in range(3):
                if params['community_total_balance_' + str(i + 1)]:
                    community_total_balance.append(
                        int(params['community_total_balance_' + str(i + 1)]))
                params.pop('community_total_balance_' + str(i + 1))
            params['community_total_balance'] = community_total_balance

            community_sponsor_cnt = []
            for i in range(3):
                if params['community_sponsor_cnt_' + str(i + 1)]:
                    community_sponsor_cnt.append(
                        int(params['community_sponsor_cnt_' + str(i + 1)]))
                params.pop('community_sponsor_cnt_' + str(i + 1))
            params['community_sponsor_cnt'] = community_sponsor_cnt

            params['lebo_price_step'] = str(params['lebo_price_step'])
            params['community_transaction_fee_rate'] = str(
                params['community_transaction_fee_rate'])
            params['community_dividend_rate'] = str(
                params['community_dividend_rate'])

            print params
            return jsonify(Api.put('/admin/setting/general_option', params))
        else:
            raise AppError.invalid_request(setting_form.errors)
    else:
        data = Api.get('/admin/setting/general_option')['value']

        for i in range(10):
            data['recommend_reward_amount_' + str(i + 1)] = \
                data['recommend_reward_amount'][i]

        for i in range(2):
            data['transaction_time_begin_' +
                 str(i + 1)] = data['transaction_time_begin'][i]

        for i in range(2):
            data['transaction_time_end_' +
                 str(i + 1)] = data['transaction_time_end'][i]

        for i in range(3):
            data['community_total_balance_' +
                 str(i + 1)] = data['community_total_balance'][i]
        for i in range(3):
            data['community_sponsor_cnt_' +
                 str(i + 1)] = data['community_sponsor_cnt'][i]

        data['lebo_price_step'] = str(
            data['lebo_price_step'] if data['lebo_price_step'] else 0)
        data['community_transaction_fee_rate'] = str(
            data['community_transaction_fee_rate']
            if data['community_transaction_fee_rate'] else 0)
        data['community_dividend_rate'] = str(
            data['community_dividend_rate']
            if data['evaluation_reward_amount'] else 0)

        setting_form.process(data=data)
        return render_template('setting/sys.html', setting_form=setting_form)