mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 04:22:01 -06:00
Merge pull request #6072 from rodvand/origin/feature
#5830: Expand ExportTemplate model with attachment choice
This commit is contained in:
commit
34457ea1b4
@ -193,7 +193,7 @@ class ExportTemplateForm(forms.ModelForm):
|
||||
class ExportTemplateAdmin(admin.ModelAdmin):
|
||||
fieldsets = (
|
||||
('Export Template', {
|
||||
'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension')
|
||||
'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension', 'as_attachment')
|
||||
}),
|
||||
('Content', {
|
||||
'fields': ('template_code',),
|
||||
@ -201,7 +201,7 @@ class ExportTemplateAdmin(admin.ModelAdmin):
|
||||
})
|
||||
)
|
||||
list_display = [
|
||||
'name', 'content_type', 'description', 'mime_type', 'file_extension',
|
||||
'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment',
|
||||
]
|
||||
list_filter = [
|
||||
'content_type',
|
||||
|
@ -116,7 +116,7 @@ class ExportTemplateSerializer(ValidatedModelSerializer):
|
||||
model = ExportTemplate
|
||||
fields = [
|
||||
'id', 'url', 'display', 'content_type', 'name', 'description', 'template_code', 'mime_type',
|
||||
'file_extension',
|
||||
'file_extension', 'as_attachment',
|
||||
]
|
||||
|
||||
|
||||
|
18
netbox/extras/migrations/0059_attachment_export_templates.py
Normal file
18
netbox/extras/migrations/0059_attachment_export_templates.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.2b1 on 2021-03-30 20:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0058_journalentry'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='exporttemplate',
|
||||
name='as_attachment',
|
||||
field=models.BooleanField(default=True),
|
||||
),
|
||||
]
|
@ -251,6 +251,10 @@ class ExportTemplate(BigIDModel):
|
||||
blank=True,
|
||||
help_text='Extension to append to the rendered filename'
|
||||
)
|
||||
as_attachment = models.BooleanField(
|
||||
default=True,
|
||||
help_text="Download file as attachment"
|
||||
)
|
||||
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
|
||||
@ -298,7 +302,9 @@ class ExportTemplate(BigIDModel):
|
||||
queryset.model._meta.verbose_name_plural,
|
||||
'.{}'.format(self.file_extension) if self.file_extension else ''
|
||||
)
|
||||
response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
|
||||
|
||||
if self.as_attachment:
|
||||
response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename)
|
||||
|
||||
return response
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user