add message

This commit is contained in:
baoliang 2021-01-10 21:22:39 +08:00
parent 9697d1bcd7
commit 1a632e63e5
9 changed files with 51 additions and 18 deletions

View File

@ -1,4 +1,5 @@
import json
from polls.utils import send_tnps
from polls.models import Notice
from django.contrib import messages
@ -1717,12 +1718,14 @@ def news_management_create(request):
news = News(type=t, title=title, author=author, date=date, content=content, source=source, image=image)
news.save()
if t== 5:
profiles = Userprofile.objects.filter(id=15)
if t == '5':
profiles = Userprofile.objects.filter(status=1)
content = '管理员发布了通知,请查收消息'
phones = []
for p in profiles:
content = '%s发布了通知,请查收消息' % (p, )
phones.append(p.user.username)
Notice.create_news_notice(p.user_id, content, news.id)
send_tnps(phones, content)
messages.success(request, '添加成功!!!')
return HttpResponseRedirect('/management/news/management/create/')
type = News.NEWMEDIA_NEWS_CHOICES

View File

@ -77,7 +77,7 @@ class Notice(models.Model):
@classmethod
def create_news_notice(cls, user_id, content, news_id):
return Notice.objects.create(user_id=user_id, content=content, news_id=news_id)
return Notice.objects.create(type=2, user_id=user_id, content=content, news_id=news_id)
@classmethod
def create_reply_notice(cls, user_id, content, app, model, field, record_id, record_pass_value, record_reject_value):

View File

@ -14,7 +14,6 @@ from aliyunsdkcore.profile import region_provider
def send_tnps(phones, content):
url = 'https://api.tpns.tencent.com//v3/push/app'
r = requests.post(url,
auth=HTTPBasicAuth(
@ -23,11 +22,12 @@ def send_tnps(phones, content):
"audience_type": "account_list",
"account_list": phones,
"message": {
"title": "【新媒体管理】有新消息",
"content": content
"title": content,
"content": ''
},
"message_type": "notify"
})
return r
def sent_sms_code(phone, code):
@ -166,4 +166,6 @@ if __name__ == '__main__':
# 'http://xgs.gansudaily.com.cn/pages/h5/hot/b3297046a53e47f594ed19db90c1183c.html')
# print(og_title, og_description, og_url, og_image)
print(send_voice_notify('13993199566'))
# print(send_voice_notify('13993199566'))
r = send_tnps(['13609346975'], '')
print(r.status_code, r.text)

View File

@ -1,3 +1,4 @@
from polls.utils import send_tnps
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.core.paginator import Paginator
@ -80,17 +81,22 @@ def create_media(request):
instance.save()
if o.is_direct():
admins = Userprofile.level1_admin()
for a in admins:
content = '%s创建了新媒体,请审核' % (profile,)
phones = []
for a in admins:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '3', '0')
send_tnps(phones, content)
else:
admins = Userprofile.level2_admin(instance.organization.cities)
for a in admins:
content = '%s创建了新媒体,请审核' % (profile,)
phones = []
for a in admins:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
send_tnps(phones, content)
return JsonResponse({'status': 'success'})
@ -228,19 +234,24 @@ def delete_media(request):
instance.status = 5
instance.save()
managers = Userprofile.level1_admin()
for a in managers:
content = '%s申请注销新媒体,请审核' % (profile,)
phones = []
for a in managers:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '0', '3')
send_tnps(phones, content)
else:
instance.status = 4
instance.save()
managers = Userprofile.level2_admin(instance.organization.cities)
for a in managers:
content = '%s申请注销新媒体,请审核' % (profile,)
phones = []
for a in managers:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '5', '3')
send_tnps(phones, content)
admins = []
for admin in instance.organization.userprofile_set.all():
u = dict()
@ -292,10 +303,13 @@ def media_admin_change(request):
profile.admin_status = 5
profile.save()
managers = Userprofile.level1_admin()
for a in managers:
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': '变更申请发送成功'})
else:
obj, created = UserModel.objects.get_or_create(
@ -309,8 +323,11 @@ def media_admin_change(request):
profile.admin_status = 4
profile.save()
managers = Userprofile.level2_admin(o.cities)
for a in managers:
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': '变更申请发送成功'})

View File

@ -1,3 +1,4 @@
from polls.utils import send_tnps
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
@ -152,9 +153,12 @@ def pass_notice(request):
n.is_read = True
n.save()
admins = Userprofile.level1_admin()
phones = []
for a in admins:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0')
send_tnps(phones, notice.content)
else: # 省级提交
for p in profiles:
if p.admin_status == 5:
@ -181,14 +185,20 @@ def pass_notice(request):
pass_value = notice.record_pass_value
if pass_value == '2':
admins = Userprofile.level1_admin()
phones = []
for a in admins:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '3', '0')
send_tnps(phones, notice.content)
if pass_value == '5':
admins = Userprofile.level1_admin()
phones = []
for a in admins:
phones.append(a.user.username)
Notice.create_reply_notice(
a.user.id, notice.content, notice.app, notice.model, notice.field, notice.record_id, '0', '3')
send_tnps(phones, notice.content)
return JsonResponse({'status': 'success', 'message': '申请已同意'})
except ObjectDoesNotExist:
return JsonResponse({'status': 'error', 'message': '通知ID错误'})

View File

@ -6,7 +6,7 @@ import datetime
from polls.decorators import polls_login_required
from polls.models import Message, Notice, Task, TaskAddition, TaskRecord
from django.core.exceptions import ObjectDoesNotExist
from polls.utils import model_to_dict, queryset_to_list, parse
from polls.utils import model_to_dict, queryset_to_list, parse, send_tnps
from dashboard.models import Group, Group_user, Userprofile
@ -72,6 +72,7 @@ def create_task(request):
if profile and profile.status == 1:
content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name)
Notice.create_normal_notice(u.user_id, content, group)
send_tnps([u.username], content)
return JsonResponse({'status': 'success'})