Merge remote-tracking branch 'origin/master' into visualize-discussion-graph
This commit is contained in:
commit
6cda24fb78
@ -32,6 +32,11 @@ def createLabels(data):
|
||||
|
||||
return(True)
|
||||
|
||||
def updateLabelsByParagraphId(data):
|
||||
for paragraph_ in data:
|
||||
Paragraph.objects.filter(pk = paragraph_['id']).update(label = paragraph_['label'])
|
||||
return(True)
|
||||
|
||||
def addToDatabase(data, file_id):
|
||||
out = {}
|
||||
para_id = []
|
||||
|
@ -3,11 +3,12 @@ from django.conf import settings
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import JsonResponse, HttpResponse
|
||||
import json
|
||||
|
||||
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, listPostsFromDiscussion
|
||||
from prototype.filehandler.functions import addToDatabase, listDiscussionsFromFile, listParagraphsFromDiscussion, createLabels, listPostsFromDiscussion, updateLabelsByParagraphId
|
||||
|
||||
|
||||
def home(request):
|
||||
@ -33,10 +34,19 @@ def model_form_upload(request):
|
||||
'form' : form
|
||||
})
|
||||
|
||||
@csrf_exempt
|
||||
def discussions(request, id):
|
||||
if request.method == 'GET':
|
||||
output = listParagraphsFromDiscussion(id)
|
||||
return JsonResponse(output, safe=False)
|
||||
|
||||
elif request.method == 'PATCH':
|
||||
received_data = json.loads(request.body.decode("utf-8"))
|
||||
if updateLabelsByParagraphId(received_data):
|
||||
output = listParagraphsFromDiscussion(id)
|
||||
return JsonResponse(output, safe=False)
|
||||
else:
|
||||
return HttpResponse('Błąd przy dodwaniu informacji do bazy danych', status=406)
|
||||
else:
|
||||
return HttpResponse('Nieobsługiwana metoda HTTP', status=406)
|
||||
|
||||
|
@ -26,7 +26,6 @@ urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('discussions/<int:id>', views.discussions),
|
||||
path('visualize/<int:id>', views.visualize)
|
||||
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
|
Loading…
Reference in New Issue
Block a user