def _csv_list(request): apps = defaultdict(dict) for app, app_data in get_tables_allowed_to_export().items(): apps[app]['tables'] = list(map(lambda d: {'name': d[1], 'url': reverse('csv_table', kwargs={'filename': d[1]})}, app_data)) for app, app_data in get_custom_exports().items(): apps[app]['custom_exports'] = list(map(lambda name: {'name': name, 'url': reverse('csv_table', kwargs={'filename': name})}, app_data)) return render_json(request, apps, template='common_json.html')
def handle_one_table(self, table_name, pk_column, batch_size): found = False for _, app_data in get_tables_allowed_to_export().items(): if table_name in list(zip(*app_data))[1]: found = True break if not found: raise CommandError('table "%s" is not supported' % table_name) print('processing %s' % table_name) dest_file = settings.DATA_DIR + '/' + table_name + '.csv' proso.db.dump_table(table_name, pk_column, batch_size, dest_file)
def _csv_list(request): apps = defaultdict(dict) for app, app_data in get_tables_allowed_to_export().items(): apps[app]['tables'] = list( map( lambda d: { 'name': d[1], 'url': reverse('csv_table', kwargs={'filename': d[1]}) }, app_data)) for app, app_data in get_custom_exports().items(): apps[app]['custom_exports'] = list( map( lambda name: { 'name': name, 'url': reverse('csv_table', kwargs={'filename': name}) }, app_data)) return render_json(request, apps, template='common_json.html')
def _csv_table(request, filename): if filename not in [x[1] for xs in get_tables_allowed_to_export().values() for x in xs] and \ filename not in [x for xs in get_custom_exports().values() for x in xs.keys()]: response = { "error": "the requested file '%s' is not valid" % filename } return render_json(request, response, status=400, template='common_json.html') download_file = settings.DATA_DIR + '/' + filename + ".csv" if not os.path.exists(download_file): response = { "error": "there is no data for the given table" } return render_json(request, response, status=204, template='common_json.html') response = HttpResponse(FileWrapper(open(download_file)), content_type='application/csv') response['Content-Length'] = os.path.getsize(download_file) response['Content-Disposition'] = 'attachment; filename=' + filename + '.csv' return response
def _csv_table(request, filename): if filename not in [x[1] for xs in get_tables_allowed_to_export().values() for x in xs] and \ filename not in [x for xs in get_custom_exports().values() for x in xs.keys()]: response = {"error": "the requested file '%s' is not valid" % filename} return render_json(request, response, status=400, template='common_json.html') download_file = settings.DATA_DIR + '/' + filename + ".csv" if not os.path.exists(download_file): response = {"error": "there is no data for the given table"} return render_json(request, response, status=204, template='common_json.html') response = HttpResponse(FileWrapper(open(download_file)), content_type='application/csv') response['Content-Length'] = os.path.getsize(download_file) response[ 'Content-Disposition'] = 'attachment; filename=' + filename + '.csv' return response
def handle_all_tables(self, batch_size): for app, app_data in get_tables_allowed_to_export().items(): for pk_column, table_name in app_data: self.handle_one_table(table_name, pk_column, batch_size)
def handle_all_tables(self, batch_size): for app, app_data in get_tables_allowed_to_export().items(): for pk_column, table_name in app_data: self.handle_one_table(table_name, pk_column, batch_size)