2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Typed report context (#9431)

* add typed report context

* make it py3.9 compatible

* fix docs

* debug docs

* fix for py 3.9

* add requested error codes
This commit is contained in:
Lukas
2025-04-02 22:45:37 +02:00
committed by GitHub
parent b2db0b67e0
commit 75b47f8d09
16 changed files with 581 additions and 154 deletions

View File

@ -4,6 +4,7 @@ import json
import os
import subprocess
import textwrap
from typing import Literal
import requests
import yaml
@ -33,6 +34,7 @@ global GLOBAL_SETTINGS
global USER_SETTINGS
global TAGS
global FILTERS
global REPORT_CONTEXT
# Read in the InvenTree settings file
here = os.path.dirname(__file__)
@ -50,6 +52,9 @@ with open(os.path.join(here, 'inventree_tags.yml'), encoding='utf-8') as f:
# Filters
with open(os.path.join(here, 'inventree_filters.yml'), encoding='utf-8') as f:
FILTERS = yaml.load(f, yaml.BaseLoader)
# Report context
with open(os.path.join(here, 'inventree_report_context.json'), encoding='utf-8') as f:
REPORT_CONTEXT = json.load(f)
def get_repo_url(raw=False):
@ -334,3 +339,16 @@ def define_env(env):
ret_data += '\n'
return ret_data
@env.macro
def report_context(type_: Literal['models', 'base'], model: str):
"""Extract information on a particular report context."""
global REPORT_CONTEXT
context = REPORT_CONTEXT.get(type_).get(model)
ret_data = '| Variable | Type | Description |\n| --- | --- | --- |\n'
for k, v in context['context'].items():
ret_data += f'| {k} | `{v["type"]}` | {v["description"]} |\n'
return ret_data