Add DEFAULT_MIME_TE constant

This commit is contained in:
Renato Almeida de Oliveira Zaroubin 2025-04-06 18:41:03 +00:00
parent 040ee1d8f7
commit fea7926197
2 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,9 @@ from extras.choices import LogLevelChoices
# Custom fields # Custom fields
CUSTOMFIELD_EMPTY_VALUES = (None, '', []) CUSTOMFIELD_EMPTY_VALUES = (None, '', [])
# Template Export
DEFAULT_MIME_TYPE = 'text/plain; charset=utf-8'
# Webhooks # Webhooks
HTTP_CONTENT_TYPE_JSON = 'application/json' HTTP_CONTENT_TYPE_JSON = 'application/json'

View File

@ -14,7 +14,7 @@ from taggit.managers import TaggableManager
from core.choices import JobStatusChoices, ObjectChangeActionChoices from core.choices import JobStatusChoices, ObjectChangeActionChoices
from core.models import ObjectType from core.models import ObjectType
from extras.choices import * from extras.choices import *
from extras.constants import CUSTOMFIELD_EMPTY_VALUES from extras.constants import CUSTOMFIELD_EMPTY_VALUES, DEFAULT_MIME_TYPE
from extras.utils import is_taggable, filename_from_model, filename_from_object from extras.utils import is_taggable, filename_from_model, filename_from_object
from netbox.config import get_config from netbox.config import get_config
from netbox.registry import registry from netbox.registry import registry
@ -362,7 +362,9 @@ class RenderMixin(models.Model):
max_length=50, max_length=50,
blank=True, blank=True,
verbose_name=_('MIME type'), verbose_name=_('MIME type'),
help_text=_('Defaults to <code>text/plain; charset=utf-8</code>') help_text=_('Defaults to <code>{default_mime_type}<code>').format(
default_mime_type=DEFAULT_MIME_TYPE
),
) )
file_name = models.CharField( file_name = models.CharField(
max_length=200, max_length=200,
@ -404,7 +406,7 @@ class RenderMixin(models.Model):
def render_to_response(self, context=None, queryset=None): def render_to_response(self, context=None, queryset=None):
output = self.render(context=context, queryset=queryset) output = self.render(context=context, queryset=queryset)
mime_type = self.mime_type or 'text/plain; charset=utf-8' mime_type = self.mime_type or DEFAULT_MIME_TYPE
# Build the response # Build the response
response = HttpResponse(output, content_type=mime_type) response = HttpResponse(output, content_type=mime_type)