2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00
Files
InvenTree/InvenTree/common/settings.py
Oliver 6eddcd3c23 Setting caching (#3178)
* Revert "Remove stat context variables"

This reverts commit 0989c308d0.

* Add a caching framework for inventree settings

- Actions that use "settings" require a DB hit every time
- For example the part.full_name() method looks at the PART_NAME_FORMAT setting
- This means 1 DB hit for every part which is serialized!!

* Fixes for DebugToolbar integration

- Requires different INTERNAL_IPS when running behind docker
- Some issues with TEMPLATES framework

* Revert "Revert "Remove stat context variables""

This reverts commit 52e6359265.

* Add unit tests for settings caching

* Update existing unit tests to handle cache framework

* Fix for unit test

* Re-enable cache for default part values

* Clear cache for further unit tests
2022-06-12 10:56:16 +10:00

41 lines
1.1 KiB
Python

"""User-configurable settings for the common app."""
from django.conf import settings
from moneyed import CURRENCIES
def currency_code_default():
"""Returns the default currency code (or USD if not specified)"""
from django.db.utils import ProgrammingError
from common.models import InvenTreeSetting
try:
code = InvenTreeSetting.get_setting('INVENTREE_DEFAULT_CURRENCY', create=False, cache=False)
except ProgrammingError: # pragma: no cover
# database is not initialized yet
code = ''
if code not in CURRENCIES:
code = 'USD' # pragma: no cover
return code
def currency_code_mappings():
"""Returns the current currency choices."""
return [(a, CURRENCIES[a].name) for a in settings.CURRENCIES]
def currency_codes():
"""Returns the current currency codes."""
return [a for a in settings.CURRENCIES]
def stock_expiry_enabled():
"""Returns True if the stock expiry feature is enabled."""
from common.models import InvenTreeSetting
return InvenTreeSetting.get_setting('STOCK_ENABLE_EXPIRY')