bia-fitness/fitnotes/views.py

20 lines
663 B
Python
Raw Normal View History

2015-04-10 18:19:12 +00:00
from django.shortcuts import render
2015-04-10 18:19:40 +00:00
from . import importer
2015-04-10 18:19:12 +00:00
@login_required
def fitnotes_upload(request):
if request.method == 'POST':
form = FitnotesUploadForm(request.POST, request.FILES)
if form.is_valid():
_, fname = tempfile.mkstemp()
with open(fname, 'wb') as tmp:
for chunk in request.FILES['file'].chunks():
tmp.write(chunk)
try:
2015-04-10 18:19:40 +00:00
importer.import_fitnotes_db(fname, request.user)
2015-04-10 18:19:12 +00:00
finally:
os.remove(fname)
else:
form = FitnotesUploadForm()
return render(request, 'lifting/fitnotes.html', {'form': form})