• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inventree / InvenTree / 8604849533

08 Apr 2024 06:20PM UTC coverage: 78.857%. First build
8604849533

Pull #6981

github

web-flow
Merge 3d6fa4389 into 4adce85ef
Pull Request #6981: Bump djangorestframework from 3.14.0 to 3.15.1 in /src/backend

19152 of 24287 relevant lines covered (78.86%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/backend/InvenTree/web/templatetags/spa_helper.py
1
"""Template tag to render SPA imports."""
2

3
import json
4
from logging import getLogger
5
from pathlib import Path
6
from typing import Union
7

8
from django import template
9
from django.conf import settings
10
from django.utils.safestring import mark_safe
11

12
logger = getLogger('InvenTree')
13
register = template.Library()
14

15
FRONTEND_SETTINGS = json.dumps(settings.FRONTEND_SETTINGS)
16

17

18
@register.simple_tag
19
def spa_bundle(manifest_path: Union[str, Path] = '', app: str = 'web'):
20
    """Render SPA bundle."""
21

22
    def get_url(file: str) -> str:
×
23
        """Get static url for file."""
24
        return f'{settings.STATIC_URL}{app}/{file}'
25

26
    if manifest_path == '':
27
        manifest = Path(__file__).parent.parent.joinpath(
28
            'static/web/.vite/manifest.json'
29
        )
30
    else:
31
        manifest = Path(manifest_path)
32

33
    if not manifest.exists():
34
        # Try old path for manifest file
35
        manifest = Path(__file__).parent.parent.joinpath('static/web/manifest.json')
36

37
        # Final check - fail if manifest file not found
38
        if not manifest.exists():
39
            logger.error('Manifest file not found')
40
            return
41

42
    try:
43
        manifest_data = json.load(manifest.open())
44
    except (TypeError, json.decoder.JSONDecodeError):
45
        logger.exception('Failed to parse manifest file')
46
        return
47

48
    return_string = ''
49
    # JS (based on index.html file as entrypoint)
50
    index = manifest_data.get('index.html')
51
    dynamic_files = index.get('dynamicImports', [])
52
    imports_files = ''.join([
53
        f'<script type="module" src="{get_url(manifest_data[file]["file"])}"></script>'
54
        for file in dynamic_files
55
    ])
56
    return_string += (
57
        f'<script type="module" src="{get_url(index["file"])}"></script>{imports_files}'
58
    )
59

60
    return mark_safe(return_string)
61

62

63
@register.simple_tag
64
def spa_settings():
65
    """Render settings for spa."""
66
    return mark_safe(
67
        f"""<script>window.INVENTREE_SETTINGS={FRONTEND_SETTINGS}</script>"""
68
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc