fix upload
This commit is contained in:
parent
d907467561
commit
d930beaa4e
@ -1,16 +1,30 @@
|
|||||||
|
import tempfile
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
import os
|
||||||
|
|
||||||
|
from . import importers
|
||||||
|
|
||||||
|
|
||||||
class FitnotesUploadForm(forms.Form):
|
class FitnotesUploadForm(forms.Form):
|
||||||
file = forms.FileField()
|
file = forms.FileField()
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
def fitnotes_upload(request):
|
def fitnotes_upload(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = FitnotesUploadForm(request.POST, request.FILES)
|
form = FitnotesUploadForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
print(request.FILES['file'])
|
_, fname = tempfile.mkstemp()
|
||||||
|
with open(fname, 'wb') as tmp:
|
||||||
|
for chunk in request.FILES['file'].chunks():
|
||||||
|
tmp.write(chunk)
|
||||||
|
try:
|
||||||
|
importers.import_fitnotes_db(fname, request.user)
|
||||||
|
finally:
|
||||||
|
os.remove(fname)
|
||||||
else:
|
else:
|
||||||
form = FitnotesUploadForm()
|
form = FitnotesUploadForm()
|
||||||
return render(request, 'upload.html', {'form': form})
|
return render(request, 'upload.html', {'form': form})
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<form method="post">
|
<form action="." method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{form}}
|
{{form}}
|
||||||
<input type="submit" />
|
<input type="submit" value="Upload" />
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user