add message

This commit is contained in:
baoliang 2020-09-26 15:40:15 +08:00
parent 5f7a91eb6b
commit 6f86ec55c8
3 changed files with 7 additions and 3 deletions

View File

@ -131,7 +131,7 @@ MESSAGE_TYPE_CHOICES = (
(0, 'text'),
(1, 'url'),
(2, 'file'),
(3, 'image')
(3, 'image'),
(4, 'task')
)

View File

@ -6,7 +6,7 @@ from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
from polls.decorators import polls_login_required
from polls.models import Message, Task, TaskAddition
from polls.models import Message, Notice, Task, TaskAddition
from polls.tasks import process_task
from django.core.exceptions import ObjectDoesNotExist
from polls.utils import model_to_dict, queryset_to_list
@ -39,6 +39,7 @@ def create_task(request):
if request.method == 'GET':
return HttpResponse(status=405)
user = request.user
profile = user.userprofile_set.first()
content = request.POST.get('content')
if not content:
return JsonResponse({'status': 'error', 'message': '内容不能为空'})
@ -62,7 +63,10 @@ def create_task(request):
for group in groups:
normalMessage = Message.objects.create(
type=0, send_from_id=user.id, send_to_id=group, task=task, content=content)
type=4, send_from_id=user.id, send_to_id=group, task=task, content=content)
content = '用户%s发布了任务,请查收消息' % (profile.name,)
Notice.create_normal_notice(user.id, content, 'dashboard')
return JsonResponse({'status': 'success'})