使用django-tables2-reports,您可以通过对项目进行最少的修改,获取任何django-tables2的报告(CSV,XLS)
项目描述
django-tables2-reports
使用django-tables2-reports,您可以通过对项目进行最少的修改,获取任何表格的报告(CSV,XLS)
需求
Python (支持2.7,3.3,3.4,3.5,3.6)
Django (支持1.3,1.4,1.5,1.6,1.7,1.8. 1.9,1.10,1.11)
xlwt,openpyxl或pyExcelerator(这些是可选的,用于导出XLS;如果可用,则默认为xlwt)
安装
在您的设置中
INSTALLED_APPS = ( 'django_tables2_reports', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.static', ) # This is optional EXCEL_SUPPORT = 'xlwt' # or 'openpyxl' or 'pyexcelerator'
项目更改
1.a 现在您的表格应扩展为‘TableReport’
############### Before ################### import django_tables2 as tables class MyTable(tables.Table): ... ############### Now ###################### from django_tables2_reports.tables import TableReport class MyTable(TableReport): ...
1.b 如果您想从报告中排除某些列(例如,如果它是按钮列),则应设置‘exclude_from_report’ - 列名称(以及表格中的属性‘exclude’)
class MyTable(TableReport): class Meta: exclude_from_report = ('column1', ...) ...
2.a 如果您使用传统视图,现在您应使用其他RequestConfig并稍微修改您的视图
############### Before ################### from django_tables2 import RequestConfig def my_view(request): objs = .... table = MyTable(objs) RequestConfig(request).configure(table) return render_to_response('app1/my_view.html', {'table': table}, context_instance=RequestContext(request)) ############### Now ###################### from django_tables2_reports.config import RequestConfigReport as RequestConfig from django_tables2_reports.utils import create_report_http_response def my_view(request): objs = .... table = MyTable(objs) table_to_report = RequestConfig(request).configure(table) if table_to_report: return create_report_http_response(table_to_report, request) return render_to_response('app1/my_view.html', {'table': table}, context_instance=RequestContext(request))
如果你在项目中有很多表格,你可以激活中间件,你不需要更改你的视图,只需要更改 RequestConfig 导入
# In your settings MIDDLEWARE_CLASSES = ( 'django_tables2_reports.middleware.TableReportMiddleware', ) ############### Now (with middleware) ###################### from django_tables2_reports.config import RequestConfigReport as RequestConfig def my_view(request): objs = .... table = MyTable(objs) RequestConfig(request).configure(table) return render_to_response('app1/my_view.html', {'table': table}, context_instance=RequestContext(request))
2.b. 如果你使用 基于类的视图
############### Before ################### from django_tables2.views import SingleTableView class PhaseChangeView(SingleTableView): table_class = MyTable model = MyModel ############### Now ###################### from django_tables2_reports.views import ReportTableView class PhaseChangeView(ReportTableView): table_class = MyTable model = MyModel
用法
在表格下方出现一个 CSV 图标(如果 Python 路径中有 xlwt、openpyxl 或 pyExcelerator,则还会出现 XLS 图标),如果你点击此图标,你会得到一个包含表格中每个项目的 CSV 报告(或 xls 报告)(无分页)。排序正常工作!
开发
通过克隆其 git 仓库,你可以获取 django-tables2-reports 的最新版本
git clone https://github.com/goinnn/django-tables2-reports
测试项目
在源树中,你会找到一个名为“test_project”的目录。它包含一个使用 django-tables2-reports 的已设置好的项目。你可以像往常一样运行它
cd test_project export PYTHONPATH=.. python manage.py syncdb --noinput python manage.py runserver
发布
0.1.0 (2017-06-19)
维护版本
Django 1.8、1.9、1.10、1.11 支持
支持 openpyxl > 2.0.0
支持最近 django-tables2
新维护者 Michał Pasternak
0.0.10 (2014-10-13)
- 针对 xlsx Content-Type 的修复
当报告格式不被识别时,django-tables2-reports 抛出 500 服务器错误。在这种情况下,404 更为合适。
django-tables2-reports 为 xlsx 文件设置 Content-Type 为 application/vnd.ms-excel,这会在 Firefox 中引起警告。application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 是 xlsx 正确的 Content-Type
支持 Django 1.7(很抱歉延迟)
添加新功能:exclude_from_report
还有一些细节
0.0.9 (2013-11-30)
与 Django 的未来版本(>=1.7)兼容
更新测试
重构代码
修复当工作表标题超过 31 个字符时的错误
0.0.8 (2013-11-14)
重构 csv_to_excel 模块。在下一个版本中,这个包将成为 pypi egg。
支持 openpyxl
与 travis 和 coveralls 集成
修复使用 paleblue 主题时的错误
修复 python 3 下的测试错误
修复一些细节
测试项目
0.0.7 (2013-08-29)
俄语翻译
- 感谢
0.0.6 (2013-08-22)
Python3 支持
波兰语翻译
0.0.5 (2013-07-03)
改进 README
使用 xlwt 可导出为 XLS
- 感谢
并空间上到 Austin Phillips
0.0.4 (2013-05-17)
在输出期间正确转义 csv 数据
现在带有逗号的字段不会被分割成多个列
0.0.3 (2012-07-19)
修复一个小的错误,当列中有换行符时。现在这些换行符被更改为了空格
详情
0.0.2 (2012-07-18)
添加默认视图(https://docs.django.ac.cn/en/dev/topics/class-based-views/)
可导出为 XLS
更新 README
0.0.1 (2012-07-17)
初始版本
项目详情
下载文件
下载适合你平台的文件。如果你不确定要选择哪个,了解更多关于 安装包 的信息。
源分布
构建发行版
django-tables2-reports-0.1.3.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 10ee0fa91649c4812e955450e25f6303b16e7656a732d55e092e68af0870addb |
|
MD5 | e29e150b13755ddf67a559dc9e749ff4 |
|
BLAKE2b-256 | 034b675c57ee0ad44b816bab5637cfb914da2388059f532ddc378e10ff6b6600 |
django_tables2_reports-0.1.3-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2fb934c0191d84a8ff2700092e261fa501d65fae3426381ca94c0a2344b6048c |
|
MD5 | 279ee5ef54cbf6b88928f200d2b6315d |
|
BLAKE2b-256 | ccb76a56258a32e212008a363858d64e00245f6cc056e703a378bdbc25f53242 |