mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Cleanup dead code (#8939)
- Used for old UI plugins - No longer referenced
This commit is contained in:
parent
6d758e8e9f
commit
19d7825fa6
@ -10,7 +10,6 @@ import traceback
|
|||||||
from importlib.metadata import entry_points
|
from importlib.metadata import entry_points
|
||||||
from importlib.util import module_from_spec
|
from importlib.util import module_from_spec
|
||||||
|
|
||||||
from django import template
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import AppRegistryNotReady
|
from django.core.exceptions import AppRegistryNotReady
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
@ -244,35 +243,3 @@ def get_plugins(pkg, baseclass, path=None):
|
|||||||
|
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
# region templates
|
|
||||||
def render_template(plugin, template_file, context=None):
|
|
||||||
"""Locate and render a template file, available in the global template context."""
|
|
||||||
try:
|
|
||||||
tmp = template.loader.get_template(template_file)
|
|
||||||
except template.TemplateDoesNotExist:
|
|
||||||
logger.exception(
|
|
||||||
"Plugin %s could not locate template '%s'", plugin.slug, template_file
|
|
||||||
)
|
|
||||||
|
|
||||||
return f"""
|
|
||||||
<div class='alert alert-block alert-danger'>
|
|
||||||
Template file <em>{template_file}</em> does not exist.
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Render with the provided context
|
|
||||||
html = tmp.render(context)
|
|
||||||
|
|
||||||
return html
|
|
||||||
|
|
||||||
|
|
||||||
def render_text(text, context=None):
|
|
||||||
"""Locate a raw string with provided context."""
|
|
||||||
ctx = template.Context(context)
|
|
||||||
|
|
||||||
return template.Template(text).render(ctx)
|
|
||||||
|
|
||||||
|
|
||||||
# endregion
|
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
"""Unit tests for helpers.py."""
|
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
from .helpers import render_template
|
|
||||||
|
|
||||||
|
|
||||||
class HelperTests(TestCase):
|
|
||||||
"""Tests for helpers."""
|
|
||||||
|
|
||||||
def test_render_template(self):
|
|
||||||
"""Check if render_template helper works."""
|
|
||||||
|
|
||||||
class ErrorSource:
|
|
||||||
slug = 'sampleplg'
|
|
||||||
|
|
||||||
# working sample
|
|
||||||
response = render_template(ErrorSource(), 'sample/sample.html', {'abc': 123})
|
|
||||||
self.assertEqual(response, '<h1>123</h1>\n')
|
|
||||||
|
|
||||||
# Wrong sample
|
|
||||||
response = render_template(
|
|
||||||
ErrorSource(), 'sample/wrongsample.html', {'abc': 123}
|
|
||||||
)
|
|
||||||
self.assertIn('lert alert-block alert-danger', response)
|
|
||||||
self.assertIn('Template file <em>sample/wrongsample.html</em>', response)
|
|
Loading…
x
Reference in New Issue
Block a user