Skip to content

Commit

Permalink
Remove custom context processors (#8540)
Browse files Browse the repository at this point in the history
* Remove custom context processors

- Only merge after 0.17.0 release
- Remove code which injects custom context variables into CUI requests
- Not needed for new API-based PUI code
- Speeds up requests - remove unnecessary DB hits

* Remove broken import

* Remove custom staticfile processing

- No longer needed as CUI is gone
  • Loading branch information
SchrodingersGat authored Dec 17, 2024
1 parent 24f433c commit acb756e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 172 deletions.
84 changes: 0 additions & 84 deletions src/backend/InvenTree/InvenTree/context.py

This file was deleted.

20 changes: 0 additions & 20 deletions src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,6 @@

STATICFILES_DIRS = []

# Translated Template settings
STATICFILES_I18_PREFIX = 'i18n'
STATICFILES_I18_SRC = BASE_DIR.joinpath('templates', 'js', 'translated')
STATICFILES_I18_TRG = BASE_DIR.joinpath('InvenTree', 'static_i18n')

# Create the target directory if it does not exist
if not STATICFILES_I18_TRG.exists():
STATICFILES_I18_TRG.mkdir(parents=True)

STATICFILES_DIRS.append(STATICFILES_I18_TRG)
STATICFILES_I18_TRG = STATICFILES_I18_TRG.joinpath(STATICFILES_I18_PREFIX)

# Append directory for compiled react files if debug server is running
if DEBUG and 'collectstatic' not in sys.argv:
web_dir = BASE_DIR.joinpath('..', 'web', 'static').absolute()
Expand All @@ -235,10 +223,6 @@
STATICFILES_DIRS.append(BASE_DIR.joinpath('plugin', 'samples', 'static'))

print('-', STATICFILES_DIRS[-1])
STATFILES_I18_PROCESSORS = ['InvenTree.context.status_codes']

# Color Themes Directory
STATIC_COLOR_THEMES_DIR = STATIC_ROOT.joinpath('css', 'color-themes').resolve()

# Database backup options
# Ref: https://django-dbbackup.readthedocs.io/en/master/configuration.html
Expand Down Expand Up @@ -553,10 +537,6 @@
'django.template.context_processors.i18n',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# Custom InvenTree context processors
'InvenTree.context.health_status',
'InvenTree.context.status_codes',
'InvenTree.context.user_roles',
],
'loaders': [
(
Expand Down
68 changes: 0 additions & 68 deletions src/backend/InvenTree/InvenTree/templatetags/inventree_extras.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""This module provides template tags for extra functionality, over and above the built-in Django tags."""

import logging
import os
from datetime import date, datetime

from django import template
from django.conf import settings as djangosettings
from django.templatetags.static import StaticNode
from django.urls import NoReverseMatch, reverse
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -444,72 +442,6 @@ def inventree_customize(reference, *args, **kwargs):
return djangosettings.CUSTOMIZE.get(reference, '')


class I18nStaticNode(StaticNode):
"""Custom StaticNode.
Replaces a variable named *lng* in the path with the current language
"""

def render(self, context): # pragma: no cover
"""Render this node with the determined locale context."""
self.original = getattr(self, 'original', None)

if not self.original:
# Store the original (un-rendered) path template, as it gets overwritten below
self.original = self.path.var

if hasattr(context, 'request'):
# Convert the "requested" language code to a standard format
language_code = context.request.LANGUAGE_CODE.lower().strip()
language_code = language_code.replace('_', '-')

# Find the first "best" match:
# - First, try the original requested code, e.g. 'pt-br'
# - Next, try a simpler version of the code e.g. 'pt'
# - Finally, fall back to english
options = [language_code, language_code.split('-')[0], 'en']

for lng in options:
lng_file = os.path.join(
djangosettings.STATIC_ROOT, self.original.format(lng=lng)
)

if os.path.exists(lng_file):
self.path.var = self.original.format(lng=lng)
break

ret = super().render(context)

return ret


# use the dynamic url - tag if in Debugging-Mode
if settings.DEBUG:

@register.simple_tag()
def i18n_static(url_name):
"""Simple tag to enable {% url %} functionality instead of {% static %}."""
return reverse(url_name)

else: # pragma: no cover

@register.tag('i18n_static')
def do_i18n_static(parser, token):
"""Overrides normal static, adds language - lookup for prerenderd files #1485.
Usage (like static):
{% i18n_static path [as varname] %}
"""
bits = token.split_contents()
loc_name = settings.STATICFILES_I18_PREFIX

# change path to called resource
bits[1] = f"'{loc_name}/{{lng}}.{bits[1][1:-1]}'"
token.contents = ' '.join(bits)

return I18nStaticNode.handle_token(parser, token)


@register.simple_tag()
def admin_index(user):
"""Return a URL for the admin interface."""
Expand Down

0 comments on commit acb756e

Please sign in to comment.