diff --git a/dashboard/models.py b/dashboard/models.py index 08be6b2..66df770 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/polls/views/__pycache__/media.cpython-38.pyc index c7989a3..834147c 100644 Binary files a/polls/views/__pycache__/media.cpython-38.pyc and b/polls/views/__pycache__/media.cpython-38.pyc differ diff --git a/polls/views/__pycache__/notice.cpython-38.pyc b/polls/views/__pycache__/notice.cpython-38.pyc index 5490ba1..5a17123 100644 Binary files a/polls/views/__pycache__/notice.cpython-38.pyc and b/polls/views/__pycache__/notice.cpython-38.pyc differ 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 +