def callback():
    """
    获取列表数据
    """
    # 检查用户权限
    _common_logic.check_user_power()

    # 查询条件
    wheres = []
    start_time = convert_helper.to_date(
        web_helper.get_query('start_time', '开始时间', is_check_null=False))
    if start_time:
        wheres.append('add_time>=' + string(start_time))
    end_time = convert_helper.to_date(
        web_helper.get_query('end_time', '结束时间', is_check_null=False))
    if end_time:
        end_time = datetime_helper.timedelta('d', end_time, 1)
        wheres.append('add_time<' + string(end_time))
    manager_name = web_helper.get_query('manager_name',
                                        '管理员姓名',
                                        is_check_null=False)
    if manager_name:
        wheres.append('manager_name like \'%' + manager_name + '%\'')
    ip = web_helper.get_query('ip', 'ip', is_check_null=False)
    if ip:
        wheres.append('ip like \'' + ip + '%\'')
    remark = web_helper.get_query('remark', '操作内容', is_check_null=False)
    if remark:
        wheres.append('remark like \'%' + remark + '%\'')

    # 页面索引
    page_number = convert_helper.to_int1(
        web_helper.get_query('page', '', is_check_null=False))
    # 页面页码与显示记录数量
    page_size = convert_helper.to_int0(
        web_helper.get_query('rows', '', is_check_null=False))
    sidx = web_helper.get_query('sidx', '', is_check_null=False)
    sord = web_helper.get_query('sord', '', is_check_null=False)
    # 初始化排序字段
    order_by = 'id desc'
    if sidx:
        order_by = sidx + ' ' + sord

    _manager_operation_log_logic = manager_operation_log_logic.ManagerOperationLogLogic(
    )
    # 读取记录
    result = _manager_operation_log_logic.get_list('*', wheres, page_number,
                                                   page_size, order_by)
    if result:
        # 直接输出json
        return json.dumps(result, cls=json_helper.CJsonEncoder)
    else:
        return web_helper.return_msg(-1, "查询失败")
Beispiel #2
0
 def test_to_date(self):
     print('---test_to_date---')
     self.assertEqual(convert_helper.to_date(None), None)
     self.assertEqual(convert_helper.to_date(''), None)
     self.assertEqual(convert_helper.to_date('xxx'), None)
     result = datetime.datetime(2017, 9, 1).date()
     print(result)
     self.assertEqual(convert_helper.to_date('2017-09-01'), result)
     self.assertEqual(convert_helper.to_date('2017-09-01 11:11'), result)
     self.assertEqual(convert_helper.to_date('2017-09-01 11:11:11'), result)
     self.assertEqual(convert_helper.to_date('2017-09-01 11:11:11.111'), result)
Beispiel #3
0
def callback():
    """
    新增记录
    """
    # 检查用户权限
    _common_logic.check_user_power()

    name = web_helper.get_form('name', '管理员名称')
    sex = web_helper.get_form('sex', '性别', is_check_null=False)
    if sex != '男':
        sex = '女'
    mobile = web_helper.get_form('mobile', '手机号码', is_check_null=False)
    if mobile and not string_helper.is_mobile(mobile):
        return web_helper.return_msg(-1, '手机号码格式不正确')
    birthday = web_helper.get_form('birthday', '出生日期', is_check_null=False)
    if birthday:
        birthday = convert_helper.to_date(birthday)
    email = web_helper.get_form('email', 'email', is_check_null=False)
    if email and not string_helper.is_email(email):
        return web_helper.return_msg(-1, 'Email格式不正确')
    remark = web_helper.get_form('remark', '备注', is_check_null=False)
    department_id = convert_helper.to_int0(
        web_helper.get_form('department_id', '所属部门'))
    positions_id = convert_helper.to_int0(
        web_helper.get_form('positions_id', '所属职位'))
    is_work = convert_helper.to_int0(web_helper.get_form('is_work', '工作状态'))
    is_enabled = web_helper.get_form('is_enabled', '是否启用', is_check_null=False)
    login_name = web_helper.get_form('login_name', '登录账号')
    login_password = web_helper.get_form('login_password1',
                                         '登录密码',
                                         is_check_special_char=False)
    if len(login_password) < 6:
        return web_helper.return_msg(-1, '登录密码长度必须大于等于6位')
    login_password = encrypt_helper.md5(
        encrypt_helper.md5(login_password)[2:24])

    # 判断提交的部门id是否正确
    _department_logic = department_logic.DepartmentLogic()
    department_result = _department_logic.get_model_for_cache(department_id)
    if not department_result:
        return web_helper.return_msg(-1, '所属部门不存在')
    # 判断提交的职位id是否正确
    _positions_logic = positions_logic.PositionsLogic()
    positions_result = _positions_logic.get_model_for_cache(positions_id)
    if not positions_result or positions_result.get(
            'department_id') != department_id:
        return web_helper.return_msg(-1, '所属职位不存在')

    _manager_logic = manager_logic.ManagerLogic()
    # 组合更新字段
    fields = {
        'name': string(name),
        'sex': string(sex),
        'mobile': string(mobile),
        'email': string(email),
        'remark': string(remark),
        'department_id': department_id,
        'department_code': string(department_result.get('code', '')),
        'department_name': string(department_result.get('name', '')),
        'positions_id': positions_id,
        'positions_name': string(positions_result.get('name', '')),
        'is_work': is_work,
        'is_enabled': is_enabled,
        'login_name': string(login_name),
        'login_password': string(login_password),
    }
    if birthday:
        fields['birthday'] = string(str(birthday))
    # 添加记录
    result = _manager_logic.add_model(fields)
    if result:
        return web_helper.return_msg(0, '成功')
    else:
        return web_helper.return_msg(-1, "提交失败")