From ea54ff82d6b6a41efd36826ed07d5a6912dd3b20 Mon Sep 17 00:00:00 2001 From: mohsentaba Date: Tue, 27 Oct 2026 15:17:47 +0330 Subject: [PATCH] feat(settings): add multilingual footer description to dynamic preferences --- .../dynamic_preferences_registry.py | 1 + dynamic_preferences/serializers.py | 2 ++ dynamic_preferences/views.py | 33 +++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dynamic_preferences/dynamic_preferences_registry.py b/dynamic_preferences/dynamic_preferences_registry.py index 0d3dbf2..caeb27f 100644 --- a/dynamic_preferences/dynamic_preferences_registry.py +++ b/dynamic_preferences/dynamic_preferences_registry.py @@ -208,6 +208,7 @@ about_us_dobodi = { "translated_text": {"type": "string", "title": "translated text"}, "title": {"type": "string", "title": "title"}, "content": {"type": "string", "format": "textarea", "title": "Content", "rows": 8}, + "footer_description": {"type": "string", "format": "textarea", "title": "Footer Description", "rows": 4}, } } diff --git a/dynamic_preferences/serializers.py b/dynamic_preferences/serializers.py index 8081a99..623a6a3 100644 --- a/dynamic_preferences/serializers.py +++ b/dynamic_preferences/serializers.py @@ -45,7 +45,9 @@ class AboutUsDobodiSerializer(BaseSettingsSerializer): title = serializers.CharField(required=False, allow_blank=True, default="") content = serializers.CharField(required=False, allow_blank=True, default="") description = serializers.CharField(required=False, allow_blank=True, default="") + footer_description = serializers.CharField(required=False, allow_blank=True, default="") translations = serializers.JSONField(required=False, default=list) + footer_translations = serializers.JSONField(required=False, default=list) title_translations = serializers.JSONField(required=False, default=list) books_count = serializers.IntegerField(read_only=True, required=False, default=0) articles_count = serializers.IntegerField(read_only=True, required=False, default=0) diff --git a/dynamic_preferences/views.py b/dynamic_preferences/views.py index f38ea6f..5d875f9 100644 --- a/dynamic_preferences/views.py +++ b/dynamic_preferences/views.py @@ -149,7 +149,16 @@ class AboutUsDobodiAPIView(GenericAPIView): if not translations and legacy_content: translations = [{'language_code': 'en', 'text': legacy_content, 'title': legacy_content}] + footer_translations = data.get('footer_translations') + if not isinstance(footer_translations, list): + footer_translations = [] + + legacy_footer = data.get('footer_description') or '' + if not footer_translations and legacy_footer: + footer_translations = [{'language_code': 'en', 'text': legacy_footer, 'title': legacy_footer}] + localized_content = get_localized_text(translations, request=request) or legacy_content or '' + localized_footer = get_localized_text(footer_translations, request=request) or legacy_footer or '' localized_title = get_localized_text(title_translations, request=request) or data.get('title') or '' payload = { @@ -157,7 +166,9 @@ class AboutUsDobodiAPIView(GenericAPIView): 'title': localized_title, 'content': localized_content, 'description': localized_content, + 'footer_description': localized_footer, 'translations': translations, + 'footer_translations': footer_translations, 'title_translations': title_translations, 'books_count': Book.objects.filter(status=True).count(), 'articles_count': Article.objects.filter(status=True).count(), @@ -177,18 +188,34 @@ class AboutUsDobodiAPIView(GenericAPIView): def put(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) - validated = dict(serializer.validated_data) + preferences = global_preferences_registry.manager() + existing = preferences.get('about_us_dobodi__about_us_dobodi', {}) + if not isinstance(existing, dict): + existing = {} + + validated = {**existing, **dict(serializer.validated_data)} + if 'translations' not in request.data and 'translations' in existing: + validated['translations'] = existing['translations'] + if 'footer_translations' not in request.data and 'footer_translations' in existing: + validated['footer_translations'] = existing['footer_translations'] + + from apps.hadis.serializers.category import get_localized_text # Ensure content/description fallback is synced with translations if provided translations = validated.get('translations') if isinstance(translations, list) and translations: - from apps.hadis.serializers.category import get_localized_text default_text = get_localized_text(translations, fallback_lang='en') or '' if default_text: validated['content'] = default_text validated['description'] = default_text - preferences = global_preferences_registry.manager() + # Ensure footer_description fallback is synced with footer_translations if provided + footer_translations = validated.get('footer_translations') + if isinstance(footer_translations, list) and footer_translations: + default_footer = get_localized_text(footer_translations, fallback_lang='en') or '' + if default_footer: + validated['footer_description'] = default_footer + preferences['about_us_dobodi__about_us_dobodi'] = validated payload = self._build_response_payload(request, validated) return Response(self.get_serializer(payload).data)