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()
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!' })
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 {}
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': '原密码错误!'})
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 {}
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': '原密码错误!'})
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)
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)
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': '成功!'})
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()
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': '成功!'})
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': '成功!'})
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})
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})
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!'})
def get_user_by_id(id): user = get_object(User, id=id) return user
def get_user_by_code(code): user = get_object(User, code=code) # if user in get_api_user(): return user
def get_user_by_code(code): user = get_object(User, code=code) # if user in get_api_user(): return user
def get_user_by_id(id): user = get_object(User, id=id) return user