예제 #1
0
    def download_selected_orders(self, request, orders):
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' \
            % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        writer.writerow(self.CSV_COLUMNS.values())
        for order in orders:
            row_values = self.get_row_values(order)
            writer.writerow([row_values.get(column, "") for column in self.CSV_COLUMNS])
        return response
예제 #2
0
    def download_applications(self, request, table):
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        def format_csv_cell(str_in):
            if not str_in:
                return '–'
            return strip_tags(str_in).replace('\n', '').strip()

        # Loop through each row in the table, strip out any HTMl, and write it to a CSV excluding the last column (actions).
        for row_raw in table.as_values():
            row_values = tuple(format_csv_cell(value) for value in row_raw)
            writer.writerow(row_values[:-1])

        return response
예제 #3
0
    def download_selected_invoices(self, request, invoices):
        response = http.HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' \
            % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        meta_data = (
            ('number', _('Invoice number')),
            ('value', _('Invoice value')),
            ('date', _('Date of purchase')),
            ('order_number', _('Order number')),
            ('num_items', _('Number of items')),
            ('status', _('Invoice status')),
            ('customer', _('Customer email address')),
            ('person_name', _('Pay as juristic person')),
            ('person_vatin', _('Juristic person VAT number')),
            ('person_code', _('Juristic person code (e.g. KPP in Russia)')),
        )
        columns = SortedDict()
        for k, v in meta_data:
            columns[k] = v

        writer.writerow(columns.values())
        for invoice in invoices:
            row = columns.copy()
            row['number'] = invoice.number
            row['value'] = invoice.total_incl_tax
            row['date'] = format_datetime(invoice.date_created,
                                          'DATETIME_FORMAT')
            row['order_number'] = invoice.order_number
            row['num_items'] = invoice.order.num_items
            row['status'] = invoice.status
            row['customer'] = invoice.order.email
            if invoice.person:
                row['person_name'] = invoice.person.name
                row['person_vatin'] = invoice.person.vatin
                row['person_code'] = invoice.person.reason_code
            else:
                row['person_name'] = '<none>'
                row['person_vatin'] = '<none>'
                row['person_code'] = '<none>'
            writer.writerow(row.values())
        return response
예제 #4
0
    def download_selected_invoices(self, request, invoices):
        response = http.HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' \
            % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        meta_data = (('number', _('Invoice number')),
                     ('value', _('Invoice value')),
                     ('date', _('Date of purchase')),
                     ('order_number', _('Order number')),
                     ('num_items', _('Number of items')),
                     ('status', _('Invoice status')),
                     ('customer', _('Customer email address')),
                     ('person_name', _('Pay as juristic person')),
                     ('person_vatin', _('Juristic person VAT number')),
                     ('person_code', _('Juristic person code (e.g. KPP in Russia)')),
                     )
        columns = SortedDict()
        for k, v in meta_data:
            columns[k] = v

        writer.writerow(columns.values())
        for invoice in invoices:
            row = columns.copy()
            row['number'] = invoice.number
            row['value'] = invoice.total_incl_tax
            row['date'] = format_datetime(invoice.date_created, 'DATETIME_FORMAT')
            row['order_number'] = invoice.order_number
            row['num_items'] = invoice.order.num_items
            row['status'] = invoice.status
            row['customer'] = invoice.order.email
            if invoice.person:
                row['person_name'] = invoice.person.name
                row['person_vatin'] = invoice.person.vatin
                row['person_code'] = invoice.person.reason_code
            else:
                row['person_name'] = '<none>'
                row['person_vatin'] = '<none>'
                row['person_code'] = '<none>'
            writer.writerow(row.values())
        return response
예제 #5
0
    def download_selected_orders(self, request, orders):
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' \
            % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        meta_data = (('number', _('Order number')),
                     ('value', _('Order value')),
                     ('total_tax', _('Tax value')),
                     ('date', _('Date of purchase')),
                     ('num_items', _('Number of items')),
                     ('status', _('Order status')),
                     ('customer', _('Customer email address')),
                     ('shipping_address_name', _('Deliver to name')),
                     ('billing_address_name', _('Bill to name')),
                     )
        columns = OrderedDict()
        for k, v in meta_data:
            columns[k] = v

        writer.writerow(columns.values())
        for order in orders:
            row = columns.copy()
            row['number'] = order.number
            row['value'] = order.total_incl_tax
            row['total_tax'] = order.total_tax
            row['date'] = format_datetime(order.date_placed, 'DATETIME_FORMAT')
            row['num_items'] = order.num_items
            row['status'] = order.status
            row['customer'] = order.email
            if order.shipping_address:
                row['shipping_address_name'] = order.shipping_address.name
            else:
                row['shipping_address_name'] = ''
            if order.billing_address:
                row['billing_address_name'] = order.billing_address.name
            else:
                row['billing_address_name'] = ''
            writer.writerow(row.values())
        return response
예제 #6
0
    def download_selected_orders(self, request, orders):
        response = HttpResponse(content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename=%s' \
            % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        meta_data = (('number', _('Order number')),
                     ('value', _('Order value')),
                     ('date', _('Date of purchase')),
                     ('num_items', _('Number of items')),
                     ('status', _('Order status')),
                     ('customer', _('Customer email address')),
                     ('shipping_address_name', _('Deliver to name')),
                     ('billing_address_name', _('Bill to name')),
                     )
        columns = SortedDict()
        for k, v in meta_data:
            columns[k] = v

        writer.writerow(columns.values())
        for order in orders:
            row = columns.copy()
            row['number'] = order.number
            row['value'] = order.total_incl_tax
            row['date'] = format_datetime(order.date_placed, 'DATETIME_FORMAT')
            row['num_items'] = order.num_items
            row['status'] = order.status
            row['customer'] = order.email
            if order.shipping_address:
                row['shipping_address_name'] = order.shipping_address.name
            else:
                row['shipping_address_name'] = ''
            if order.billing_address:
                row['billing_address_name'] = order.billing_address.name
            else:
                row['billing_address_name'] = ''
            writer.writerow(row.values())
        return response
예제 #7
0
    def download_selected_orders(self, request, orders):
        response = HttpResponse(content_type="text/csv")
        response["Content-Disposition"] = "attachment; filename=%s" % self.get_download_filename(request)
        writer = UnicodeCSVWriter(open_file=response)

        meta_data = (
            ("number", _("Order number")),
            ("value", _("Order value")),
            ("date", _("Date of purchase")),
            ("num_items", _("Number of items")),
            ("status", _("Order status")),
            ("customer", _("Customer email address")),
            ("shipping_address_name", _("Deliver to name")),
            ("billing_address_name", _("Bill to name")),
        )
        columns = SortedDict()
        for k, v in meta_data:
            columns[k] = v

        writer.writerow(columns.values())
        for order in orders:
            row = columns.copy()
            row["number"] = order.number
            row["value"] = order.total_incl_tax
            row["date"] = format_datetime(order.date_placed, "DATETIME_FORMAT")
            row["num_items"] = order.num_items
            row["status"] = order.status
            row["customer"] = order.email
            if order.shipping_address:
                row["shipping_address_name"] = order.shipping_address.name
            else:
                row["shipping_address_name"] = ""
            if order.billing_address:
                row["billing_address_name"] = order.billing_address.name
            else:
                row["billing_address_name"] = ""
            writer.writerow(row)
        return response