def download_centers_csv(request): """View to handle 'download centers as CSV' link""" response = prepare_csv_response('centers') writer = UnicodeWriter(response) # write header row writer.writerow(CSV_FIELDS) for center in RegistrationCenter.objects.all(): writer.writerow([format_field(center, field) for field in CSV_FIELDS]) return response
def download_centers_csv(request): """View to handle 'download centers as CSV' link""" response = prepare_csv_response("centers") writer = UnicodeWriter(response) # write header row writer.writerow(CSV_FIELDS) for center in RegistrationCenter.objects.all(): writer.writerow([format_field(center, field) for field in CSV_FIELDS]) return response
def download_blackwhitelisted_numbers(list_type): """Common handler for black- & whitelisted number download. Permissions must be tested by the calling view; they're not checked here. """ # Technically this is not a CSV since there's only one column, but treating it as # a CSV will make it easier to use with Excel, etc. response = prepare_csv_response('{}list'.format(list_type)) writer = UnicodeWriter(response) model = Blacklist if list_type == 'black' else Whitelist for number in model.objects.all(): writer.writerow([number.phone_number]) return response
def download_blackwhitelisted_numbers(list_type): """Common handler for black- & whitelisted number download. Permissions must be tested by the calling view; they're not checked here. """ # Technically this is not a CSV since there's only one column, but treating it as # a CSV will make it easier to use with Excel, etc. response = prepare_csv_response("{}list".format(list_type)) writer = UnicodeWriter(response) model = Blacklist if list_type == "black" else Whitelist for number in model.objects.all(): writer.writerow([number.phone_number]) return response