Пример #1
0
def add_client():

    resp_data = {}
    resp_data['api'] = '/api/v1.0/clients/add'
    resp_data['method'] = 'post'
    resp_data['data'] = []
    resp_data['error'] = ''

    data = request.json

    if data is None:
        resp_data['success'] = False
        resp_data['error'] = 'Необходимо передать имя клиента параметром name'
        return jsonify(resp_data)

    new_client = Client(name=data['name'])
    new_client.owner = g.user
    new_client.get_token()

    try:
        db.session.add(new_client)
        db.session.commit()
        resp_data['success'] = True
        resp_data['data'] = new_client.to_dict()
    except:
        resp_data['error'] = 'Ошибка добавления клиента!'
        return jsonify(resp_data)

    return jsonify(resp_data)
Пример #2
0
def add_client():

    api_resp = {
        'url': '',
        'method': '',
        'success': True,
        'resp_data': '',
        'error': ''
    }

    name = request.form['name']

    api_resp['url'] = '/dash/v1.0/add_client'
    api_resp['method'] = 'POST'

    new_client = Client(name=name)
    new_client.owner = current_user
    new_client.get_token()

    try:
        db.session.add(new_client)
        db.session.commit()
        api_resp['success'] = True
        api_resp['resp_data'] = new_client.to_dict()
    except:
        api_resp['error'] = 'Ошибка добавления клиента!'
        return jsonify(api_resp)

    api_resp['success'] = True

    return jsonify(api_resp)