Skip to content
Snippets Groups Projects
Verified Commit 27d0b60e authored by Nik | Klampfradler's avatar Nik | Klampfradler Committed by Jonathan Weth
Browse files

Move remaining parts to site preferences

parent 66a5c580
No related branches found
No related tags found
1 merge request!217Migrate from constance to dynamic-preferences
......@@ -19,13 +19,9 @@ from polymorphic.models import PolymorphicModel
from .mixins import ExtensibleModel, PureDjangoModel
from .tasks import send_notification
from .util.core_helpers import now_tomorrow
from .util.core_helpers import get_site_preferences, now_tomorrow
from .util.model_helpers import ICONS
from dynamic_preferences.registries import global_preferences_registry
global_preferences = global_preferences_registry.manager()
class Person(ExtensibleModel):
""" A model describing any person related to a school, including, but not
......@@ -117,9 +113,9 @@ class Person(ExtensibleModel):
@property
def adressing_name(self) -> str:
if global_preferences["notification__addressing_name_format"] == "dutch":
if get_site_preferences()["notification__addressing_name_format"] == "dutch":
return f"{self.last_name} {self.first_name}"
elif global_preferences["notification__addressing_name_format"] == "english":
elif get_site_preferences()["notification__addressing_name_format"] == "english":
return f"{self.last_name}, {self.first_name}"
else:
return f"{self.first_name} {self.last_name}"
......@@ -180,7 +176,7 @@ class Person(ExtensibleModel):
a primary group, unless force is True.
"""
pattern = pattern or global_preferences["account__primary_group_pattern"]
pattern = pattern or get_site_preferences()["account__primary_group_pattern"]
if pattern:
if force or not self.primary_group:
......
......@@ -88,6 +88,12 @@ def merge_app_settings(setting: str, original: Union[dict, list], deduplicate: b
raise TypeError("Only dict and list settings can be merged.")
def get_site_preferences():
""" Get the preferences manager of the current site """
return get_current_site(get_request()).preferences
def lazy_preference(section: str, name: str) -> Callable[[str, str], Any]:
""" Lazily get a config value from dynamic preferences. Useful to bind preferences
to other global settings to make them available to third-party apps that are not
......@@ -95,8 +101,7 @@ def lazy_preference(section: str, name: str) -> Callable[[str, str], Any]:
"""
def _get_preference(section: str, name: str) -> Any:
site = get_current_site(get_request())
return site.preferences["%s__%s" % (section, name)]
return get_site_preferences()["%s__%s" % (section, name)]
# The type is guessed from the default value to improve lazy()'s behaviour
# FIXME Reintroduce the behaviour described above
......
from django.conf import settings
from colour import web2hex
from dynamic_preferences.registries import global_preferences_registry
from sass import SassColor
from .util.core_helpers import get_site_preferences
def get_colour(html_colour: str) -> SassColor:
rgb = web2hex(html_colour, force_long=True)[1:]
......@@ -13,5 +13,5 @@ def get_colour(html_colour: str) -> SassColor:
def get_preference(section: str, name: str) -> str:
global_preferences = global_preferences_registry.manager()
return global_preferences["%s__%s" % (section, name)]
site = get_current_site(get_request())
return get_site_preferences()["%s__%s" % (section, name)]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment