<s> '''<STR_LIT>''' <EOL> import csv <EOL> from decimal import Decimal <EOL> from StringIO import StringIO <EOL> from django . http import HttpResponse <EOL> from django . views . generic import View <EOL> from . . api . transactions import ( BillingsQuerysetMixin , <EOL> SmartTransactionListMixin , TransactionQuerysetMixin , TransferQuerysetMixin ) <EOL> from . . utils import datetime_or_now <EOL> class CSVDownloadView ( View ) : <EOL> basename = '<STR_LIT>' <EOL> headings = [ ] <EOL> def get ( self , * args , ** kwargs ) : <EOL> content = StringIO ( ) <EOL> csv_writer = csv . writer ( content ) <EOL> csv_writer . writerow ( self . get_headings ( ) ) <EOL> for record in self . get_queryset ( ) : <EOL> csv_writer . writerow ( self . queryrow_to_columns ( record ) ) <EOL> content . seek ( <NUM_LIT:0> ) <EOL> resp = HttpResponse ( content , content_type = '<STR_LIT>' ) <EOL> resp [ '<STR_LIT>' ] = '<STR_LIT>' . format ( <EOL> self . get_filename ( ) ) <EOL> return resp <EOL> def get_headings ( self ) : <EOL> return self . headings <EOL> def get_queryset ( self ) : <EOL> raise NotImplementedError <EOL> def get_filename ( self ) : <EOL> return datetime_or_now ( ) . strftime ( self . basename + '<STR_LIT>' ) <EOL> def queryrow_to_columns ( self , record ) : <EOL> raise NotImplementedError <EOL> class TransactionDownloadView ( SmartTransactionListMixin , <EOL> TransactionQuerysetMixin , CSVDownloadView ) : <EOL> basename = '<STR_LIT>' <EOL> headings = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:description>' <EOL> ] <EOL> def get_queryset ( self ) : <EOL> return super ( TransactionDownloadView , self ) . get_queryset ( ) . order_by ( <EOL> '<STR_LIT>' ) <EOL> def queryrow_to_columns ( self , transaction ) : <EOL> return [ <EOL> transaction . created_at . date ( ) , <EOL> '<STR_LIT>' . format ( Decimal ( transaction . dest_amount ) / <NUM_LIT:100> ) , <EOL> transaction . dest_unit . encode ( '<STR_LIT:utf-8>' ) , <EOL> transaction . dest_organization . printable_name . encode ( '<STR_LIT:utf-8>' ) , <EOL> transaction . dest_account . encode ( '<STR_LIT:utf-8>' ) , <EOL> '<STR_LIT>' . format ( Decimal ( transaction . orig_amount ) / <NUM_LIT:100> ) , <EOL> transaction . orig_unit . encode ( '<STR_LIT:utf-8>' ) , <EOL> transaction . orig_organization . printable_name . encode ( '<STR_LIT:utf-8>' ) , <EOL> transaction . orig_account . encode ( '<STR_LIT:utf-8>' ) , <EOL> ( '<STR_LIT>' % transaction . descr . replace ( <EOL> '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> ] <EOL> class BillingStatementDownloadView ( SmartTransactionListMixin , <EOL> BillingsQuerysetMixin , CSVDownloadView ) : <EOL> basename = '<STR_LIT>' <EOL> headings = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def queryrow_to_columns ( self , transaction ) : <EOL> return [ <EOL> transaction . created_at . date ( ) , <EOL> '<STR_LIT>' . format ( <EOL> ( - <NUM_LIT:1> if transaction . is_debit ( self . organization ) else <NUM_LIT:1> ) * <EOL> Decimal ( transaction . dest_amount ) / <NUM_LIT:100> ) , <EOL> transaction . dest_unit . encode ( '<STR_LIT:utf-8>' ) , <EOL> ( '<STR_LIT>' % transaction . descr . replace ( <EOL> '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> ] <EOL> class TransferDownloadView ( SmartTransactionListMixin , <EOL> TransferQuerysetMixin , CSVDownloadView ) : <EOL> basename = '<STR_LIT>' <EOL> headings = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> def queryrow_to_columns ( self , transaction ) : <EOL> return [ <EOL> transaction . created_at . date ( ) , <EOL> '<STR_LIT>' . format ( <EOL> ( - <NUM_LIT:1> if transaction . is_debit ( self . organization ) else <NUM_LIT:1> ) * <EOL> Decimal ( transaction . dest_amount ) / <NUM_LIT:100> ) , <EOL> transaction . dest_unit . encode ( '<STR_LIT:utf-8>' ) , <EOL> ( '<STR_LIT>' % transaction . descr . replace ( <EOL> '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) ) . encode ( '<STR_LIT:utf-8>' ) <EOL> ] </s>
