<s> import csv <EOL> import io <EOL> import os <EOL> from django import forms <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext <EOL> import tempfile <EOL> class MsgForm ( forms . Form ) : <EOL> subject = forms . CharField ( max_length = <NUM_LIT:100> ) <EOL> message = forms . CharField ( ) <EOL> f = forms . FileField ( ) <EOL> def home ( request ) : <EOL> from django . conf import settings <EOL> print ( settings . SOME_VALUE ) <EOL> subject = None <EOL> message = None <EOL> size = <NUM_LIT:0> <EOL> print ( request . META ) <EOL> if request . POST : <EOL> form = MsgForm ( request . POST , request . FILES ) <EOL> print ( request . FILES ) <EOL> if form . is_valid ( ) : <EOL> subject = form . cleaned_data [ '<STR_LIT>' ] <EOL> message = form . cleaned_data [ '<STR_LIT:message>' ] <EOL> f = request . FILES [ '<STR_LIT:f>' ] <EOL> if not hasattr ( f , "<STR_LIT>" ) : <EOL> size = len ( f . read ( ) ) <EOL> else : <EOL> try : <EOL> size = int ( os . fstat ( f . fileno ( ) ) [ <NUM_LIT:6> ] ) <EOL> except io . UnsupportedOperation : <EOL> size = len ( f . read ( ) ) <EOL> else : <EOL> form = MsgForm ( ) <EOL> return render_to_response ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT>' : subject , <EOL> '<STR_LIT:message>' : message , <EOL> '<STR_LIT:size>' : size <EOL> } , RequestContext ( request ) ) <EOL> def acsv ( request ) : <EOL> rows = [ <EOL> { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:2> } , <EOL> { '<STR_LIT:a>' : <NUM_LIT:3> , '<STR_LIT:b>' : <NUM_LIT:3> } <EOL> ] <EOL> response = HttpResponse ( mimetype = '<STR_LIT>' ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> writer = csv . writer ( response ) <EOL> writer . writerow ( [ '<STR_LIT:a>' , '<STR_LIT:b>' ] ) <EOL> for r in rows : <EOL> writer . writerow ( [ r [ '<STR_LIT:a>' ] , r [ '<STR_LIT:b>' ] ] ) <EOL> return response </s>
