refactor message
This commit is contained in:
parent
26374732fd
commit
570e1bb347
Binary file not shown.
Binary file not shown.
|
@ -5,7 +5,7 @@ import datetime
|
|||
|
||||
from polls.decorators import polls_login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from polls.models import Message, TaskRecord
|
||||
from polls.models import Message, Task, TaskRecord
|
||||
from dashboard.models import Group_user, Userprofile
|
||||
|
||||
|
||||
|
@ -18,10 +18,24 @@ def last_messages(request):
|
|||
group_id = request.GET.get('group_id')
|
||||
messages = Message.objects.filter(send_to_id=group_id)[:100]
|
||||
results = []
|
||||
filter_dict = dict()
|
||||
for m in messages:
|
||||
if m.type == 4 or m.type == 1:
|
||||
task_id = m.task_id
|
||||
if task_id:
|
||||
if task_id in filter_dict:
|
||||
c = filter_dict[task_id]
|
||||
for o in messages:
|
||||
result = dict()
|
||||
t = o.type
|
||||
if t == 4:
|
||||
continue
|
||||
result['id'] = str(o.id)
|
||||
result['type'] = o.type
|
||||
result['type'] = t
|
||||
if t == 1:
|
||||
t_id = o.task_id
|
||||
task = Task.objects.get(id=t_id)
|
||||
result['title'] = task.content
|
||||
profile = Userprofile.objects.filter(user_id=o.send_from_id).first()
|
||||
result['user_name'] = profile.name
|
||||
result['organization'] = profile.organization.name
|
||||
|
@ -70,7 +84,7 @@ def is_read_message(request):
|
|||
return JsonResponse({'status': 'success', 'message': False}, safe=False)
|
||||
|
||||
is_exists = TaskRecord.objects.filter(
|
||||
task__message__id=message_id).exists()
|
||||
task__message__id=message_id, user_id=id).exists()
|
||||
return JsonResponse({'status': 'success', 'message': is_exists}, safe=False)
|
||||
|
||||
|
||||
|
@ -81,6 +95,7 @@ def read_message(request):
|
|||
return HttpResponse(status=405)
|
||||
user = request.user
|
||||
message_id = request.POST.get('message_id')
|
||||
print(message_id)
|
||||
if not message_id:
|
||||
return JsonResponse({'status': 'success', 'message': False}, safe=False)
|
||||
message = Message.objects.get(id=message_id)
|
||||
|
|
|
@ -38,7 +38,7 @@ def create_task(request):
|
|||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
user = request.user
|
||||
profile = user.userprofile_set.first()
|
||||
creater_profile = user.userprofile_set.first()
|
||||
content = request.POST.get('content')
|
||||
if not content:
|
||||
return JsonResponse({'status': 'error', 'message': '内容不能为空'})
|
||||
|
@ -63,16 +63,15 @@ def create_task(request):
|
|||
if picture:
|
||||
pictureAddtion = TaskAddition.objects.create(
|
||||
task=task, category=2, image=picture)
|
||||
|
||||
for group in groups:
|
||||
users = Group_user.objects.filter(group_id=group)
|
||||
for u in users:
|
||||
g = Group.objects.get(id=group)
|
||||
profile = Userprofile.objects.filter(user_id=u.user_id).first()
|
||||
if profile and profile.status == 1:
|
||||
content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name)
|
||||
content = '%s在群组“%s”发布了任务,请查收消息' % (creater_profile, g.name)
|
||||
Notice.create_normal_notice(u.user_id, content, group)
|
||||
# send_tnps([u.username], content)
|
||||
send_tnps([u.username], content)
|
||||
return JsonResponse({'status': 'success'})
|
||||
|
||||
|
||||
|
@ -102,7 +101,8 @@ def get_task(request):
|
|||
for r in records:
|
||||
p = dict()
|
||||
p['id'] = r.user_id
|
||||
is_finished = TaskRecord.objects.filter(user_id=r.user_id, task_id=task_id)
|
||||
is_finished = TaskRecord.objects.filter(
|
||||
user_id=r.user_id, task_id=task_id)
|
||||
p['status'] = '完成' if is_finished else '未完成'
|
||||
profile = Userprofile.objects.filter(user_id=r.user_id).first()
|
||||
p['name'] = profile.name
|
||||
|
@ -112,6 +112,7 @@ def get_task(request):
|
|||
result['added'] = task.added.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return JsonResponse({'status': 'success', 'message': result})
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def create_test_task(request):
|
||||
# if request.method == 'GET':
|
||||
|
|
Loading…
Reference in New Issue