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

Fix missing bits for migration to dynamic_preferences

parent c23f1224
No related branches found
No related tags found
1 merge request!217Migrate from constance to dynamic-preferences
......@@ -30,7 +30,7 @@ class CoreConfig(AppConfig):
def preference_updated(
self,
sender: Any,
section: Optional[str] = None,,
section: Optional[str] = None,
name: Optional[str] = None,
old_value: Optional[Any] = None,
new_value: Optional[Any] = None,
......
......@@ -3,11 +3,12 @@ from django.forms import EmailField, URLField
from django.utils.translation import gettext_lazy as _
from colorfield.widgets import ColorWidget
from dynamic_preferences.types import BooleanPreference, StringPreference
from dynamic_preferences.types import BooleanPreference, ChoicePreference, StringPreference
from dynamic_preferences.preferences import Section
from dynamic_preferences.registries import global_preferences_registry
from dynamic_preferences.users.registries import user_preferences_registry
from .util.notifications import get_notification_choices_lazy
general = Section("general")
theme = Section("theme")
......@@ -110,7 +111,8 @@ class AdressingNameFormat(ChoicePreference):
@user_preferences_registry.register
class NotificationChannels(MultipleChoicePreference):
class NotificationChannels(ChoicePreference):
# FIXME should be a MultipleChoicePreference
section = notification
name = "channels"
default = ["email"]
......
......@@ -410,9 +410,9 @@ if _settings.get("celery.enabled", False):
INSTALLED_APPS += ("djcelery_email",)
EMAIL_BACKEND = "djcelery_email.backends.CeleryEmailBackend"
PWA_APP_NAME = lazy_config("general", "title")
PWA_APP_DESCRIPTION = lazy_config("general", "description")
PWA_APP_THEME_COLOR = lazy_config("theme", "primary")
PWA_APP_NAME = lazy_preference("general", "title")
PWA_APP_DESCRIPTION = lazy_preference("general", "description")
PWA_APP_THEME_COLOR = lazy_preference("theme", "primary")
PWA_APP_BACKGROUND_COLOR = "#ffffff"
PWA_APP_DISPLAY = "standalone"
PWA_APP_ORIENTATION = "any"
......
......@@ -34,11 +34,11 @@
// 1. Colors
// ==========================================================================
$primary-color: adjust-color(get-colour(get-config(COLOUR_PRIMARY)), $alpha: 1);
$primary-color: adjust-color(get-colour(get-preference(theme, primary)), $alpha: 1);
$primary-color-light: lighten($primary-color, 15%) !default;
$primary-color-dark: darken($primary-color, 15%) !default;
$secondary-color: adjust-color(get-colour(get-config(COLOUR_SECONDARY)), $alpha: 1);
$secondary-color: adjust-color(get-colour(get-preference(theme, secondary)), $alpha: 1);
$success-color: color("green", "base") !default;
$error-color: color("red", "base") !default;
$link-color: color("light-blue", "darken-1") !default;
......
......@@ -36,7 +36,7 @@ class AppConfig(django.apps.AppConfig):
user_logged_out.connect(self.user_logged_out)
# Getting an app ready means it should look at its config once
self.config_updated()
self.preference_updated(self)
# Register system checks of this app
try:
......@@ -129,7 +129,7 @@ class AppConfig(django.apps.AppConfig):
def preference_updated(
self,
sender: Any,
section: Optional[str] = None,,
section: Optional[str] = None,
name: Optional[str] = None,
old_value: Optional[Any] = None,
new_value: Optional[Any] = None,
......
......@@ -13,8 +13,6 @@ from django.http import HttpRequest
from django.utils import timezone
from django.utils.functional import lazy
from dynamic_preferences.registries import global_preferences_registry
def copyright_years(years: Sequence[int], seperator: str = ", ", joiner: str = "") -> str:
""" Takes a sequence of integegers and produces a string with ranges
......@@ -95,6 +93,9 @@ def lazy_preference(section: str, name: str) -> Callable[[str, str], Any]:
"""
def _get_preference(section: str, name: str) -> Any:
from dynamic_preferences.registries import global_preferences_registry # noqa
global_preferences = global_preferences_registry.manager()
return global_preferences["%s__%s" % (section, name)]
# The type is guessed from the default value to improve lazy()'s behaviour
......
......@@ -15,7 +15,7 @@ try:
except ImportError:
TwilioClient = None
from .core_helpers import celery_optional, lazy_config
from .core_helpers import celery_optional, lazy_preference
def send_templated_sms(
......@@ -38,7 +38,7 @@ def _send_notification_email(notification: "Notification", template: str = "noti
}
send_templated_mail(
template_name=template,
from_email=lazy_config("MAIL_OUT"),
from_email=lazy_preference("notification__mail_out"),
recipient_list=[notification.recipient.email],
context=context,
)
......@@ -63,7 +63,7 @@ def _send_notification_sms(
# - Check for availability
# - Send notification through it
_CHANNELS_MAP = {
"email": (_("E-Mail"), lambda: lazy_config("MAIL_OUT"), _send_notification_email),
"email": (_("E-Mail"), lambda: lazy_preference("notification__mail_out"), _send_notification_email),
"sms": (_("SMS"), lambda: getattr(settings, "TWILIO_SID", None), _send_notification_sms),
}
......@@ -75,7 +75,7 @@ def send_notification(notification: Union[int, "Notification"], resend: bool = F
previously marked as sent.
"""
channels = lazy_config("NOTIFICATION_CHANNELS")
channels = lazy_preference("notification__channels")
if isinstance(notification, int):
Notification = apps.get_model("core", "Notification")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment