Exemple #1
0
def addr_file_process(file_id):
    file = AddressFile.objects.get(id=file_id)
    with transaction.atomic():
        book = xlrd.open_workbook(file.file.path)
        sheet = book.sheets()[0]
        rows = sheet.nrows
        cols = sheet.ncols
        for row in range(1, rows):
            row_data = sheet.row_values(row)
            if row_data:
                addr = Address(
                    name=row_data[1],
                    phone=type(row_data[0]) == float and str(int(row_data[0]))
                    or row_data[0],
                    sex=row_data[2] in {
                        u'男': 'male',
                        u'女': 'female'
                    } and {
                        u'男': 'male',
                        u'女': 'female'
                    }[row_data[2]] or row_data[2],
                    email=row_data[3],
                    company=row_data[4],
                    dept=row_data[5],
                    post=row_data[6],
                    addr=row_data[7],
                    group_id=file.group_id)
                obj = get_object(Address,
                                 phone=addr.phone,
                                 group_id=addr.group_id)
                if obj: addr.id = obj.id
                addr.save()
Exemple #2
0
def su(request):
    uid = request.json['object']['id']
    query = User.objects.filter(id=uid)
    if query.count() == 1:
        user = query[0]
        if user.stat == 'normal':
            dept_root = user.dept.root and user.dept.root or user.dept
            admin = get_object(dept_root.dept_user_set,
                               role__type='admin',
                               admin=dept_root)
            request.session['user'] = {
                'id': user.id,
                'name': user.name,
                'code': user.code,
                'type': user.role.type,
                'dept_id': user.dept.id,
                'dept_name': user.dept.name,
                'dept_path': user.dept.path,
                'dept_root_id': dept_root.id,
                'dept_root_name': dept_root.name,
                'admin_id': admin is not None and admin.id or None,
            }
    return JsonResponse({
        'success': True,
        'message': 'Success,Please press F5!'
    })
Exemple #3
0
def get_wxlt_config(pinid):
    wxlt_config = get_object(WxltConfig, pinid=pinid)
    return wxlt_config and {
        'pinid': wxlt_config.pinid.encode(),
        'accountid': wxlt_config.accountid.encode(),
        'accountpwd': wxlt_config.accountpwd.encode(),
        'des_key': wxlt_config.des_key.encode(),
        'user_id': wxlt_config.dept_user_id,
    } or {}
Exemple #4
0
def user_reset_pass(request):
    obj = request.json['object']
    user = get_object(User, code=obj.get('code'))
    if user.pwd == obj.get('old_pwd'):
        user.pwd = obj.get('pwd')
        user.save()
        return JsonResponse({'success': True, 'message': '成功!'})
    else:
        return JsonResponse({'success': False, 'message': '原密码错误!'})
Exemple #5
0
def get_wxlt_config(pinid):
    wxlt_config = get_object(WxltConfig, pinid=pinid)
    return wxlt_config and {
        'pinid': wxlt_config.pinid.encode(),
        'accountid': wxlt_config.accountid.encode(),
        'accountpwd': wxlt_config.accountpwd.encode(),
        'des_key': wxlt_config.des_key.encode(),
        'user_id': wxlt_config.dept_user_id,
    } or {}
Exemple #6
0
def user_reset_pass(request):
    obj = request.json['object']
    user = get_object(User, code=obj.get('code'))
    if user.pwd == obj.get('old_pwd'):
        user.pwd = obj.get('pwd')
        user.save()
        return JsonResponse({'success': True, 'message': '成功!'})
    else:
        return JsonResponse({'success': False, 'message': '原密码错误!'})
Exemple #7
0
def role_perm(request):
    obj = request.json['role']
    role = get_object(Role, pk=obj.get('id'))
    role_perm_list = role.perm.all()
    perm_list = Permission.objects.all()

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    perm_tree = get_perm_tree_checked(perm_list, role_perm_list, [], None)
    return JsonResponse(perm_tree)
Exemple #8
0
def role_perm(request):
    obj = request.json['role']
    role = get_object(Role, pk=obj.get('id'))
    role_perm_list = role.perm.all()
    perm_list = Permission.objects.all()

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    perm_tree = get_perm_tree_checked(perm_list, role_perm_list, [], None)
    return JsonResponse(perm_tree)
Exemple #9
0
def role_perm_update(request):
    obj = request.json['role']
    ids = request.json['ids']
    role = get_object(Role, pk=obj.get('id'))
    if ids:
        id_list = ids.split(',')
    else:
        id_list = []
    perm_list = Permission.objects.all().filter(id__in=[id for id in id_list])

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    role.perm = perm_list
    return JsonResponse({'success': True, 'message': '成功!'})
Exemple #10
0
def processor_update(request):
    obj = request.json['object']
    dept_id = obj.get('dept_id')
    pid = obj.get('pid')

    proc = get_object(Processor, processor_dept_id=dept_id)
    if not proc:
        proc = Processor()
        proc.processor_dept_id = dept_id
    if pid is None or pid == '':
        if proc.id:
            proc.delete()
    else:
        proc.pid = pid
        proc.save()
Exemple #11
0
def role_perm_update(request):
    obj = request.json['role']
    ids = request.json['ids']
    role = get_object(Role, pk=obj.get('id'))
    if ids:
        id_list = ids.split(',')
    else:
        id_list = []
    perm_list = Permission.objects.all().filter(id__in=[id for id in id_list])

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    role.perm = perm_list
    return JsonResponse({'success': True, 'message': '成功!'})
Exemple #12
0
def addr_file(request):
    j_addr = request.json['object']
    j_file = request.FILES['object.file']
    print dir(j_file)
    file = AddressFile(
        name=j_file.name,
        file=j_file,
        group=get_object(AddressGroup, pk=j_addr.get('group_id')),
    )

    model_default(request, file)
    model_check(request, file)

    file.save()

    addr_file_process.delay(file.id)

    return JsonResponse({'success': True, 'message': '成功!'})
Exemple #13
0
def user_login(request):
    obj = request.json['object']

    query = User.objects.filter(code=obj['code'])
    success = False
    message = ""
    if query.count() == 1:
        user = query[0]
        if user.pwd == obj['pwd']:
            if user.stat == 'normal':
                if request.session.get('verify_expire', 0) > time.time():
                    if request.session.get('verify_code') == obj.get('verify'):
                        request.session.pop('verify_expire')
                        request.session.pop('verify_code')
                        dept_root = user.dept.root and user.dept.root or user.dept
                        admin = get_object(dept_root.dept_user_set,
                                           role__type='admin',
                                           admin=dept_root)
                        request.session['user'] = {
                            'id': user.id,
                            'name': user.name,
                            'code': user.code,
                            'type': user.role.type,
                            'dept_id': user.dept.id,
                            'dept_name': user.dept.name,
                            'dept_path': user.dept.path,
                            'dept_root_id': dept_root.id,
                            'dept_root_name': dept_root.name,
                            'admin_id': admin is not None and admin.id or None,
                        }
                        success = True
                    else:
                        message = '验证码错误!'
                else:
                    message = "验证码过期!"
            else:
                message = "账户被锁定!"
        else:
            message = "密码错误!"
    else:
        message = "账号不存在!"

    return JsonResponse({'success': success, 'message': message})
Exemple #14
0
def user_login(request):
    obj = request.json['object']

    query = User.objects.filter(code=obj['code'])
    success = False
    message = ""
    if query.count() == 1:
        user = query[0]
        if user.pwd == obj['pwd']:
            if user.stat == 'normal':
                if request.session.get('verify_expire', 0) > time.time():
                    if request.session.get('verify_code') == obj.get('verify'):
                        request.session.pop('verify_expire')
                        request.session.pop('verify_code')
                        dept_root = user.dept.root and user.dept.root or user.dept
                        admin = get_object(dept_root.dept_user_set, role__type='admin', admin=dept_root)
                        request.session['user'] = {
                            'id': user.id,
                            'name': user.name,
                            'code': user.code,
                            'type': user.role.type,
                            'dept_id': user.dept.id,
                            'dept_name': user.dept.name,
                            'dept_path': user.dept.path,
                            'dept_root_id': dept_root.id,
                            'dept_root_name': dept_root.name,
                            'admin_id': admin is not None and admin.id or None,
                        }
                        success = True
                    else:
                        message = '验证码错误!'
                else:
                    message = "验证码过期!"
            else:
                message = "账户被锁定!"
        else:
            message = "密码错误!"
    else:
        message = "账号不存在!"

    return JsonResponse({'success': success, 'message': message})
Exemple #15
0
def su(request):
    uid = request.json['object']['id']
    query = User.objects.filter(id=uid)
    if query.count() == 1:
        user = query[0]
        if user.stat == 'normal':
            dept_root = user.dept.root and user.dept.root or user.dept
            admin = get_object(dept_root.dept_user_set, role__type='admin', admin=dept_root)
            request.session['user'] = {
                'id': user.id,
                'name': user.name,
                'code': user.code,
                'type': user.role.type,
                'dept_id': user.dept.id,
                'dept_name': user.dept.name,
                'dept_path': user.dept.path,
                'dept_root_id': dept_root.id,
                'dept_root_name': dept_root.name,
                'admin_id': admin is not None and admin.id or None,
            }
    return JsonResponse({'success': True, 'message': 'Success,Please press F5!'})
Exemple #16
0
def get_user_by_id(id):
    user = get_object(User, id=id)
    return user
Exemple #17
0
def get_user_by_code(code):
    user = get_object(User, code=code)
    # if user in get_api_user():
    return user
Exemple #18
0
def get_user_by_code(code):
    user = get_object(User, code=code)
    # if user in get_api_user():
    return user
Exemple #19
0
def get_user_by_id(id):
    user = get_object(User, id=id)
    return user