|
|
|
@ -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) |
|
|
|
|