1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #3665: Enable rendering export templates via REST API

This commit is contained in:
jeremystretch
2021-05-11 15:51:36 -04:00
parent 96ffae3372
commit 43a823d0ac
4 changed files with 30 additions and 5 deletions

View File

@@ -300,13 +300,12 @@ class ExportTemplate(BigIDModel):
# Build the response
response = HttpResponse(output, content_type=mime_type)
filename = 'netbox_{}{}'.format(
queryset.model._meta.verbose_name_plural,
'.{}'.format(self.file_extension) if self.file_extension else ''
)
if self.as_attachment:
response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
basename = queryset.model._meta.verbose_name_plural.replace(' ', '_')
extension = f'.{self.file_extension}' if self.file_extension else ''
filename = f'netbox_{basename}{extension}'
response['Content-Disposition'] = f'attachment; filename="{filename}"'
return response