Esempio n. 1
0
def update_customer():
    if request.method == 'GET':
        return obj2json(RetModel(1, dict_err_code[1], {}))

    if (request.form.get('uid', None) is None
            or request.form.get('token', None) is None):
        return obj2json(RetModel(21, dict_err_code[21]))

    if (False == verify_user_token(request.form['uid'],
                                   request.form['token'])):
        return obj2json(RetModel(21, dict_err_code[21], {}))

    if (request.form.get('id', None) is None):
        return obj2json(RetModel(31, dict_err_code[31], {}))

    if (request.form.get('name', None) is None):
        return obj2json(RetModel(32, dict_err_code[32], {}))

    if (request.form.get('address', None) is None):
        return obj2json(RetModel(33, dict_err_code[33], {}))

    if (request.form.get('longitude', None) is None):
        return obj2json(RetModel(34, dict_err_code[34], {}))

    if (request.form.get('latitude', None) is None):
        return obj2json(RetModel(35, dict_err_code[35], {}))

    customer = Customer()
    customer.id = request.form['id']
    customer.uid = request.form['uid']
    customer.name = request.form['name']
    customer.group_name = request.form.get('group_name', '')
    customer.spell = request.form.get('spell', '')
    customer.address = request.form['address']
    customer.longitude = request.form['longitude']
    customer.latitude = request.form['latitude']
    customer.boss = request.form.get('boss', '')
    customer.phone = request.form.get('phone', '')
    customer.email = request.form.get('email', '')
    customer.description = request.form.get('description', '')
    customer.update_date = request.form.get('update_date', int(time.time()))

    szRet = ''
    if (False == if_customer_exists(customer)):
        szRet = obj2json(RetModel(30, dict_err_code[30], {}))
    else:
        if (True == update_customer_info(request.form['uid'], customer)):
            szRet = obj2json(RetModel(0, dict_err_code[0], {}))
        else:
            szRet = obj2json(RetModel(1000, dict_err_code[1000], {}))

    return szRet
def init_customer(row):
    customer = Customer()
    customer.id = row['id']
    customer.uid = row['uid']
    customer.name = row['name']
    customer.group_name = row['group_name']
    customer.spell = row['spell']

    customer.address = row['address']
    customer.longitude = row['longitude']
    customer.latitude = row['latitude']
    customer.boss = row['boss']
    customer.phone = row['phone']

    customer.email = row['email']
    customer.description = row['description']
    customer.update_date = row['update_date']
    customer.is_deleted = row['is_deleted']

    return customer