def export_companies(request, fmt): if not request.user.has_perm("core.export_companies"): return HttpResponseForbidden() data = map( lambda p: blacklist( add_encrypted_url(p, request.user, "encrypted_company_redirect"), ["id"]), ElasticCompany.get_all_companies(), ) ActionLog(user=request.user, action="download_companies_dataset", details=fmt).save() if fmt == "json": response = JsonResponse(data, safe=False) if fmt == "xml": response = render(request, "xml.jinja", {"data": data}, content_type="application/xhtml+xml") response[ "Content-Disposition"] = "attachment; filename=companies_{:%Y%m%d_%H%M}.{}".format( datetime.now(), fmt) response["Content-Length"] = len(response.content) return response
def export_persons(request, fmt): if not request.user.has_perm("core.export_persons"): return HttpResponseForbidden() if request.user.has_perm("core.export_id_and_last_modified"): fields_to_blacklist = [] else: fields_to_blacklist = ["id", "last_change"] data = map( lambda p: blacklist( add_encrypted_url(p, request.user, "encrypted_person_redirect"), fields_to_blacklist), ElasticPerson.get_all_persons(), ) ActionLog(user=request.user, action="download_dataset", details=fmt).save() if fmt == "json": response = JsonResponse(data, safe=False) if fmt == "xml": response = render(request, "xml.jinja", {"data": data}, content_type="application/xhtml+xml") response[ "Content-Disposition"] = "attachment; filename=peps_{:%Y%m%d_%H%M}.{}".format( datetime.now(), fmt) response["Content-Length"] = len(response.content) return response