Skip to content

Commit

Permalink
Dumped whole build
Browse files Browse the repository at this point in the history
  • Loading branch information
agronick committed Jan 11, 2018
1 parent c3131e8 commit 05913f7
Show file tree
Hide file tree
Showing 72 changed files with 19,377 additions and 1,351 deletions.
24 changes: 24 additions & 0 deletions django_qbe/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django import forms
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from ordered_model.admin import OrderedModelAdmin

from .models import SavedReport


class SavedReportForm(forms.ModelForm):
model = SavedReport


class SavedReportAdmin(ImportExportModelAdmin, OrderedModelAdmin):
form = SavedReportForm
fields = [str(f).split('.')[-1] for f in SavedReport._meta.get_fields() if f.name not in ['id', 'order']]
list_display = ['title', 'description', 'report_type', 'move_up_down_links', 'created', 'modified']
readonly_fields = ['created', 'modified']
list_filter = ['report_type']

def save_form(self, request, form, change):
return super(SavedReportAdmin, self).save_form(request, form, change)


admin.site.register(SavedReport, SavedReportAdmin)
27 changes: 14 additions & 13 deletions django_qbe/exports.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
# -*- coding: utf-8 -*-
import csv
import six
from builtins import object, str
from builtins import str

import collections
import six
from collections import OrderedDict as SortedDict
from django.http import StreamingHttpResponse
from future import standard_library
from io import StringIO, BytesIO
from io import StringIO

standard_library.install_aliases()


__all__ = ("formats", )
__all__ = ("formats",)


class FormatsException(Exception):
pass


class Formats(SortedDict):

def add(self, format):
parent = self

Expand All @@ -46,7 +42,7 @@ class UnicodeWriter:

def __init__(self, dialect=csv.excel_tab, encoding="utf-8", **kwds):
# Redirect output to a queue
self.queue = BytesIO() if six.PY2 else StringIO()
self.queue = StringIO()
self.writer = csv.writer(self.queue, dialect=dialect, **kwds)

def writerow(self, row):
Expand All @@ -67,13 +63,12 @@ def writerows(self, rows):
def base_export(labels, results, dialect=csv.excel_tab):
w = UnicodeWriter(dialect=dialect)
count = 0
import ipdb; ipdb.set_trace()
w.writerow(labels)
for row in results:
count += 1
w.writerow(row)

if count % 200 == 0:
if count % 1000 == 0:
yield w.get_values()

yield w.get_values()
Expand All @@ -87,16 +82,22 @@ def make_attachment(response, ext):
@formats.add("csv")
def csv_format(labels, results):
content_type = "text/csv"
return make_attachment(StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "csv")
return make_attachment(
StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "csv"
)


@formats.add("ods")
def ods_format(labels, results):
content_type = "application/vnd.oasis.opendocument.spreadsheet"
return make_attachment(StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "ods")
return make_attachment(
StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "ods"
)


@formats.add("xls")
def xls_format(labels, results):
content_type = "application/vnd.ms-excel"
return make_attachment(StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "xls")
return make_attachment(
StreamingHttpResponse(base_export(labels, results, dialect=csv.excel), content_type=content_type), "xls"
)
Loading

0 comments on commit 05913f7

Please sign in to comment.