예제 #1
0
    def render_to_response(self, context):
        response = HttpResponse(mimetype='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s.csv' % str(
            unicode(context['project']['title']).encode('utf-8'))

        writer = UnicodeWriter(response)
        writer.writerow([context['project']['title']])
        writer.writerow([context['project']['description']])
        writer.writerow([])
        writer.writerows(context['table'])
        return response
예제 #2
0
    def render_to_csv_response(self, context):
        response = HttpResponse(mimetype='text/csv')
        response[
            'Content-Disposition'] = 'attachment; filename=search_results.csv'

        writer = UnicodeWriter(response)

        writer.writerow([
            'title', 'description', 'country', 'start date', 'budget',
            'principal sector'
        ])
        for activity in context['paginator'].object_list:
            title = activity['title']
            description = activity['description']
            country = iso_to_country(
                activity['recipient_country_code']) or "Unspecified"
            start_date = activity['start_actual']
            budget = currency(activity['total_budget'])
            sector = activity['sector']
            writer.writerow(
                [title, description, country, start_date, budget, sector])
        return response