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':
return HttpResponse(status=405)
id = request.POST.get('id')
print(id)
if not id:
return JsonResponse({'status': 'error', 'message': '参数错误'})
name = request.POST.get('name')
@ -323,11 +322,16 @@ def media_admin_change(request):
return JsonResponse({'status': 'error', 'message': '手机号不能为空'})
u = request.user
operator = Userprofile.objects.filter(user=u).first()
profile = Userprofile.objects.filter(user_id=id).first()
o = profile.organization
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 changing_user.username == phone: #修改名字
profile.name = name
profile.save()
else:
obj, created = UserModel.objects.get_or_create(
username=phone)
if not created:
@ -345,6 +349,10 @@ def media_admin_change(request):
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}})
else:
if changing_user.username == phone: #修改名字
profile.name = name
profile.save()
else:
obj, created = UserModel.objects.get_or_create(
username=phone)
@ -387,14 +395,11 @@ def media_admin_add(request):
if o.is_direct(): # 如果是省直
obj, created = UserModel.objects.get_or_create(
username=phone, last_login=datetime.now())
if created:
username=phone)
if not created:
return JsonResponse({'status': 'error', 'message': '手机号已存在'})
p = Userprofile.objects.create(
user=obj, name=name, organization=o, admin_status=2)
else:
p = Userprofile.objects.filter(user=obj).first()
p.admin_status = 2
p.save()
managers = Userprofile.level1_admin()
content = '%s申请添加管理员,请审核' % (operator,)
phones = []
@ -407,14 +412,10 @@ def media_admin_add(request):
else:
obj, created = UserModel.objects.get_or_create(
username=phone, last_login=datetime.now())
if created:
if not created:
return JsonResponse({'status': 'error', 'message': '手机号已存在'})
p = Userprofile.objects.create(
user=obj, name=name, organization=o, admin_status=1)
else:
p = Userprofile.objects.filter(user=obj).first()
p.admin_status = 1
p.save()
managers = Userprofile.level2_admin(o.cities)
content = '%s申请添加管理员,请审核' % (operator,)
phones = []