Cleanup and reverted back to SQLite
This commit is contained in:
parent
0d479e23ad
commit
9fd6529e2b
@ -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', {
|
||||
|
@ -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)
|
||||
|
@ -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'),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user