mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-15 12:20:21 +01:00
refactor: create TransientSettings
for settings that are not to be persisted
This commit is contained in:
parent
2dff48dcd0
commit
0b3324cd8f
2 changed files with 16 additions and 7 deletions
|
@ -22,6 +22,7 @@ from lnbits.settings import (
|
|||
readonly_variables,
|
||||
send_admin_user_to_saas,
|
||||
settings,
|
||||
transient_variables,
|
||||
)
|
||||
from lnbits.wallets.base import PaymentResponse, PaymentStatus
|
||||
|
||||
|
@ -449,7 +450,7 @@ async def check_admin_settings():
|
|||
|
||||
def update_cached_settings(sets_dict: dict):
|
||||
for key, value in sets_dict.items():
|
||||
if not key in readonly_variables:
|
||||
if not key in readonly_variables + transient_variables:
|
||||
try:
|
||||
setattr(settings, key, value)
|
||||
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(
|
||||
EnvSettings,
|
||||
SaaSSettings,
|
||||
PersistenceSettings,
|
||||
SuperUserSettings,
|
||||
InstalledExtensionsSettings,
|
||||
EnvSettings, SaaSSettings, PersistenceSettings, SuperUserSettings
|
||||
):
|
||||
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("_")]
|
||||
|
||||
|
||||
class Settings(EditableSettings, ReadOnlySettings):
|
||||
class Settings(EditableSettings, ReadOnlySettings, TransientSettings):
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "Settings":
|
||||
data = dict(row)
|
||||
|
@ -324,6 +331,7 @@ def send_admin_user_to_saas():
|
|||
############### INIT #################
|
||||
|
||||
readonly_variables = ReadOnlySettings.readonly_fields()
|
||||
transient_variables = TransientSettings.readonly_fields()
|
||||
|
||||
settings = Settings()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue