add message

This commit is contained in:
baoliang 2020-10-26 02:11:34 +08:00
parent 5a2529e12e
commit 31622d81e2
5 changed files with 136 additions and 48 deletions

View File

@ -87,22 +87,11 @@ class Group_admin(models.Model):
class Group_user(models.Model): class Group_user(models.Model):
"""
status:
'0': '已删除',
'1': '添加申请市级审核中',
'2': '添加申请省级审核中',
'3': '正常',
'4': '注销申请市级审核中',
'5': '注销申请省级审核中',
"""
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
user = models.ForeignKey( user = models.ForeignKey(
User, on_delete=models.CASCADE, null=True, blank=True) User, on_delete=models.CASCADE, null=True, blank=True)
group = models.ForeignKey( group = models.ForeignKey(
Group, on_delete=models.CASCADE, null=True, blank=True) Group, on_delete=models.CASCADE, null=True, blank=True)
status = models.IntegerField('status', default=1)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
updated = models.DateTimeField('更新时间', auto_now=True) updated = models.DateTimeField('更新时间', auto_now=True)
@ -160,6 +149,15 @@ class Organization(models.Model):
# 扩展用户表 # 扩展用户表
class Userprofile(models.Model): class Userprofile(models.Model):
"""
admin_status:
'0': '已删除',
'1': '添加申请市级审核中',
'2': '添加申请省级审核中',
'3': '正常',
'4': '注销申请市级审核中',
'5': '注销申请省级审核中',
"""
user = models.ForeignKey(User, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField('姓名', null=True, blank=True, max_length=256) name = models.CharField('姓名', null=True, blank=True, max_length=256)
sex = 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) Organization, on_delete=models.CASCADE, null=True, blank=True)
# 用户状态:注册进来默认为0为未审核状态审核后status=1 # 用户状态:注册进来默认为0为未审核状态审核后status=1
status = models.IntegerField('用户状态', null=True, blank=True, default=0) status = models.IntegerField('用户状态', null=True, blank=True, default=0)
admin_status = models.IntegerField('管理状态', default=3)
# 20201017新增字段职位 # 20201017新增字段职位
zhiwei = models.CharField('职位', max_length=256, null=True, blank=True) zhiwei = models.CharField('职位', max_length=256, null=True, blank=True)
created = models.DateTimeField('创建时间', auto_now_add=True) created = models.DateTimeField('创建时间', auto_now_add=True)
@ -732,21 +731,22 @@ class NewmediaSentimentToutiao(models.Model):
class TimelinessMonitoring(models.Model): class TimelinessMonitoring(models.Model):
id = models.UUIDField('id',primary_key=True,default=uuid.uuid4()) id = models.UUIDField('id', primary_key=True, default=uuid.uuid4())
n_type = models.CharField('新媒体类型',max_length=256,null=True,blank=True) n_type = models.CharField('新媒体类型', max_length=256, null=True, blank=True)
n_name = 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_type = models.CharField('主体类型', max_length=256, null=True, blank=True)
o_name = 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) city = models.CharField('', null=True, blank=True, max_length=256)
counties = models.CharField('县区',max_length=256,null=True,blank=True) counties = models.CharField('县区', max_length=256, null=True, blank=True)
remark = 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) results = models.CharField('监测结果', max_length=256, null=True, blank=True)
update = 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) silet = models.CharField('最大连续静默日数', max_length=256, null=True, blank=True)
start_data = models.CharField('开始时间',max_length=256,null=True,blank=True) start_data = models.CharField(
end_data = models.CharField('结束时间',max_length=256,null=True,blank=True) '开始时间', max_length=256, null=True, blank=True)
comment = models.CharField('评论次数',max_length=256,null=True,blank=True) end_data = models.CharField('结束时间', max_length=256, null=True, blank=True)
date = 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): def __str__(self):
return self.n_name return self.n_name

View File

@ -5,6 +5,7 @@ from django.core.paginator import Paginator
from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Userprofile, Weibo, Weixin from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Userprofile, Weibo, Weixin
from polls.decorators import polls_login_required from polls.decorators import polls_login_required
from polls.models import Notice from polls.models import Notice
from django.contrib.auth import get_user_model
@csrf_exempt @csrf_exempt
@ -256,3 +257,54 @@ def delete_media(request):
result['organization'] = instance.organization.name result['organization'] = instance.organization.name
result['admin'] = admins result['admin'] = admins
return JsonResponse({'status': 'success', 'message': result}) 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')

View File

@ -121,21 +121,45 @@ def pass_notice(request):
try: try:
notice = Notice.objects.get(id=notice_id) notice = Notice.objects.get(id=notice_id)
ReplyModel = apps.get_model(notice.app, notice.model) ReplyModel = apps.get_model(notice.app, notice.model)
m = ReplyModel.objects.get(pk=notice.record_id) if notice.model == 'Userprofile':
setattr(m, notice.field, notice.record_pass_value) pass_value = notice.record_pass_value
m.save(update_fields=[notice.field]) profiles = ReplyModel.objects.filter(organization_id=notice.record_id)
notice.is_read = True if pass_value == '2': #市级提交1->2, 4->5
notice.save() for p in profiles:
pass_value = notice.record_pass_value if p.admin_status == 1:
if pass_value == '2': p.admin_status = 2
admins = Userprofile.level1_admin() p.save()
for a in admins: if p.admin_status == 4:
Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0') p.admin_status = 5
if pass_value == '5': p.save()
admins = Userprofile.level1_admin() admins = Userprofile.level1_admin()
for a in admins: for a in admins:
Notice.create_reply_notice(a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3') 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': '申请已同意'}) 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: except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'}) return JsonResponse({'status': 'error', 'message': '通知ID错误'})
@ -152,12 +176,24 @@ def reject_notice(request):
try: try:
notice = Notice.objects.get(id=notice_id) notice = Notice.objects.get(id=notice_id)
ReplyModel = apps.get_model(notice.app, notice.model) ReplyModel = apps.get_model(notice.app, notice.model)
m = ReplyModel.objects.get(pk=notice.record_id) if notice.model == 'Userprofile':
setattr(m, notice.field, notice.record_reject_value) reject_value = notice.record_reject_value
m.save(update_fields=[notice.field]) profiles = ReplyModel.objects.filter(organization_id=notice.record_id)
notice.is_read = True for p in profiles:
notice.save() if p.admin_status == 1 or p.admin_status == 2:
return JsonResponse({'status': 'success', 'message': '申请已拒绝'}) 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: except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'}) 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() count = Notice.objects.filter(user_id=user_id, is_read=False).count()
return JsonResponse({'status': 'success', 'message': count}) return JsonResponse({'status': 'success', 'message': count})