admin.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:ckanext-requestdata 作者: ViderumGlobal 项目源码 文件源码
def download_requests_data(self):
        '''
            Handles creating csv or json file from all of the Requested Data

            :returns: json or csv file
        '''

        file_format = request.query_string
        requests = \
            _get_action('requestdata_request_list_for_sysadmin', {})
        s = StringIO()

        if 'json' in file_format.lower():
            response.headerlist = \
                [('Content-Type', 'application/json'),
                 ('Content-Disposition',
                  'attachment;filename="data_requests.json"')]
            json.dump(requests, s, indent=4)

            return s.getvalue()

        if 'csv' in file_format.lower():
            response.headerlist = \
                [('Content-Type', 'text/csv'),
                 ('Content-Disposition',
                  'attachment;filename="data_requests.csv"')]
            writer = csv.writer(s, encoding='utf-8')
            header = True
            for k in requests:
                if header:
                    writer.writerow(k.keys())
                    header = False
                writer.writerow(k.values())

            return s.getvalue()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号