Added endpoint for listing posts for discussion visualization
This commit is contained in:
parent
16579fd1ff
commit
630e27e7b4
@ -92,3 +92,20 @@ def listParagraphsFromDiscussion(id):
|
||||
out['posts'] = posts_
|
||||
return(out)
|
||||
|
||||
def listPostsFromDiscussion(id):
|
||||
out = {}
|
||||
posts = Post.objects.filter(discussion_id = id)
|
||||
posts_array = []
|
||||
for post in posts:
|
||||
obj = {}
|
||||
obj['author'] = post.author
|
||||
obj['id'] = post.post_id
|
||||
obj['parent'] = post.parent
|
||||
message = ""
|
||||
paragraphs = Paragraph.objects.filter(post_id = post.pk)
|
||||
for paragraph in paragraphs:
|
||||
message += paragraph.message + " "
|
||||
obj['message'] = message.rstrip()
|
||||
posts_array.append(obj)
|
||||
out['posts'] = posts_array
|
||||
return(out)
|
||||
|
@ -7,7 +7,7 @@ from django.http import JsonResponse, HttpResponse
|
||||
from prototype.filehandler.models import Document, Forum
|
||||
from prototype.filehandler.forms import DocumentForm
|
||||
from prototype.filehandler.xmlParser import parseData
|
||||
from prototype.filehandler.functions import addToDatabase, listDiscussionsFromFile, listParagraphsFromDiscussion, createLabels
|
||||
from prototype.filehandler.functions import addToDatabase, listDiscussionsFromFile, listParagraphsFromDiscussion, createLabels, listPostsFromDiscussion
|
||||
|
||||
|
||||
def home(request):
|
||||
@ -39,3 +39,10 @@ def discussions(request, id):
|
||||
return JsonResponse(output, safe=False)
|
||||
else:
|
||||
return HttpResponse('Nieobsługiwana metoda HTTP', status=406)
|
||||
|
||||
def visualize(request, id):
|
||||
if request.method == 'GET':
|
||||
output = listPostsFromDiscussion(id)
|
||||
return JsonResponse(output, safe=False)
|
||||
else:
|
||||
return HttpResponse('Nieobsługiwana metoda HTTP', status=406)
|
||||
|
@ -24,7 +24,8 @@ urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('prototype/form/', views.model_form_upload, name='model_form_upload'),
|
||||
path('admin/', admin.site.urls),
|
||||
path('discussions/<int:id>', views.discussions)
|
||||
path('discussions/<int:id>', views.discussions),
|
||||
path('visualize/<int:id>', views.visualize)
|
||||
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user