Better API i hope
This commit is contained in:
@@ -26,6 +26,7 @@ Version: 0.1.0
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.utils.translation import get_language, gettext_lazy as _
|
||||
@@ -141,8 +142,8 @@ class TranslatableWidget(forms.Widget):
|
||||
if attrs is None:
|
||||
attrs = {}
|
||||
|
||||
# Debug: Print what we're getting as value
|
||||
print(f"Widget render - name: {name}, value: {repr(value)}, type: {type(value)}")
|
||||
# Debug: logging.debug what we're getting as value
|
||||
logging.debug(f"Widget render - name: {name}, value: {repr(value)}, type: {type(value)}")
|
||||
|
||||
# Try to get the full translations from the current context
|
||||
translations = {}
|
||||
@@ -162,7 +163,7 @@ class TranslatableWidget(forms.Widget):
|
||||
elif value:
|
||||
translations = {'en': str(value)}
|
||||
|
||||
print(f"Widget render - parsed translations from value: {translations}")
|
||||
logging.debug(f"Widget render - parsed translations from value: {translations}")
|
||||
|
||||
# If translations are empty or only have English, try to get from the bound instance
|
||||
if len(translations) <= 1 and hasattr(self, '_instance_data'):
|
||||
@@ -183,15 +184,15 @@ class TranslatableWidget(forms.Widget):
|
||||
try:
|
||||
db_translations = json.loads(row[0])
|
||||
if isinstance(db_translations, dict):
|
||||
print(f"Widget render - got translations for instance {instance.pk}: {db_translations}")
|
||||
logging.debug(f"Widget render - got translations for instance {instance.pk}: {db_translations}")
|
||||
translations = db_translations
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
print(f"Widget render - instance DB lookup error: {e}")
|
||||
logging.debug(f"Widget render - instance DB lookup error: {e}")
|
||||
|
||||
print(f"Widget render - final translations: {translations}")
|
||||
logging.debug(f"Widget render - final translations: {translations}")
|
||||
|
||||
|
||||
# Get English value for primary field
|
||||
|
||||
Reference in New Issue
Block a user