mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 20:36:16 +02:00
refactor: create TransientSettings
for settings that are not to be persisted
This commit is contained in:
@@ -22,6 +22,7 @@ from lnbits.settings import (
|
|||||||
readonly_variables,
|
readonly_variables,
|
||||||
send_admin_user_to_saas,
|
send_admin_user_to_saas,
|
||||||
settings,
|
settings,
|
||||||
|
transient_variables,
|
||||||
)
|
)
|
||||||
from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
||||||
|
|
||||||
@@ -449,7 +450,7 @@ async def check_admin_settings():
|
|||||||
|
|
||||||
def update_cached_settings(sets_dict: dict):
|
def update_cached_settings(sets_dict: dict):
|
||||||
for key, value in sets_dict.items():
|
for key, value in sets_dict.items():
|
||||||
if not key in readonly_variables:
|
if not key in readonly_variables + transient_variables:
|
||||||
try:
|
try:
|
||||||
setattr(settings, key, value)
|
setattr(settings, key, value)
|
||||||
except:
|
except:
|
||||||
|
@@ -243,12 +243,19 @@ class SuperUserSettings(LNbitsSettings):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TransientSettings(InstalledExtensionsSettings):
|
||||||
|
# Transient Settings:
|
||||||
|
# - are initialized, updated and used at runtime
|
||||||
|
# - are not read from a file or from the `setings` table
|
||||||
|
# - are not persisted in the `settings` table when the setings are updated
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def readonly_fields(cls):
|
||||||
|
return [f for f in inspect.signature(cls).parameters if not f.startswith("_")]
|
||||||
|
|
||||||
|
|
||||||
class ReadOnlySettings(
|
class ReadOnlySettings(
|
||||||
EnvSettings,
|
EnvSettings, SaaSSettings, PersistenceSettings, SuperUserSettings
|
||||||
SaaSSettings,
|
|
||||||
PersistenceSettings,
|
|
||||||
SuperUserSettings,
|
|
||||||
InstalledExtensionsSettings,
|
|
||||||
):
|
):
|
||||||
lnbits_admin_ui: bool = Field(default=False)
|
lnbits_admin_ui: bool = Field(default=False)
|
||||||
|
|
||||||
@@ -264,7 +271,7 @@ class ReadOnlySettings(
|
|||||||
return [f for f in inspect.signature(cls).parameters if not f.startswith("_")]
|
return [f for f in inspect.signature(cls).parameters if not f.startswith("_")]
|
||||||
|
|
||||||
|
|
||||||
class Settings(EditableSettings, ReadOnlySettings):
|
class Settings(EditableSettings, ReadOnlySettings, TransientSettings):
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row) -> "Settings":
|
def from_row(cls, row: Row) -> "Settings":
|
||||||
data = dict(row)
|
data = dict(row)
|
||||||
@@ -324,6 +331,7 @@ def send_admin_user_to_saas():
|
|||||||
############### INIT #################
|
############### INIT #################
|
||||||
|
|
||||||
readonly_variables = ReadOnlySettings.readonly_fields()
|
readonly_variables = ReadOnlySettings.readonly_fields()
|
||||||
|
transient_variables = TransientSettings.readonly_fields()
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user