diff --git a/backend/webapp/prototype/filehandler/views.py b/backend/webapp/prototype/filehandler/views.py index b01f04c..c48679b 100644 --- a/backend/webapp/prototype/filehandler/views.py +++ b/backend/webapp/prototype/filehandler/views.py @@ -16,14 +16,14 @@ def home(request): @csrf_exempt def model_form_upload(request): if request.method == 'POST': - try: - form = DocumentForm(request.POST, request.FILES) - if form.is_valid(): + form = DocumentForm(request.POST, request.FILES) + if form.is_valid(): + try: data = parseData(request.FILES['file']) form.save() return JsonResponse(data, safe=False) - except: - return HttpResponse('Niepoprawny format XML', status=406) + except: + return HttpResponse('Niepoprawny format XML', status=406) else: form = DocumentForm() return render(request, 'core/model_form_upload.html', { diff --git a/backend/webapp/prototype/filehandler/xmlParser.py b/backend/webapp/prototype/filehandler/xmlParser.py index 4c81ce9..7fdee29 100644 --- a/backend/webapp/prototype/filehandler/xmlParser.py +++ b/backend/webapp/prototype/filehandler/xmlParser.py @@ -18,31 +18,29 @@ def parseData(file): f.write(chunk) f.close() - try: - # make a soup: - with open(fd.name) as forum: - soup = BeautifulSoup(forum, "xml") + # make a soup: + with open(fd.name) as forum: + soup = BeautifulSoup(forum, "xml") - # put json together - out = {} - out['id'] = soup.forum.get('id') - out['name'] = soup.forum.find('name').text - out['discussions'] = [] - for d in soup.forum.find_all('discussion'): - posts = [] - for p in d.find_all('post'): - posts.append({ - 'id': p.get('id'), - 'parent': p.find('parent').text, - 'author': p.userid.text, - 'message': p.message.get_text() - }) - out['discussions'].append({ - 'id': d.get('id'), - 'title': d.find('name').text, - 'first_post': d.firstpost.text, - 'posts': posts - }) - return(out) - finally: - fd.close() + # put json together + out = {} + out['id'] = soup.forum.get('id') + out['name'] = soup.forum.find('name').text + out['discussions'] = [] + for d in soup.forum.find_all('discussion'): + posts = [] + for p in d.find_all('post'): + posts.append({ + 'id': p.get('id'), + 'parent': p.find('parent').text, + 'author': p.userid.text, + 'message': p.message.get_text() + }) + out['discussions'].append({ + 'id': d.get('id'), + 'title': d.find('name').text, + 'first_post': d.firstpost.text, + 'posts': posts + }) + fd.close() + return(out) diff --git a/backend/webapp/prototype/settings.py b/backend/webapp/prototype/settings.py index 69d9ad5..a8003dc 100644 --- a/backend/webapp/prototype/settings.py +++ b/backend/webapp/prototype/settings.py @@ -79,12 +79,8 @@ WSGI_APPLICATION = 'prototype.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': 'mydb', - 'USER': 'kushiji', - 'PASSWORD': 'battle55', - 'HOST': 'localhost', - 'PORT': '3306', + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }