2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

feat: Re-Implement customize options (#8969)

* Extend api to also include customize functions

* [FR] Re-Implement customize options
Fixes #8818

* re-implement header

* add splashscreen customisation

* make simpler

* fix rendering

* bump api
This commit is contained in:
Matthias Mair
2025-01-31 03:10:31 +01:00
committed by GitHub
parent e75ceb0719
commit cfa248aad9
7 changed files with 135 additions and 35 deletions

View File

@ -20,6 +20,7 @@ from rest_framework.views import APIView
import InvenTree.version
import users.models
from InvenTree import helpers
from InvenTree.mixins import ListCreateAPI
from InvenTree.templatetags.inventree_extras import plugins_info
from part.models import Part
@ -198,6 +199,14 @@ class VersionTextView(ListAPI):
class InfoApiSerializer(serializers.Serializer):
"""InvenTree server information - some information might be blanked if called without elevated credentials."""
class CustomizeSerializer(serializers.Serializer):
"""Serializer for customize field."""
logo = serializers.CharField()
splash = serializers.CharField()
login_message = serializers.CharField()
navbar_message = serializers
server = serializers.CharField(read_only=True)
version = serializers.CharField(read_only=True)
instance = serializers.CharField(read_only=True)
@ -214,6 +223,7 @@ class InfoApiSerializer(serializers.Serializer):
default_locale = serializers.ChoiceField(
choices=settings.LOCALE_CODES, read_only=True
)
customize = CustomizeSerializer(read_only=True)
system_health = serializers.BooleanField(read_only=True)
database = serializers.CharField(read_only=True)
platform = serializers.CharField(read_only=True)
@ -263,6 +273,12 @@ class InfoView(APIView):
'debug_mode': settings.DEBUG,
'docker_mode': settings.DOCKER,
'default_locale': settings.LANGUAGE_CODE,
'customize': {
'logo': helpers.getLogoImage(),
'splash': helpers.getSplashScreen(),
'login_message': helpers.getCustomOption('login_message'),
'navbar_message': helpers.getCustomOption('navbar_message'),
},
# Following fields are only available to staff users
'system_health': check_system_health() if is_staff else None,
'database': InvenTree.version.inventreeDatabase() if is_staff else None,

View File

@ -1,13 +1,16 @@
"""InvenTree API version information."""
# InvenTree API version
INVENTREE_API_VERSION = 306
INVENTREE_API_VERSION = 307
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """
v307 - 2025-01-29 : https://github.com/inventree/InvenTree/pull/8969
- Extend Info Endpoint to include customizations
v306 - 2025-01-28 : https://github.com/inventree/InvenTree/pull/8966
- Adds "start_date" to PurchasesOrder API
- Adds "start_date" to SalesOrder API

View File

@ -193,6 +193,15 @@ def getSplashScreen(custom=True):
return static_storage.url('img/inventree_splash.jpg')
def getCustomOption(reference: str):
"""Return the value of a custom option from settings.CUSTOMIZE.
Args:
reference: Reference key for the custom option
"""
return settings.CUSTOMIZE.get(reference, None)
def TestIfImageURL(url):
"""Test if an image URL (or filename) looks like a valid image format.