add message
This commit is contained in:
parent
2cbe11b8d7
commit
9af96aad1d
|
@ -32,6 +32,8 @@ urlpatterns = [
|
|||
path('medias/admin/my/', views.my_media_admins, name='polls_my_media_admins'),
|
||||
path('medias/admin/change/', views.media_admin_change,
|
||||
name='polls_media_admin_change'),
|
||||
path('medias/admin/delete/', views.media_admin_delete,
|
||||
name='polls_media_admin_delete'),
|
||||
path('medias/<str:type>/<str:media_id>/',
|
||||
views.media_detail, name='polls_media_detail'),
|
||||
path('medias/delete/', views.delete_media, name='polls_delete_media'),
|
||||
|
@ -69,6 +71,10 @@ urlpatterns = [
|
|||
name='polls_organizations_list'),
|
||||
path('organizations/level/', views.organization_level,
|
||||
name='polls_organization_level'),
|
||||
path('organizations/districts/', views.organization_districts,
|
||||
name="polls_organization_districts"),
|
||||
path('organizations/create/', views.create_organization,
|
||||
name='polls_add_organization'),
|
||||
path('messages/list/last/', views.last_messages,
|
||||
name='polls_messages_list_last'),
|
||||
path('messages/send/text/', views.send_text_message,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from .user import index, status_500, status_401, polls_login, send_code, register_step_one, register_step_two, password_recover_step_one, password_recover_step_two, reset_password, upload_profile
|
||||
from .notice import notices, notice_top, read_notice, pass_notice, reject_notice, detail_notice, unread_notice_count
|
||||
from .media import medias, media_admins, my_medias, create_media, update_media, media_detail, delete_media, media_admin_change, my_media_admins
|
||||
from .media import medias, media_admins, my_medias, create_media, update_media, media_detail, delete_media, media_admin_change, my_media_admins, media_admin_delete
|
||||
from .news import news_list, news_top, news_detail
|
||||
from .monitor import monitor_statistics, monitor_result, media_statistics, city_ranking, monitor_unqualified_result, monitor_unqualified_index
|
||||
from .task import tasks, create_task, create_test_task, get_task
|
||||
from .group import groups, room, is_level1_or_leve2, group_member, group_manager, group_enter, group_leave, pick_groups
|
||||
from .compartment import compartments
|
||||
from .organizations import organizations, organization_level
|
||||
from .organizations import organizations, organization_level, organization_districts, create_organization
|
||||
from .message import last_messages, send_text_message, is_read_message, read_message
|
||||
from .download import download, app_intro, has_update
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -19,18 +19,22 @@ def medias(request):
|
|||
new_medias = NewMedia.media_list(organization_id)
|
||||
return JsonResponse({'status': 'success', 'message': new_medias}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def media_admins(request):
|
||||
if request.method == 'POST':
|
||||
return HttpResponse(status=405)
|
||||
organization_id = request.GET.get('organization_id')
|
||||
profiles = Userprofile.objects.filter(organization_id=organization_id)
|
||||
profiles = Userprofile.objects.filter(
|
||||
organization_id=organization_id).exclude(admin_status=0)
|
||||
results = []
|
||||
for p in profiles:
|
||||
result = dict()
|
||||
result['id'] = p.id
|
||||
result['name'] = p.name
|
||||
result['phone'] = p.user.username
|
||||
result['adminStatus'] = p.admin_status
|
||||
results.append(result)
|
||||
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
||||
|
||||
|
@ -46,6 +50,7 @@ def my_medias(request):
|
|||
new_medias = NewMedia.media_list(organization_id)
|
||||
return JsonResponse({'status': 'success', 'message': new_medias}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def my_media_admins(request):
|
||||
|
@ -54,12 +59,15 @@ def my_media_admins(request):
|
|||
user = request.user
|
||||
profile = user.userprofile_set.first()
|
||||
organization_id = profile.organization.id
|
||||
profiles = Userprofile.objects.filter(organization_id=organization_id)
|
||||
profiles = Userprofile.objects.filter(
|
||||
organization_id=organization_id).exclude(admin_status=0)
|
||||
results = []
|
||||
for p in profiles:
|
||||
result = dict()
|
||||
result['id'] = p.id
|
||||
result['name'] = p.name
|
||||
result['phone'] = p.user.username
|
||||
result['adminStatus'] = p.admin_status
|
||||
results.append(result)
|
||||
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
||||
|
||||
|
@ -72,6 +80,7 @@ def create_media(request):
|
|||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
f = request.FILES.get('file')
|
||||
organization_id = request.POST.get('organization_id', o.id)
|
||||
category = request.POST.get('category')
|
||||
if not category:
|
||||
return JsonResponse({'status': 'error', 'message': '类型错误'})
|
||||
|
@ -92,24 +101,24 @@ def create_media(request):
|
|||
if category == 'weixin':
|
||||
model_name = 'Weixin'
|
||||
instance = Weixin(code=code, weixinid=media_id, alias=alias,
|
||||
image=f, status=status, organization=o, attention=attention, remark=remark)
|
||||
image=f, status=status, organization_id=organization_id, attention=attention, remark=remark)
|
||||
elif category == 'weibo':
|
||||
model_name = 'Weibo'
|
||||
instance = Weibo(code=code, weiboid=media_id, alias=alias,
|
||||
image=f, status=status, organization=o, attention=attention, remark=remark)
|
||||
image=f, status=status, organization_id=organization_id, attention=attention, remark=remark)
|
||||
elif category == 'toutiao':
|
||||
model_name = 'Toutiao'
|
||||
instance = Toutiao(code=code, toutiaoid=media_id, alias=alias,
|
||||
image=f, status=status, organization=o, attention=attention, remark=remark)
|
||||
image=f, status=status, organization_id=organization_id, attention=attention, remark=remark)
|
||||
elif category == 'douyin':
|
||||
model_name = 'Douyin'
|
||||
instance = Douyin(code=code, douyinid=media_id, alias=alias,
|
||||
image=f, status=status, organization=o, attention=attention, remark=remark)
|
||||
image=f, status=status, organization_id=organization_id, attention=attention, remark=remark)
|
||||
else:
|
||||
model_name = 'Qita'
|
||||
type = request.POST.get('type')
|
||||
instance = Qita(code=code, qitaid=media_id, alias=alias,
|
||||
image=f, status=status, organization=o, attention=attention, remark=remark)
|
||||
image=f, status=status, organization_id=organization_id, attention=attention, remark=remark)
|
||||
instance.save()
|
||||
if o.is_direct():
|
||||
admins = Userprofile.level1_admin()
|
||||
|
@ -129,7 +138,7 @@ def create_media(request):
|
|||
Notice.create_reply_notice(
|
||||
a.user.id, content, 'dashboard', model_name, 'status', instance.id, '2', '0')
|
||||
send_tnps(phones, '审核', content)
|
||||
return JsonResponse({'status': 'success'})
|
||||
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': organization_id}}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
@ -240,7 +249,6 @@ def delete_media(request):
|
|||
return HttpResponse(status=405)
|
||||
profile = request.user.userprofile_set.first()
|
||||
o = profile.organization
|
||||
|
||||
category = request.POST.get('category')
|
||||
if not category:
|
||||
return JsonResponse({'status': 'error', 'message': '参数错误'})
|
||||
|
@ -290,23 +298,7 @@ def delete_media(request):
|
|||
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()
|
||||
u['id'] = admin.user.id
|
||||
u['name'] = admin.name
|
||||
u['phone'] = admin.user.username
|
||||
admins.append(u)
|
||||
|
||||
result['id'] = instance.id
|
||||
result['code'] = instance.code
|
||||
result['alias'] = instance.alias
|
||||
result['status'] = instance.status
|
||||
result['attention'] = instance.attention
|
||||
result['remark'] = instance.remark
|
||||
result['organization'] = instance.organization.name
|
||||
result['admin'] = admins
|
||||
return JsonResponse({'status': 'success', 'message': result})
|
||||
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
@ -348,7 +340,7 @@ def media_admin_change(request):
|
|||
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': '变更申请发送成功'})
|
||||
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}})
|
||||
else:
|
||||
obj, created = UserModel.objects.get_or_create(
|
||||
username=phone, last_login=datetime.now())
|
||||
|
@ -368,4 +360,43 @@ def media_admin_change(request):
|
|||
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': '变更申请发送成功'})
|
||||
return JsonResponse({'status': 'success', 'message': {'title': o.name, 'organizationId': o.id}})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def media_admin_delete(request):
|
||||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
id = request.POST.get('id')
|
||||
if not id:
|
||||
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(): # 如果是省直
|
||||
profile.admin_status = 5
|
||||
profile.save()
|
||||
managers = Userprofile.level1_admin()
|
||||
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': {'title': o.name, 'organizationId': o.id}}, safe=False)
|
||||
else:
|
||||
profile.admin_status = 4
|
||||
profile.save()
|
||||
managers = Userprofile.level2_admin(o.cities)
|
||||
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': {'title': o.name, 'organizationId': o.id}}, safe=False)
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
from polls.utils import send_tnps
|
||||
from polls.models import Notice
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from dashboard.models import Organization
|
||||
from dashboard.models import Area_code_2020, Organization, Userprofile
|
||||
from django.http import JsonResponse
|
||||
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
@ -57,4 +60,60 @@ def organization_level(request):
|
|||
level = organization.level.level
|
||||
if not level:
|
||||
return JsonResponse({'status': 'error', 'message': '权限错误'})
|
||||
return JsonResponse({'status': 'success', 'message': {'level': level, 'province':organization.province, 'cities': organization.cities, 'district': organization.district}}, safe=False)
|
||||
return JsonResponse({'status': 'success', 'message': {'level': level, 'province': organization.province, 'cities': organization.cities, 'district': organization.district}}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def organization_districts(request):
|
||||
code = request.GET.get('code', "620100000000")
|
||||
districts = Area_code_2020.objects.filter(pcode=code)
|
||||
results = []
|
||||
for o in districts:
|
||||
result = dict()
|
||||
result['value'] = o.code
|
||||
result['label'] = o.name
|
||||
results.append(result)
|
||||
return JsonResponse({'status': 'success', 'message': {'districts': results}}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def create_organization(request):
|
||||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
profile = request.user.userprofile_set.first()
|
||||
name = request.POST.get('name')
|
||||
if not name:
|
||||
return JsonResponse({'status': 'error', 'message': '名称不能为空'})
|
||||
if Organization.objects.filter(name=name).exists():
|
||||
return JsonResponse({'status': 'error', 'message': '名称已经存在'})
|
||||
province = request.POST.get('province')
|
||||
cities = request.POST.get('cities')
|
||||
district = request.POST.get('district')
|
||||
directly = '否'
|
||||
admin_status = 1
|
||||
if (not cities) and (not district):
|
||||
directly = '是'
|
||||
admin_status = 2
|
||||
o = Organization.objects.create(name=name, province=province, cities=cities, district=district, directly=directly,
|
||||
image='danweimoren.jpg', status='1', level_id='69be9ef4-b7b7-4049-a86e-7083bee40f0e', admin_status=admin_status)
|
||||
if o.is_direct():
|
||||
admins = Userprofile.level1_admin()
|
||||
content = '%s创建了机构,请审核' % (profile,)
|
||||
phones = []
|
||||
for a in admins:
|
||||
phones.append(a.user.username)
|
||||
Notice.create_reply_notice(
|
||||
a.user.id, content, 'dashboard', 'Organization', 'admin_status', o.id, '3', '0')
|
||||
send_tnps(phones, '审核', content)
|
||||
else:
|
||||
admins = Userprofile.level2_admin(cities)
|
||||
content = '%s创建了机构,请审核' % (profile,)
|
||||
phones = []
|
||||
for a in admins:
|
||||
phones.append(a.user.username)
|
||||
Notice.create_reply_notice(
|
||||
a.user.id, content, 'dashboard', 'Organization', 'admin_status', o.id, '2', '0')
|
||||
send_tnps(phones, '审核', content)
|
||||
return JsonResponse({'status': 'success'})
|
||||
|
|
Loading…
Reference in New Issue