mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #4360: Drop support for the Django template language in export templates
This commit is contained in:
@ -4,4 +4,9 @@
|
|||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
|
||||||
|
* [#4360](https://github.com/netbox-community/netbox/issues/4360) - Remove support for the Django template language from export templates
|
||||||
* [#4941](https://github.com/netbox-community/netbox/issues/4941) - `commit` argument is now required argument in a custom script's `run()` method
|
* [#4941](https://github.com/netbox-community/netbox/issues/4941) - `commit` argument is now required argument in a custom script's `run()` method
|
||||||
|
|
||||||
|
### REST API Changes
|
||||||
|
|
||||||
|
* extras.ExportTemplate: The `template_language` field has been removed
|
||||||
|
@ -198,11 +198,6 @@ class ExportTemplateForm(forms.ModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ExportTemplate
|
model = ExportTemplate
|
||||||
exclude = []
|
exclude = []
|
||||||
help_texts = {
|
|
||||||
'template_language': "<strong>Warning:</strong> Support for Django templating will be dropped in NetBox "
|
|
||||||
"v2.10. <a href=\"https://jinja.palletsprojects.com\">Jinja2</a> is strongly "
|
|
||||||
"recommended."
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -219,7 +214,7 @@ class ExportTemplateAdmin(admin.ModelAdmin):
|
|||||||
'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension')
|
'fields': ('content_type', 'name', 'description', 'mime_type', 'file_extension')
|
||||||
}),
|
}),
|
||||||
('Content', {
|
('Content', {
|
||||||
'fields': ('template_language', 'template_code'),
|
'fields': ('template_code',),
|
||||||
'classes': ('monospace',)
|
'classes': ('monospace',)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -71,17 +71,10 @@ class ExportTemplateSerializer(ValidatedModelSerializer):
|
|||||||
content_type = ContentTypeField(
|
content_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.filter(FeatureQuery('export_templates').get_query()),
|
queryset=ContentType.objects.filter(FeatureQuery('export_templates').get_query()),
|
||||||
)
|
)
|
||||||
template_language = ChoiceField(
|
|
||||||
choices=TemplateLanguageChoices,
|
|
||||||
default=TemplateLanguageChoices.LANGUAGE_JINJA2
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ExportTemplate
|
model = ExportTemplate
|
||||||
fields = [
|
fields = ['id', 'url', 'content_type', 'name', 'description', 'template_code', 'mime_type', 'file_extension']
|
||||||
'id', 'url', 'content_type', 'name', 'description', 'template_language', 'template_code', 'mime_type',
|
|
||||||
'file_extension',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -101,7 +101,7 @@ class ExportTemplateFilterSet(BaseFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ExportTemplate
|
model = ExportTemplate
|
||||||
fields = ['id', 'content_type', 'name', 'template_language']
|
fields = ['id', 'content_type', 'name']
|
||||||
|
|
||||||
|
|
||||||
class TagFilterSet(BaseFilterSet):
|
class TagFilterSet(BaseFilterSet):
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 3.1 on 2020-08-21 15:13
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('extras', '0047_tag_ordering'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='exporttemplate',
|
||||||
|
name='template_language',
|
||||||
|
),
|
||||||
|
]
|
@ -283,11 +283,6 @@ class ExportTemplate(models.Model):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
template_language = models.CharField(
|
|
||||||
max_length=50,
|
|
||||||
choices=TemplateLanguageChoices,
|
|
||||||
default=TemplateLanguageChoices.LANGUAGE_JINJA2
|
|
||||||
)
|
|
||||||
template_code = models.TextField(
|
template_code = models.TextField(
|
||||||
help_text='The list of objects being exported is passed as a context variable named <code>queryset</code>.'
|
help_text='The list of objects being exported is passed as a context variable named <code>queryset</code>.'
|
||||||
)
|
)
|
||||||
@ -321,17 +316,8 @@ class ExportTemplate(models.Model):
|
|||||||
context = {
|
context = {
|
||||||
'queryset': queryset
|
'queryset': queryset
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.template_language == TemplateLanguageChoices.LANGUAGE_DJANGO:
|
|
||||||
template = Template(self.template_code)
|
|
||||||
output = template.render(Context(context))
|
|
||||||
|
|
||||||
elif self.template_language == TemplateLanguageChoices.LANGUAGE_JINJA2:
|
|
||||||
output = render_jinja2(self.template_code, context)
|
output = render_jinja2(self.template_code, context)
|
||||||
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Replace CRLF-style line terminators
|
# Replace CRLF-style line terminators
|
||||||
output = output.replace('\r\n', '\n')
|
output = output.replace('\r\n', '\n')
|
||||||
|
|
||||||
|
@ -55,9 +55,9 @@ class ExportTemplateTestCase(TestCase):
|
|||||||
content_types = ContentType.objects.filter(model__in=['site', 'rack', 'device'])
|
content_types = ContentType.objects.filter(model__in=['site', 'rack', 'device'])
|
||||||
|
|
||||||
export_templates = (
|
export_templates = (
|
||||||
ExportTemplate(name='Export Template 1', content_type=content_types[0], template_language=TemplateLanguageChoices.LANGUAGE_DJANGO, template_code='TESTING'),
|
ExportTemplate(name='Export Template 1', content_type=content_types[0], template_code='TESTING'),
|
||||||
ExportTemplate(name='Export Template 2', content_type=content_types[1], template_language=TemplateLanguageChoices.LANGUAGE_JINJA2, template_code='TESTING'),
|
ExportTemplate(name='Export Template 2', content_type=content_types[1], template_code='TESTING'),
|
||||||
ExportTemplate(name='Export Template 3', content_type=content_types[2], template_language=TemplateLanguageChoices.LANGUAGE_JINJA2, template_code='TESTING'),
|
ExportTemplate(name='Export Template 3', content_type=content_types[2], template_code='TESTING'),
|
||||||
)
|
)
|
||||||
ExportTemplate.objects.bulk_create(export_templates)
|
ExportTemplate.objects.bulk_create(export_templates)
|
||||||
|
|
||||||
@ -73,10 +73,6 @@ class ExportTemplateTestCase(TestCase):
|
|||||||
params = {'content_type': ContentType.objects.get(model='site').pk}
|
params = {'content_type': ContentType.objects.get(model='site').pk}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||||
|
|
||||||
def test_template_language(self):
|
|
||||||
params = {'template_language': TemplateLanguageChoices.LANGUAGE_JINJA2}
|
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigContextTestCase(TestCase):
|
class ConfigContextTestCase(TestCase):
|
||||||
queryset = ConfigContext.objects.all()
|
queryset = ConfigContext.objects.all()
|
||||||
|
Reference in New Issue
Block a user