diff --git a/backend/webapp/prototype/filehandler/functions.py b/backend/webapp/prototype/filehandler/functions.py index 35b4c5e..20ff7a9 100644 --- a/backend/webapp/prototype/filehandler/functions.py +++ b/backend/webapp/prototype/filehandler/functions.py @@ -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) diff --git a/backend/webapp/prototype/filehandler/views.py b/backend/webapp/prototype/filehandler/views.py index 68cd55c..21bb74c 100644 --- a/backend/webapp/prototype/filehandler/views.py +++ b/backend/webapp/prototype/filehandler/views.py @@ -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) diff --git a/backend/webapp/prototype/urls.py b/backend/webapp/prototype/urls.py index aeb791b..2a4212a 100644 --- a/backend/webapp/prototype/urls.py +++ b/backend/webapp/prototype/urls.py @@ -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/', views.discussions) + path('discussions/', views.discussions), + path('visualize/', views.visualize) ]