change admin

This commit is contained in:
baoliang 2021-04-30 00:06:56 +08:00
parent f12fe00766
commit 0426ea726d
2 changed files with 52 additions and 51 deletions

View File

@ -312,7 +312,6 @@ def media_admin_change(request):
if request.method == 'GET': if request.method == 'GET':
return HttpResponse(status=405) return HttpResponse(status=405)
id = request.POST.get('id') id = request.POST.get('id')
print(id)
if not id: if not id:
return JsonResponse({'status': 'error', 'message': '参数错误'}) return JsonResponse({'status': 'error', 'message': '参数错误'})
name = request.POST.get('name') name = request.POST.get('name')
@ -323,45 +322,54 @@ def media_admin_change(request):
return JsonResponse({'status': 'error', 'message': '手机号不能为空'}) return JsonResponse({'status': 'error', 'message': '手机号不能为空'})
u = request.user u = request.user
operator = Userprofile.objects.filter(user=u).first() operator = Userprofile.objects.filter(user=u).first()
profile = Userprofile.objects.filter(user_id=id).first()
o = profile.organization
UserModel = get_user_model() UserModel = get_user_model()
changing_user = UserModel.objects.get(id=id)
profile = changing_user.userprofile_set.first()
o = profile.organization
if o.is_direct(): # 如果是省直 if o.is_direct(): # 如果是省直
obj, created = UserModel.objects.get_or_create( if changing_user.username == phone: #修改名字
username=phone) profile.name = name
if not created: profile.save()
return JsonResponse({'status': 'error', 'message': '手机号已存在'}) else:
p = Userprofile.objects.create( obj, created = UserModel.objects.get_or_create(
user=obj, name=name, organization=o, admin_status=2) username=phone)
profile.admin_status = 5 if not created:
profile.save() return JsonResponse({'status': 'error', 'message': '手机号已存在'})
managers = Userprofile.level1_admin() p = Userprofile.objects.create(
content = '%s申请变更管理员,请审核' % (operator,) user=obj, name=name, organization=o, admin_status=2)
phones = [] profile.admin_status = 5
for a in managers: profile.save()
phones.append(a.user.username) managers = Userprofile.level1_admin()
Notice.create_reply_notice( content = '%s申请变更管理员,请审核' % (operator,)
a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '3', '0') phones = []
send_tnps(phones, '审核', content) for a in managers:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '3', '0')
send_tnps(phones, '审核', content)
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}}) return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}})
else: else:
obj, created = UserModel.objects.get_or_create( if changing_user.username == phone: #修改名字
username=phone) profile.name = name
if not created: profile.save()
return JsonResponse({'status': 'error', 'message': '手机号已存在'}) else:
p = Userprofile.objects.create( obj, created = UserModel.objects.get_or_create(
user=obj, name=name, organization=o, admin_status=1) username=phone)
profile.admin_status = 4 if not created:
profile.save() return JsonResponse({'status': 'error', 'message': '手机号已存在'})
managers = Userprofile.level2_admin(o.cities) p = Userprofile.objects.create(
content = '%s申请变更管理员,请审核' % (operator,) user=obj, name=name, organization=o, admin_status=1)
phones = [] profile.admin_status = 4
for a in managers: profile.save()
phones.append(a.user.username) managers = Userprofile.level2_admin(o.cities)
Notice.create_reply_notice( content = '%s申请变更管理员,请审核' % (operator,)
a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '2', '0') phones = []
send_tnps(phones, '审核', content) for a in managers:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '2', '0')
send_tnps(phones, '审核', content)
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}}) return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}})
@ -387,14 +395,11 @@ def media_admin_add(request):
if o.is_direct(): # 如果是省直 if o.is_direct(): # 如果是省直
obj, created = UserModel.objects.get_or_create( obj, created = UserModel.objects.get_or_create(
username=phone, last_login=datetime.now()) username=phone)
if created: if not created:
p = Userprofile.objects.create( return JsonResponse({'status': 'error', 'message': '手机号已存在'})
user=obj, name=name, organization=o, admin_status=2) p = Userprofile.objects.create(
else: user=obj, name=name, organization=o, admin_status=2)
p = Userprofile.objects.filter(user=obj).first()
p.admin_status = 2
p.save()
managers = Userprofile.level1_admin() managers = Userprofile.level1_admin()
content = '%s申请添加管理员,请审核' % (operator,) content = '%s申请添加管理员,请审核' % (operator,)
phones = [] phones = []
@ -407,14 +412,10 @@ def media_admin_add(request):
else: else:
obj, created = UserModel.objects.get_or_create( obj, created = UserModel.objects.get_or_create(
username=phone, last_login=datetime.now()) username=phone, last_login=datetime.now())
if created: if not created:
p = Userprofile.objects.create( return JsonResponse({'status': 'error', 'message': '手机号已存在'})
user=obj, name=name, organization=o, admin_status=1) p = Userprofile.objects.create(
else: user=obj, name=name, organization=o, admin_status=1)
p = Userprofile.objects.filter(user=obj).first()
p.admin_status = 1
p.save()
managers = Userprofile.level2_admin(o.cities) managers = Userprofile.level2_admin(o.cities)
content = '%s申请添加管理员,请审核' % (operator,) content = '%s申请添加管理员,请审核' % (operator,)
phones = [] phones = []