From 31622d81e2186221b5ae4fee71fe3248f937db65 Mon Sep 17 00:00:00 2001 From: baoliang Date: Mon, 26 Oct 2020 02:11:34 +0800 Subject: [PATCH] add message --- dashboard/models.py | 52 ++++++------ polls/views/__pycache__/media.cpython-38.pyc | Bin 6225 -> 7405 bytes polls/views/__pycache__/notice.cpython-38.pyc | Bin 4596 -> 5206 bytes polls/views/media.py | 52 ++++++++++++ polls/views/notice.py | 80 +++++++++++++----- 5 files changed, 136 insertions(+), 48 deletions(-) diff --git a/dashboard/models.py b/dashboard/models.py index 3efbd9d..d0c0195 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -87,22 +87,11 @@ class Group_admin(models.Model): class Group_user(models.Model): - """ - status: - '0': '已删除', - '1': '添加申请市级审核中', - '2': '添加申请省级审核中', - '3': '正常', - '4': '注销申请市级审核中', - '5': '注销申请省级审核中', - """ - id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) user = models.ForeignKey( User, on_delete=models.CASCADE, null=True, blank=True) group = models.ForeignKey( Group, on_delete=models.CASCADE, null=True, blank=True) - status = models.IntegerField('status', default=1) created = models.DateTimeField('创建时间', auto_now_add=True) updated = models.DateTimeField('更新时间', auto_now=True) @@ -160,6 +149,15 @@ class Organization(models.Model): # 扩展用户表 class Userprofile(models.Model): + """ + admin_status: + '0': '已删除', + '1': '添加申请市级审核中', + '2': '添加申请省级审核中', + '3': '正常', + '4': '注销申请市级审核中', + '5': '注销申请省级审核中', + """ user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField('姓名', null=True, blank=True, max_length=256) sex = models.CharField('性别', null=True, blank=True, max_length=256) @@ -171,6 +169,7 @@ class Userprofile(models.Model): Organization, on_delete=models.CASCADE, null=True, blank=True) # 用户状态:注册进来默认为0,为未审核状态,审核后status=1 status = models.IntegerField('用户状态', null=True, blank=True, default=0) + admin_status = models.IntegerField('管理状态', default=3) # 20201017新增字段(职位) zhiwei = models.CharField('职位', max_length=256, null=True, blank=True) created = models.DateTimeField('创建时间', auto_now_add=True) @@ -732,21 +731,22 @@ class NewmediaSentimentToutiao(models.Model): class TimelinessMonitoring(models.Model): - id = models.UUIDField('id',primary_key=True,default=uuid.uuid4()) - n_type = models.CharField('新媒体类型',max_length=256,null=True,blank=True) - n_name = models.CharField('新媒体名称',max_length=256,null=True,blank=True) - o_type = models.CharField('主体类型',max_length=256,null=True,blank=True) - o_name = models.CharField('主体名称',max_length=256,null=True,blank=True) - city = models.CharField('市',null=True,blank=True,max_length=256) - counties = models.CharField('县区',max_length=256,null=True,blank=True) - remark = models.CharField('备注',max_length=256,null=True,blank=True) - results = models.CharField('监测结果',max_length=256,null=True,blank=True) - update = models.CharField('更新次数',max_length=256,null=True,blank=True) - silet = models.CharField('最大连续静默日数',max_length=256,null= True,blank=True) - start_data = models.CharField('开始时间',max_length=256,null=True,blank=True) - end_data = models.CharField('结束时间',max_length=256,null=True,blank=True) - comment = models.CharField('评论次数',max_length=256,null=True,blank=True) - date = models.CharField('最近更新时间',max_length=256,null=True,blank=True) + id = models.UUIDField('id', primary_key=True, default=uuid.uuid4()) + n_type = models.CharField('新媒体类型', max_length=256, null=True, blank=True) + n_name = models.CharField('新媒体名称', max_length=256, null=True, blank=True) + o_type = models.CharField('主体类型', max_length=256, null=True, blank=True) + o_name = models.CharField('主体名称', max_length=256, null=True, blank=True) + city = models.CharField('市', null=True, blank=True, max_length=256) + counties = models.CharField('县区', max_length=256, null=True, blank=True) + remark = models.CharField('备注', max_length=256, null=True, blank=True) + results = models.CharField('监测结果', max_length=256, null=True, blank=True) + update = models.CharField('更新次数', max_length=256, null=True, blank=True) + silet = models.CharField('最大连续静默日数', max_length=256, null=True, blank=True) + start_data = models.CharField( + '开始时间', max_length=256, null=True, blank=True) + end_data = models.CharField('结束时间', max_length=256, null=True, blank=True) + comment = models.CharField('评论次数', max_length=256, null=True, blank=True) + date = models.CharField('最近更新时间', max_length=256, null=True, blank=True) def __str__(self): return self.n_name diff --git a/polls/views/__pycache__/media.cpython-38.pyc b/pol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~tsMaRhP*1lA~=g$kdH8ivlS=hJ7vBD~#+vkMd z4q0Hb7gR1kuKp{`x6fjN8}|*2&KY2T(0*ZZ-v>y0+; zM`f`%U0t3+7M*ncisO>324Vet3Giv6^MEYi0)Q{UMT{;1SVZn7cjW%%9&bT7yLikfFnn)f8m%KoUnJ@8H9o=Lk>9#vnJ xzPn6QSYsBj0;mEc08u^t!JRT`eA+r=9@AD$E(&A$xK4xS`<#v(Q9q5%{11BKrUn22 diff --git a/polls/views/__pycache__/notice.cpython-38.pyc b/polls/views/__pycache__/notice.cpython-38.pyc index 5490ba1267a7d673ad4d71dd8978a4db15a8a94c..5a171239f89449b45d67a0f5faa74b630cb6f07e 100644 GIT binary patch delta 1430 zcmb7E&1)1%6z}Sp>FLz;*JM88h|6qHGzl&nGy&IL7Q{tFR#`Nn2BmFNoj9F1Nvb=0 zkRC^Hj}Zq-g+;*xmfiIv>Ol{pCj~E_M5OWHC4L<|`3Lx3IWZsT!GZVV)vGtJ-mCik z`osEXJ=Q_fqze2VJ-Fmvsou0ksGWl)+D@==NEK)4FXAX2x09iL-P0d4(u4Zb5vO z*~{b8vr*?vzf#4^Ey$cpF|q#WCfPJ zs-7cn6?i#&!u1r z8su?3Mp)N*LKLx;MF+_Y6iC%!_zy=(b8OpsaMiJvu795s4=Nb=ktndHo!^1{&l)0>#_c@^{a03?RTPSxse7&oy)1_L8KE)?TYZHE$kf~u!mIK%0dm&#` z&F<0T;3z3dDA9>Q(!`SHfUglpMk#nYc$!@4q=z^v=3*4lQXR;2KB`fsCp94R>q&C#p?l!?ecj4vFYWwHQY76hm3=ji9!$6BmdYnE3 z^vHvNmgJKj262C4e*xI9N1d?_jTEpMNq$|DzX0SfO7a7R-QptoSC?zEtpsd?&xd4N z8QHc8*~b4sKyvW|2*?>egm4hyFo3vbRZK}Cegu|7y=C#ERzaQ&CWSUnxF7f<(Q2mf zV_0JV!9zHX&@EmX>r2DNiocw|oe{Ci-l+WtZn#bCFuOM5>pJkBMfr+|6kd7hUF9o| wiNEcK+DR->6U^CEdW;3+*R@TcBH@9Ua~5(wCXFEkqLn|A8&ru(jPDUY0@V*whX4Qo delta 808 zcmbtSJ#5oJ7`@MK9QP7Cc9Q-{ptf`%>5>ZC0SN{K6H+AvErp8KwQ>g4NufPE49F2k zWhA8NU}H!I1|~!qx>YP7CPoGiEGWQ?va#@;p(>1sJH2=Q^u2qM-*+EN{V8+NFet(0 zw;ns~(N|`b<_59MAkHCzt03;v)5_hxctgkU4fwjBid5fVgDq&LLNk(84q8+QEz(%FrtnW;p;PRVW;#lrCo9uUJxq6oBHdSf6?MZ1 zyz6HX(%oPNGrRg4kgZ)b$kmh`;1mC7VKSquqeDN`n8j?Cex_{061hwUNH|iX=y*xY zTjP)y8`kuhQ~38UAT}DC%nd!~#=2K$!9oltVmKMYObl~;7$uDy($^=izrEb+?d|q< z9)5YyE{}?eHYOe!r3$}*?KmBHp&N!gP9-+6&AsYv&YVp*2%I}^z2Wg$)bUC2*_aV4 z_QVlBkM%M=6fA2l+gQI9#Ndi8a}s97zCCi*0=YHN6X*i zT=<<2_k6D!{*{o_$Ol^1M8zBvPwgqKjb(65=3yP?VSx#JRs68uYL2|KCf?9lN diff --git a/polls/views/media.py b/polls/views/media.py index adc45ec..dd510db 100644 --- a/polls/views/media.py +++ b/polls/views/media.py @@ -5,6 +5,7 @@ from django.core.paginator import Paginator from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Userprofile, Weibo, Weixin from polls.decorators import polls_login_required from polls.models import Notice +from django.contrib.auth import get_user_model @csrf_exempt @@ -256,3 +257,54 @@ def delete_media(request): result['organization'] = instance.organization.name result['admin'] = admins return JsonResponse({'status': 'success', 'message': result}) + + +@csrf_exempt +@polls_login_required +def media_admin_change(request): + if request.method == 'GET': + return HttpResponse(status=405) + id = request.POST.get('id') + if not id: + return JsonResponse({'status': 'error', 'message': '参数错误'}) + name = request.POST.get('name') + if not name: + return JsonResponse({'status': 'error', 'message': '姓名不能为空'}) + phone = request.POST.get('phone') + if not phone: + 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() + + if o.is_direct(): # 如果是省直 + obj, created = UserModel.objects.get_or_create(username=phone) + if created: + p = Userprofile.objects.create(obj, organization=o, admin_status=2) + else: + obj.admin_status = 2 + obj.save() + profile.admin_status = 5 + profile.save() + managers = Userprofile.level1_admin() + for a in managers: + content = '%s申请变更管理员,请审核' % (operator,) + Notice.create_reply_notice( + a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '0', '3') + else: + obj, created = UserModel.objects.get_or_create(username=phone) + if created: + p = Userprofile.objects.create(obj, organization=o, admin_status=1) + else: + obj.admin_status = 1 + obj.save() + profile.admin_status = 4 + profile.save() + managers = Userprofile.level2_admin(o.cities) + for a in managers: + content = '%s申请变更管理员,请审核' % (operator,) + Notice.create_reply_notice( + a.user.id, content, 'dashboard', 'Userprofile', 'admin_status', o.id, '0', '2') + diff --git a/polls/views/notice.py b/polls/views/notice.py index 6ba37e5..8b56115 100644 --- a/polls/views/notice.py +++ b/polls/views/notice.py @@ -121,21 +121,45 @@ def pass_notice(request): try: notice = Notice.objects.get(id=notice_id) ReplyModel = apps.get_model(notice.app, notice.model) - m = ReplyModel.objects.get(pk=notice.record_id) - setattr(m, notice.field, notice.record_pass_value) - m.save(update_fields=[notice.field]) - notice.is_read = True - notice.save() - pass_value = notice.record_pass_value - if pass_value == '2': - admins = Userprofile.level1_admin() - for a in admins: - Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') - if pass_value == '5': - admins = Userprofile.level1_admin() - for a in admins: - Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3') - return JsonResponse({'status': 'success', 'message': '申请已同意'}) + if notice.model == 'Userprofile': + pass_value = notice.record_pass_value + profiles = ReplyModel.objects.filter(organization_id=notice.record_id) + if pass_value == '2': #市级提交,1->2, 4->5 + for p in profiles: + if p.admin_status == 1: + p.admin_status = 2 + p.save() + if p.admin_status == 4: + p.admin_status = 5 + p.save() + admins = Userprofile.level1_admin() + for a in admins: + Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') + return JsonResponse({'status': 'success', 'message': '申请已同意'}) + else: #省级提交 + for p in profiles: + if p.admin_status == 5: + p.admin_status = 0 + p.save() + if p.admin_status == 2: + p.admin_status = 3 + p.save() + else: + m = ReplyModel.objects.get(pk=notice.record_id) + setattr(m, notice.field, notice.record_pass_value) + m.save(update_fields=[notice.field]) + notice.is_read = True + notice.save() + pass_value = notice.record_pass_value + if pass_value == '2': + admins = Userprofile.level1_admin() + for a in admins: + Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') + if pass_value == '5': + admins = Userprofile.level1_admin() + for a in admins: + Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3') + return JsonResponse({'status': 'success', 'message': '申请已同意'}) except ObjectDoesNotExist: return JsonResponse({'status': 'error', 'message': '通知ID错误'}) @@ -152,12 +176,24 @@ def reject_notice(request): try: notice = Notice.objects.get(id=notice_id) ReplyModel = apps.get_model(notice.app, notice.model) - m = ReplyModel.objects.get(pk=notice.record_id) - setattr(m, notice.field, notice.record_reject_value) - m.save(update_fields=[notice.field]) - notice.is_read = True - notice.save() - return JsonResponse({'status': 'success', 'message': '申请已拒绝'}) + if notice.model == 'Userprofile': + reject_value = notice.record_reject_value + profiles = ReplyModel.objects.filter(organization_id=notice.record_id) + for p in profiles: + if p.admin_status == 1 or p.admin_status == 2: + p.admin_status = 0 + p.save() + if p.admin_status == 4 or p.admin_status == 5: + p.admin_status = 3 + p.save() + return JsonResponse({'status': 'success', 'message': '申请已拒绝'}) + else: + m = ReplyModel.objects.get(pk=notice.record_id) + setattr(m, notice.field, notice.record_reject_value) + m.save(update_fields=[notice.field]) + notice.is_read = True + notice.save() + return JsonResponse({'status': 'success', 'message': '申请已拒绝'}) except ObjectDoesNotExist: return JsonResponse({'status': 'error', 'message': '通知ID错误'}) @@ -171,4 +207,4 @@ def unread_notice_count(request): count = Notice.objects.filter(user_id=user_id, is_read=False).count() return JsonResponse({'status': 'success', 'message': count}) - \ No newline at end of file +