benoitc 7715199b48 it's better to test when you use the right code to do it. We had a
blocking operation django example (we read a file already on the fs and
recreate another which blocked async schedulers).

While I'm here ease the code of eventlet worker. Just use the convenient
eventlet.serve function which already manage what we do and revert sopme
useless changes in body and header parsing.
2010-09-02 14:55:56 +02:00

58 lines
1.3 KiB
Python
Executable File

# Create your views here.
import csv
import os
from django import forms
from django.http import HttpResponse
from django.shortcuts import render_to_response
import tempfile
class MsgForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField()
f = forms.FileField()
def home(request):
subject = None
message = None
size = 0
print request.META
if request.POST:
form = MsgForm(request.POST, request.FILES)
print request.FILES
if form.is_valid():
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
f = request.FILES['f']
size = int(os.fstat(f.fileno())[6])
else:
form = MsgForm()
return render_to_response('home.html', {
'form': form,
'subject': subject,
'message': message,
'size': size
})
def acsv(request):
rows = [
{'a': 1, 'b': 2},
{'a': 3, 'b': 3}
]
response = HttpResponse(mimetype='text/csv')
response['Content-Disposition'] = 'attachment; filename=report.csv'
writer = csv.writer(response)
writer.writerow(['a', 'b'])
for r in rows:
writer.writerow([r['a'], r['b']])
return response