2020-09-03 04:03:19 +00:00
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from django.http import HttpResponse, JsonResponse
|
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2020-09-24 06:51:39 +00:00
|
|
|
|
from django.apps import apps
|
2020-09-03 04:03:19 +00:00
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
from polls.decorators import polls_login_required
|
|
|
|
|
from polls.models import Notice
|
2020-09-03 09:46:04 +00:00
|
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2020-10-08 07:12:48 +00:00
|
|
|
|
from dashboard.models import Userprofile
|
2020-09-03 04:03:19 +00:00
|
|
|
|
|
2020-10-04 15:09:07 +00:00
|
|
|
|
|
2020-09-03 04:03:19 +00:00
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def notices(request):
|
2020-09-24 06:51:39 +00:00
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
id = request.user.id
|
2020-10-11 06:58:13 +00:00
|
|
|
|
notices = Notice.objects.filter(user__id=id)
|
2020-09-24 06:51:39 +00:00
|
|
|
|
results = []
|
|
|
|
|
for o in notices:
|
|
|
|
|
result = dict()
|
|
|
|
|
result['id'] = o.id
|
|
|
|
|
result['type'] = o.type
|
|
|
|
|
result['content'] = o.content
|
2020-10-08 07:12:48 +00:00
|
|
|
|
result['isRead'] = o.is_read
|
2020-09-24 06:51:39 +00:00
|
|
|
|
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
results.append(result)
|
2020-10-04 15:09:07 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
2020-09-24 06:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def notice_top(request):
|
2020-09-03 04:03:19 +00:00
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
id = request.user.id
|
2020-10-04 15:09:07 +00:00
|
|
|
|
notices = Notice.objects.filter(user__id=id, is_read=False)[:10]
|
2020-09-03 04:03:19 +00:00
|
|
|
|
results = []
|
|
|
|
|
for o in notices:
|
|
|
|
|
result = dict()
|
|
|
|
|
result['id'] = o.id
|
2020-09-24 06:51:39 +00:00
|
|
|
|
result['type'] = o.type
|
2020-09-03 09:46:04 +00:00
|
|
|
|
result['content'] = o.content
|
2020-10-08 07:12:48 +00:00
|
|
|
|
result['isRead'] = o.is_read
|
2020-09-03 04:03:19 +00:00
|
|
|
|
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
results.append(result)
|
2020-10-04 15:09:07 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
2020-09-03 09:46:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def read_notice(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
id = request.user.id
|
|
|
|
|
notice_id = request.POST.get('notice')
|
|
|
|
|
if not notice_id:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
try:
|
|
|
|
|
notice = Notice.objects.get(id=notice_id)
|
|
|
|
|
notice.is_read = True
|
|
|
|
|
notice.save()
|
|
|
|
|
return JsonResponse({'status': 'success'})
|
2020-09-24 06:51:39 +00:00
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
|
|
|
|
|
|
2020-09-30 08:02:29 +00:00
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def detail_notice(request, notice_id):
|
2020-10-08 07:12:48 +00:00
|
|
|
|
if request.method == 'POST':
|
2020-09-30 08:02:29 +00:00
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
if not notice_id:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
try:
|
|
|
|
|
notice = Notice.objects.get(id=notice_id)
|
|
|
|
|
results = dict()
|
|
|
|
|
results['id'] = notice.id
|
2020-10-04 15:09:07 +00:00
|
|
|
|
results['category'] = notice.type
|
|
|
|
|
results['content'] = notice.content
|
2020-11-17 00:45:44 +00:00
|
|
|
|
results['isRead'] = notice.is_read
|
2020-10-17 16:00:23 +00:00
|
|
|
|
if notice.type == 1:
|
|
|
|
|
ReplyModel = apps.get_model(notice.app, notice.model)
|
2020-10-26 00:56:41 +00:00
|
|
|
|
if notice.model == 'Userprofile':
|
|
|
|
|
profiles = ReplyModel.objects.filter(organization_id=notice.record_id).exclude(
|
|
|
|
|
admin_status__in=[0, 3])
|
|
|
|
|
m = []
|
|
|
|
|
for p in profiles:
|
|
|
|
|
n = dict()
|
|
|
|
|
n['id'] = p.user_id
|
|
|
|
|
n['name'] = p.name
|
|
|
|
|
n['adminStatus'] = p.admin_status
|
|
|
|
|
m.append(n)
|
|
|
|
|
results['profiles'] = m
|
2020-10-17 16:00:23 +00:00
|
|
|
|
else:
|
2020-10-26 00:56:41 +00:00
|
|
|
|
m = ReplyModel.objects.get(pk=notice.record_id)
|
|
|
|
|
detail = dict()
|
|
|
|
|
detail['id'] = m.id
|
|
|
|
|
detail['code'] = m.code
|
|
|
|
|
if notice.model == 'Weixin':
|
|
|
|
|
detail['type'] = 'weixin'
|
|
|
|
|
elif notice.model == 'Weibo':
|
|
|
|
|
detail['type'] = 'weibo'
|
|
|
|
|
elif notice.model == 'Toutiao':
|
|
|
|
|
detail['type'] = 'Toutiao'
|
|
|
|
|
elif notice.model == 'Douyin':
|
|
|
|
|
detail['type'] = 'douyin'
|
|
|
|
|
else:
|
|
|
|
|
detail['type'] = 'qita'
|
|
|
|
|
detail['status'] = m.status
|
|
|
|
|
results['media'] = detail
|
2020-10-21 13:37:19 +00:00
|
|
|
|
else:
|
2020-10-21 16:29:06 +00:00
|
|
|
|
results['groupId'] = notice.group_id
|
2020-10-04 15:09:07 +00:00
|
|
|
|
results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S")
|
2020-10-08 07:12:48 +00:00
|
|
|
|
results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
|
2020-10-22 13:52:48 +00:00
|
|
|
|
notice.is_read = True
|
|
|
|
|
notice.save()
|
2020-09-30 08:02:29 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': results})
|
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
|
|
|
|
|
|
2020-09-24 06:51:39 +00:00
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
2020-10-08 07:12:48 +00:00
|
|
|
|
def pass_notice(request):
|
2020-09-24 06:51:39 +00:00
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
id = request.user.id
|
|
|
|
|
notice_id = request.POST.get('notice_id')
|
|
|
|
|
if not notice_id:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
try:
|
|
|
|
|
notice = Notice.objects.get(id=notice_id)
|
|
|
|
|
ReplyModel = apps.get_model(notice.app, notice.model)
|
2020-10-25 18:11:34 +00:00
|
|
|
|
if notice.model == 'Userprofile':
|
|
|
|
|
pass_value = notice.record_pass_value
|
2020-10-26 00:56:41 +00:00
|
|
|
|
profiles = ReplyModel.objects.filter(
|
|
|
|
|
organization_id=notice.record_id)
|
|
|
|
|
if pass_value == '2': # 市级提交,1->2, 4->5
|
2020-10-25 18:11:34 +00:00
|
|
|
|
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()
|
2020-11-17 00:45:44 +00:00
|
|
|
|
group_notices = Notice.objects.filter(record_id=notice.record_id)
|
|
|
|
|
for n in group_notices:
|
|
|
|
|
n.is_read = True
|
|
|
|
|
n.save()
|
2020-10-25 18:11:34 +00:00
|
|
|
|
admins = Userprofile.level1_admin()
|
|
|
|
|
for a in admins:
|
2020-10-26 00:56:41 +00:00
|
|
|
|
Notice.create_reply_notice(
|
|
|
|
|
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0')
|
|
|
|
|
else: # 省级提交
|
2020-10-25 18:11:34 +00:00
|
|
|
|
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()
|
2020-11-17 00:45:44 +00:00
|
|
|
|
group_notices = Notice.objects.filter(record_id=notice.record_id)
|
|
|
|
|
for n in group_notices:
|
|
|
|
|
n.is_read = True
|
|
|
|
|
n.save()
|
2020-10-26 00:56:41 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': '申请已同意'})
|
2020-10-25 18:11:34 +00:00
|
|
|
|
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()
|
2020-11-17 00:45:44 +00:00
|
|
|
|
group_notices = Notice.objects.filter(record_id=notice.record_id)
|
|
|
|
|
for n in group_notices:
|
|
|
|
|
n.is_read = True
|
|
|
|
|
n.save()
|
2020-10-25 18:11:34 +00:00
|
|
|
|
pass_value = notice.record_pass_value
|
|
|
|
|
if pass_value == '2':
|
|
|
|
|
admins = Userprofile.level1_admin()
|
|
|
|
|
for a in admins:
|
2020-10-26 00:56:41 +00:00
|
|
|
|
Notice.create_reply_notice(
|
|
|
|
|
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0')
|
2020-10-25 18:11:34 +00:00
|
|
|
|
if pass_value == '5':
|
|
|
|
|
admins = Userprofile.level1_admin()
|
|
|
|
|
for a in admins:
|
2020-10-26 00:56:41 +00:00
|
|
|
|
Notice.create_reply_notice(
|
|
|
|
|
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3')
|
2020-10-25 18:11:34 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': '申请已同意'})
|
2020-10-08 07:12:48 +00:00
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def reject_notice(request):
|
|
|
|
|
if request.method == 'GET':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
id = request.user.id
|
|
|
|
|
notice_id = request.POST.get('notice_id')
|
|
|
|
|
if not notice_id:
|
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
|
|
|
|
try:
|
|
|
|
|
notice = Notice.objects.get(id=notice_id)
|
|
|
|
|
ReplyModel = apps.get_model(notice.app, notice.model)
|
2020-10-25 18:11:34 +00:00
|
|
|
|
if notice.model == 'Userprofile':
|
|
|
|
|
reject_value = notice.record_reject_value
|
2020-10-26 00:56:41 +00:00
|
|
|
|
profiles = ReplyModel.objects.filter(
|
|
|
|
|
organization_id=notice.record_id)
|
2020-10-25 18:11:34 +00:00
|
|
|
|
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()
|
2020-11-17 00:45:44 +00:00
|
|
|
|
group_notices = Notice.objects.filter(record_id=notice.record_id)
|
|
|
|
|
for n in group_notices:
|
|
|
|
|
n.is_read = True
|
|
|
|
|
n.save()
|
|
|
|
|
|
2020-10-25 18:11:34 +00:00
|
|
|
|
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()
|
2020-11-17 00:45:44 +00:00
|
|
|
|
group_notices = Notice.objects.filter(record_id=notice.record_id)
|
|
|
|
|
for n in group_notices:
|
|
|
|
|
n.is_read = True
|
|
|
|
|
n.save()
|
2020-10-25 18:11:34 +00:00
|
|
|
|
return JsonResponse({'status': 'success', 'message': '申请已拒绝'})
|
2020-09-03 09:46:04 +00:00
|
|
|
|
except ObjectDoesNotExist:
|
2020-10-04 15:09:07 +00:00
|
|
|
|
return JsonResponse({'status': 'error', 'message': '通知ID错误'})
|
2020-10-22 13:52:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
@polls_login_required
|
|
|
|
|
def unread_notice_count(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
return HttpResponse(status=405)
|
|
|
|
|
user_id = request.user.id
|
|
|
|
|
count = Notice.objects.filter(user_id=user_id, is_read=False).count()
|
|
|
|
|
return JsonResponse({'status': 'success', 'message': count})
|