<s> from __future__ import absolute_import <EOL> import csv <EOL> from decimal import Decimal <EOL> from json import JSONEncoder <EOL> from django . http import HttpResponse <EOL> class DecimalEncoder ( JSONEncoder ) : <EOL> def default ( self , obj ) : <EOL> if isinstance ( obj , Decimal ) : <EOL> return float ( obj ) <EOL> return super ( DecimalEncoder , self ) . default ( obj ) <EOL> class CSVViewMixin ( object ) : <EOL> def render_to_response ( self , context ) : <EOL> response = HttpResponse ( content_type = '<STR_LIT>' ) <EOL> fn = self . get_filename ( context ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' % fn <EOL> rows = self . convert_context_to_csv ( context ) <EOL> writer = csv . writer ( response ) <EOL> for row in rows : <EOL> writer . writerow ( row ) <EOL> return response <EOL> def get_filename ( self , context ) : <EOL> raise NotImplemented ( '<STR_LIT>' ) <EOL> def convert_context_to_csv ( self , context ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplemented ( '<STR_LIT>' ) </s>
