add message
This commit is contained in:
parent
b3679a54af
commit
5f7a91eb6b
|
@ -132,6 +132,7 @@ MESSAGE_TYPE_CHOICES = (
|
|||
(1, 'url'),
|
||||
(2, 'file'),
|
||||
(3, 'image')
|
||||
(4, 'task')
|
||||
)
|
||||
|
||||
|
||||
|
@ -139,7 +140,7 @@ class Message(models.Model):
|
|||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||
send_from = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
send_to = models.ForeignKey(Group, on_delete=models.CASCADE)
|
||||
task = models.ForeignKey(Task, on_delete=models.CASCADE)
|
||||
task = models.ForeignKey(Task, on_delete=models.CASCADE, null=True, blank=True)
|
||||
type = models.IntegerField(
|
||||
'Type', choices=MESSAGE_TYPE_CHOICES, default=1)
|
||||
#text
|
||||
|
|
|
@ -10,8 +10,10 @@ urlpatterns = [
|
|||
path('send_code/', views.send_code, name='polls_send_code'),
|
||||
path('register/', views.register_step_one, name='polls_register'),
|
||||
path('register/save/', views.register_step_two, name='polls_register_save'),
|
||||
path('password/recovery/', views.password_recover_step_one, name='polls_password_recovery'),
|
||||
path('password/recovery/save/', views.password_recover_step_two, name='polls_password_recovery_save'),
|
||||
path('password/recovery/', views.password_recover_step_one,
|
||||
name='polls_password_recovery'),
|
||||
path('password/recovery/save/', views.password_recover_step_two,
|
||||
name='polls_password_recovery_save'),
|
||||
path('notices/list/', views.notices, name='polls_notices'),
|
||||
path('notices/top/', views.notice_top, name='polls_notice_top'),
|
||||
path('notices/read/', views.read_notice, name='polls_read_notice'),
|
||||
|
@ -20,17 +22,26 @@ urlpatterns = [
|
|||
path('medias/update/', views.update_media, name='polls_update_media'),
|
||||
path('medias/list/', views.medias, name='polls_medias'),
|
||||
path('medias/my/', views.my_medias, name='polls_my_medias'),
|
||||
path('medias/<str:type>/<str:media_id>/', views.media_detail, name='polls_media_detail'),
|
||||
path('medias/<str:type>/<str:media_id>/',
|
||||
views.media_detail, name='polls_media_detail'),
|
||||
path('news/list/', views.news_list, name='polls_news'),
|
||||
path('news/top/', views.news_top, name='polls_news_top'),
|
||||
path('news/detail/<str:news_id>/', views.news_detail, name='polls_news_detail'),
|
||||
path('monitor/statistics/', views.monitor_statistics, name='polls_monitor_statistics'),
|
||||
path('news/detail/<str:news_id>/',
|
||||
views.news_detail, name='polls_news_detail'),
|
||||
path('monitor/statistics/', views.monitor_statistics,
|
||||
name='polls_monitor_statistics'),
|
||||
path('tasks/list/', views.tasks, name='polls_tasks_list'),
|
||||
path('tasks/create/', views.create_task, name='polls_tasks_create'),
|
||||
path('tasks/create_test/', views.create_test_task, name='polls_tasks_create_test'),
|
||||
path('tasks/create_test/', views.create_test_task,
|
||||
name='polls_tasks_create_test'),
|
||||
path('groups/list/', views.groups, name='polls_groups_list'),
|
||||
path('groups/test-room/', views.room, name='polls_group_test_room'),
|
||||
path('compartments/list/', views.compartments, name='polls_compartments_list'),
|
||||
path('organizations/list/', views.organizations, name='polls_organizations_list'),
|
||||
path('messages/list/last/', views.last_messages, name='polls_messages_list_last'),
|
||||
path('compartments/list/', views.compartments,
|
||||
name='polls_compartments_list'),
|
||||
path('organizations/list/', views.organizations,
|
||||
name='polls_organizations_list'),
|
||||
path('messages/list/last/', views.last_messages,
|
||||
name='polls_messages_list_last'),
|
||||
path('messages/send/text/', views.send_text_message,
|
||||
name='polls_message_send_text')
|
||||
]
|
||||
|
|
|
@ -7,4 +7,4 @@ from .task import tasks, create_task, create_test_task
|
|||
from .group import groups, room
|
||||
from .compartment import compartments
|
||||
from .organizations import organizations
|
||||
from .message import last_messages
|
||||
from .message import last_messages, send_text_message
|
Binary file not shown.
Binary file not shown.
|
@ -18,8 +18,37 @@ def last_messages(request):
|
|||
messages = Message.objects.filter(send_to_id=group_id)
|
||||
results = []
|
||||
for o in messages:
|
||||
print(dir(o))
|
||||
result = dict()
|
||||
result['id'] = str(o.id)
|
||||
result['type'] = o.type
|
||||
result['user_name'] = o.send_from.username
|
||||
result['content'] = o.content
|
||||
result['page_title'] = o.page_title
|
||||
result['page_description'] = o.page_description
|
||||
result['page_image'] = o.page_image
|
||||
result['url'] = o.url
|
||||
result['file_title'] = o.file_title
|
||||
result['file'] = request.build_absolute_uri(o.file.uri) if o.file else ''
|
||||
result['image_title'] = o.image_title
|
||||
result['picture'] = request.build_absolute_uri(o.picture.uri) if o.picture else ''
|
||||
result['added'] = o.added.strftime("%Y-%m-%d %H:%M:%S")
|
||||
results.append(result)
|
||||
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@polls_login_required
|
||||
def send_text_message(request):
|
||||
if request.method == 'GET':
|
||||
return HttpResponse(status=405)
|
||||
user = request.user
|
||||
group_id = request.POST.get('group_id')
|
||||
if not group_id:
|
||||
return JsonResponse({'status': 'error', 'message': '参数错误'})
|
||||
content = request.POST.get('content')
|
||||
if not content:
|
||||
return JsonResponse({'status': 'error', 'message': '内容不能为空'})
|
||||
|
||||
normalMessage = Message.objects.create(
|
||||
type=0, send_from_id=user.id, send_to_id=group_id, content=content)
|
||||
return JsonResponse({'status': 'success'})
|
||||
|
|
Loading…
Reference in New Issue