summaryrefslogtreecommitdiffstats
path: root/core/models
diff options
context:
space:
mode:
authorMichael Manfre2022-11-22 23:06:21 -0500
committerGitHub2022-11-22 21:06:21 -0700
commit9014d53399b501cee48d1b80bc5e0d59c229134a (patch)
tree04cea6edc05bcbd9567b1727e6859b46c56afe61 /core/models
parent975c205d1d8152f68745597487862ead00c6dac9 (diff)
downloadtakahe-9014d53399b501cee48d1b80bc5e0d59c229134a.tar.gz
takahe-9014d53399b501cee48d1b80bc5e0d59c229134a.tar.bz2
takahe-9014d53399b501cee48d1b80bc5e0d59c229134a.zip
StatorRunner will refresh Config.system on each schedule_interval
Diffstat (limited to 'core/models')
-rw-r--r--core/models/config.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/core/models/config.py b/core/models/config.py
index dca8a0c..0a8d624 100644
--- a/core/models/config.py
+++ b/core/models/config.py
@@ -2,6 +2,7 @@ from functools import partial
from typing import ClassVar
import pydantic
+from asgiref.sync import sync_to_async
from django.core.files import File
from django.db import models
from django.templatetags.static import static
@@ -89,19 +90,39 @@ class Config(models.Model):
)
@classmethod
+ async def aload_system(cls):
+ """
+ Async loads the system config options object
+ """
+ return await sync_to_async(cls.load_values)(
+ cls.SystemOptions,
+ {"identity__isnull": True, "user__isnull": True},
+ )
+
+ @classmethod
def load_user(cls, user):
"""
Loads a user config options object
"""
return cls.load_values(
- cls.SystemOptions,
+ cls.UserOptions,
+ {"identity__isnull": True, "user": user},
+ )
+
+ @classmethod
+ async def aload_user(cls, user):
+ """
+ Async loads the user config options object
+ """
+ return await sync_to_async(cls.load_values)(
+ cls.UserOptions,
{"identity__isnull": True, "user": user},
)
@classmethod
def load_identity(cls, identity):
"""
- Loads a user config options object
+ Loads an identity config options object
"""
return cls.load_values(
cls.IdentityOptions,
@@ -109,6 +130,16 @@ class Config(models.Model):
)
@classmethod
+ async def aload_identity(cls, identity):
+ """
+ Async loads an identity config options object
+ """
+ return await sync_to_async(cls.load_values)(
+ cls.IdentityOptions,
+ {"identity": identity, "user__isnull": True},
+ )
+
+ @classmethod
def set_value(cls, key, value, options_class, filters):
config_field = options_class.__fields__[key]
if isinstance(value, File):