From 0426ea726d09cd2074ce1e9d1834ee15ca449fd1 Mon Sep 17 00:00:00 2001 From: baoliang Date: Fri, 30 Apr 2021 00:06:56 +0800 Subject: [PATCH] change admin --- polls/views/__pycache__/media.cpython-39.pyc | Bin 10965 -> 10986 bytes polls/views/media.py | 103 ++++++++++--------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/polls/views/__pycache__/media.cpython-39.pyc b/polls/views/__pycache__/media.cpython-39.pyc index 9208f58bbb8746e1d30e7e48c9cd12b3a25dd1a1..2335aeb6de2751c7ec40f364b428006a51df32e7 100644 GIT binary patch delta 1340 zcmb7^&rcIU6vua_WxL&9{YhI|3MB<89E?FOMh>C|HEKK%4x$DcrUI)0SxO{k){>Aw z1PX-l$YHCAi5g7^|AfXwPhPl5Jb56&1U%xKwS|aiu*rTqZ{F+7_w{|UpL@Rb=vhsZ z1^5iTpX>i{Wlg_a>kB}rz;gkfae~n~% z;#tMhs9VVMTY^-E-+GCk1d47;C50dy6sjDQ7ws@ytdS6{x{D%$r4I_0k7^f%J8hPq z`s`}zH>wQ1gpiPr*ik2nQJsWIHHlEK5hGC&D@h3Kj-AZcP#>wG`m_tG-6RfqpHq`q z#T8S9N>9+=vqN3III62^nQid3!-Dm%*=S>ZeGnq^441Q9`nd24vz1Ff+p15AS-w2YvYD7Nz?TH1CBV8; z>BbFj&v?$fK1y=;d$oa~?8xBo$Y9?D?3o?BGzY>Sr*5DrwjD}@MHECL(vgfrEOSLN zWYFIF_M8BA8@0PV3`{g zxY4Kr+?=v>s@Z<312+MOo1h(XqA*oSh?4_j4wDFp7C1O#yZLIWkr-9W*wjEe;*`V> zu&Ef$N9|ZiAc-Od>K(hl$K(-wR1E*(gB#}O#({_f(}M@D+m7ivNup)iUmeFb5xRwz zI%cQO%jOIp+AJU1PP&(Ero+lrzHJI5ufnAIo6qI)*Vbd5O26fMjx`x z#uL@^Jj(}fE^sMwS!Btk4sjB}Yi5X(z#cWJU3gE%ZlFO#(w>MV;K7X~h}|dxv5I1t zXJpVyjrv=S1U2Rg`xH&CZ#TU`N(vxRoV`wh0#ZYTe delta 1342 zcma)+&uiYAdgvY_8~EbN}L;4fLr5=ifT}ZwaDC5VjZ=_ z8Y%+_JE+q)ZOm}H4;NURj}0`sqjV4F{T}IB4(5@e*5fXp=x5^sFQVFZQB5X>3Mi45 z6lq(Ndzf2+vJzWYl-Ne|jB@d4?4X@^=mcs|8q!NelSw%pRnX!kKFQ0d1r=W5)u9dq zb*&s#(dJWVZDy!D$7?h{mG<~sJ@%gJbL0c)-rt*@*T?A7yU^tZ{t&(fe_>DleLMVr z?Zq!%?7QVXfRT2+yBxMxc?-g$bne&1>6wSxD7O)=b|NvDn<<>4YFL!f7Oh4@tTa!6 zE5gQs$#6kdmnla1C0gajb-uhNo;7~5BC07F0}L=h7f|wyA{0Rdl^GzunQe-d*?Aa< zd$ZH*_}H`hhB&d`?_H(W*8&SOk)1e0g;Zdqf*$8FAN~`mH0PpDhp%#nyL9$Or;%25 z)KlT|bn*sw&}dJfAw8hqNKHJd7Wl;22a|lTu#oy-qm`7<4syYy^kE??CzW(qMUxk~ z$4lgDRf;hd!i`7o>!@;$ri($R6}-zsL!xN!XWhPsXn@j*FMgd2#8Wt8M`OPhmA&gDyFT<$eRp3d#GjSvCx;#Z t3vY|gOj-Of|DT((?RXsaiRdIe`u+cA0O~+83bA_lM&Vlq49rt9-vTFRMT!6b diff --git a/polls/views/media.py b/polls/views/media.py index 486cfda..7eea24a 100644 --- a/polls/views/media.py +++ b/polls/views/media.py @@ -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,45 +322,54 @@ 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(): # 如果是省直 - obj, created = UserModel.objects.get_or_create( - username=phone) - if not created: - return JsonResponse({'status': 'error', 'message': '手机号已存在'}) - p = Userprofile.objects.create( - user=obj, name=name, organization=o, admin_status=2) - profile.admin_status = 5 - profile.save() - managers = Userprofile.level1_admin() - content = '%s申请变更管理员,请审核' % (operator,) - phones = [] - 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) + if changing_user.username == phone: #修改名字 + profile.name = name + profile.save() + else: + obj, created = UserModel.objects.get_or_create( + username=phone) + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=2) + profile.admin_status = 5 + profile.save() + managers = Userprofile.level1_admin() + content = '%s申请变更管理员,请审核' % (operator,) + phones = [] + 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}}) else: - obj, created = UserModel.objects.get_or_create( - username=phone) - if not created: - return JsonResponse({'status': 'error', 'message': '手机号已存在'}) - p = Userprofile.objects.create( - user=obj, name=name, organization=o, admin_status=1) - profile.admin_status = 4 - profile.save() - managers = Userprofile.level2_admin(o.cities) - content = '%s申请变更管理员,请审核' % (operator,) - phones = [] - 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) + if changing_user.username == phone: #修改名字 + profile.name = name + profile.save() + else: + obj, created = UserModel.objects.get_or_create( + username=phone) + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=1) + profile.admin_status = 4 + profile.save() + managers = Userprofile.level2_admin(o.cities) + content = '%s申请变更管理员,请审核' % (operator,) + phones = [] + 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}}) @@ -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: - 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() + username=phone) + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=2) 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: - 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() - + if not created: + return JsonResponse({'status': 'error', 'message': '手机号已存在'}) + p = Userprofile.objects.create( + user=obj, name=name, organization=o, admin_status=1) managers = Userprofile.level2_admin(o.cities) content = '%s申请添加管理员,请审核' % (operator,) phones = []