def user_select(request): u"""查看用户列表""" status = check_auth(request, "add_user") if not status: return render(request, 'default/error_auth.html', locals()) else: uf = CustomUser.objects.all().filter(is_active=True, is_staff=True) return render(request, 'accounts/user_list.html', locals())
def user_old(request): u""" 离职用户列表 """ status = check_auth(request, "add_user") if not status: return render_to_response(request, 'default/error_auth.html', locals()) uf = CustomUser.objects.all().filter(is_active=False, is_staff=False) return render(request, 'accounts/user_list.html', locals())
def user_status(request, id): u""" 禁用用户 """ status = check_auth(request, "delete_user") if not status: return render(request, 'default/error_auth.html', locals()) user = CustomUser.objects.get(pk=id) if user.is_staff: user.is_staff = False else: user.is_staff = True user.save() return render(request, 'accounts/user_list.html', locals())
def department_edit(request, id): u""" 部门修改 """ status = check_auth(request, "add_department") if not status: return render_to_response('default/error_auth.html', locals()) data = department_Mode.objects.get(id=id) if request.method == 'POST': uf = department_from(request.POST, instance=data) u"验证数据有效性" if uf.is_valid(): uf.save() return HttpResponseRedirect("/accounts/list_department/") uf = department_from(instance=data) return render(request, 'accounts/edit_department.html', locals())
def department_view(request): u""" 添加部门 """ status = check_auth(request, "add_department") if not status: return render_to_response('default/error_auth.html', locals()) #验证post方法 if request.method == 'POST': uf = department_from(request.POST) if uf.is_valid(): uf.save() # return render_to_response('user/department_add.html', locals(), context_instance=RequestContext(request)) return HttpResponseRedirect("/accounts/list_department/") else: uf = department_from() return render(request, 'accounts/add_department.html', locals())
def user_edit(request, id): status = check_auth(request, "edit_user") if not status: return render(request, 'default/error_auth.html', locals()) data = CustomUser.objects.get(id=id) # data_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) if request.method == 'POST': # if request.POST.getlist("password1") == request.POST.getlist("password2"): uf = useredit_from(request.POST, instance=data) # print uf if uf.is_valid(): # zw = uf.save(commit=False) # zw.last_login = data_time # zw.date_joined = data_time # zw.username = data.username # zw.id = id uf.save() return HttpResponseRedirect("/accounts/user_list/") else: uf = useredit_from(instance=data) return render(request, 'accounts/user_edit.html', locals())
def department_list(request): u""" 查看部门 """ status = check_auth(request, "add_department") if not status: return render(request, 'default/error_auth.html', locals()) uf = department_Mode.objects.all() content = {} for i in uf: user_list = [] dep_all = i.users.all().values("first_name") for t in dep_all: user_list.append(t.get("first_name")) content[i.department_name] = { "user_list": user_list, "department_id": i.id } return render(request, 'accounts/department_list.html', locals())