Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def data_to_dict(self, processed_data, request):
"""
Converts processed form data into a dictionary suitable
for rendering in a context.
"""
dictionary = {}
for key, value in processed_data.items():
new_key = key.replace('-', '_')
if isinstance(value, list):
dictionary[new_key] = ', '.join(value)
else:
dictionary[new_key] = utils.attempt_protected_media_value_conversion(request, value)
return dictionary
def get_csv_response(self, context):
filename = self.get_csv_filename()
response = HttpResponse(content_type='text/csv; charset=utf-8')
response['Content-Disposition'] = 'attachment;filename={}'.format(filename)
writer = csv.writer(response)
writer.writerow(context['data_headings'])
for data_row in context['data_rows']:
modified_data_row = []
for cell in data_row:
modified_cell = attempt_protected_media_value_conversion(self.request, cell)
modified_data_row.append(modified_cell)
writer.writerow(modified_data_row)
return response