@ -4,10 +4,12 @@ from django.utils.translation import gettext_lazy as _
from unfold.admin import ModelAdmin , TabularInline
from unfold.admin import ModelAdmin , TabularInline
from unfold.contrib.forms.widgets import WysiwygWidget
from unfold.contrib.forms.widgets import WysiwygWidget
from unfold.decorators import display , action
from unfold.decorators import display , action
from unfold.widgets import UnfoldAdminTextInputWidget , UnfoldAdminTextareaWidget
from utils.multilang_json_widget import MultiLanguageJSONWidget , MultiLanguageAddressWidget , LinksJSONWidget
from utils.json_editor_field import JsonEditorWidget
from utils.json_editor_field import JsonEditorWidget
import json
import json
from utils.admin import dovoodi_admin_site , dovoodi_admin_site
from utils.admin import dovoodi_admin_site
from ..models import (
from ..models import (
Hadis , HadisReference , HadisTag , HadisStatus , ReferenceImage ,
Hadis , HadisReference , HadisTag , HadisStatus , ReferenceImage ,
HadisCollection , HadisInCollection , HadisCorrection
HadisCollection , HadisInCollection , HadisCorrection
@ -22,189 +24,18 @@ class HadisAdminForm(forms.ModelForm):
model = Hadis
model = Hadis
fields = ' __all__ '
fields = ' __all__ '
widgets = {
widgets = {
' explanation ' : WysiwygWidget ( ) ,
' title ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
' title_narrator ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
' description ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
' translation ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
' address ' : MultiLanguageAddressWidget ( ) ,
' links ' : LinksJSONWidget ( ) ,
}
}
def __init__ ( self , * args , * * kwargs ) :
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
super ( ) . __init__ ( * args , * * kwargs )
# Schema for translation JSON field
translation_schema = {
" type " : " array " ,
" title " : " Translations " ,
" items " : {
" type " : " object " ,
" title " : " Translation " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " ]
}
} ,
" text " : { # <‑‑ use text, not title
" type " : " string " ,
" title " : " Translation Text "
}
} ,
" required " : [ " language_code " , " text " ] # <‑‑ update required key
}
}
# Schema for links JSON field (array of objects with title and link)
links_schema = {
" type " : " array " ,
" title " : " Links " ,
" items " : {
" type " : " object " ,
" title " : " Link " ,
" properties " : {
" title " : {
" type " : " string " ,
" title " : " Link Title "
} ,
" link " : {
" type " : " string " ,
" title " : " URL " ,
" format " : " uri "
}
} ,
" required " : [ " title " , " link " ]
}
}
# Schema for title_narrator JSON field
title_narrator_schema = {
" type " : " array " ,
" title " : " Title Narrators " ,
" items " : {
" type " : " object " ,
" title " : " Title Narrator " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Narrator Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for title JSON field
title_schema = {
" type " : " array " ,
" title " : " Titles " ,
" items " : {
" type " : " object " ,
" title " : " Title " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for description JSON field
description_schema = {
" type " : " array " ,
" title " : " Descriptions " ,
" items " : {
" type " : " object " ,
" title " : " Description " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Description Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for hadis_status_text JSON field
hadis_status_text_schema = {
" type " : " array " ,
" title " : " Status Texts " ,
" items " : {
" type " : " object " ,
" title " : " Status Text " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Status Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for address JSON field (text is an array of strings)
address_schema = {
" type " : " array " ,
" title " : " Addresses " ,
" items " : {
" type " : " object " ,
" title " : " Address " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " array " ,
" title " : " Address Parts " ,
" items " : {
" type " : " string " ,
" title " : " Address Part "
}
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for explanation JSON field (text is an array of objects with title and detail)
# Schema for explanation JSON field (title is an array of objects with title and detail)
explanation_schema = {
explanation_schema = {
" type " : " array " ,
" type " : " array " ,
" title " : " Explanations " ,
" title " : " Explanations " ,
@ -220,7 +51,7 @@ class HadisAdminForm(forms.ModelForm):
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
}
} ,
} ,
" text " : {
" titl e " : {
" type " : " array " ,
" type " : " array " ,
" title " : " Explanation Items " ,
" title " : " Explanation Items " ,
" items " : {
" items " : {
@ -241,111 +72,15 @@ class HadisAdminForm(forms.ModelForm):
}
}
}
}
} ,
} ,
" required " : [ " language_code " , " text " ]
" required " : [ " language_code " , " titl e " ]
}
}
}
}
# Schema for explanations JSON field (array of objects with title and description)
# explanations_schema = {
# "type": "array",
# "title": "Explanations",
# "items": {
# "type": "object",
# "title": "Explanation",
# "properties": {
# "language_code": {
# "type": "string",
# "title": "Language Code",
# "enum": ["en", "fa", "ar", "ur", "ru"],
# "options": {
# "enum_titles": ["English", "Persian", "Arabic", "Urdu", "Russian"]
# }
# },
# "title": {
# "type": "string",
# "title": "Title"
# },
# "description": {
# "type": "string",
# "title": "Description"
# }
# },
# "required": ["language_code", "title", "description"]
# }
# }
# Schema for address_details JSON field (array of objects with text and priority)
# address_details_schema = {
# "type": "array",
# "title": "Address Details",
# "items": {
# "type": "object",
# "title": "Address Detail",
# "properties": {
# "text": {
# "type": "string",
# "title": "Address Text"
# },
# "priority": {
# "type": "integer",
# "title": "Priority",
# "minimum": 0
# }
# },
# "required": ["text", "priority"]
# }
# }
# Apply JSON editor widgets
self . fields [ ' translation ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( translation_schema ) ,
' title ' : ' Translations '
} )
self . fields [ ' links ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( links_schema ) ,
' title ' : ' Links '
} )
self . fields [ ' title_narrator ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_narrator_schema ) ,
' title ' : ' Title Narrators '
} )
self . fields [ ' title ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_schema ) ,
' title ' : ' Titles '
} )
self . fields [ ' description ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( description_schema ) ,
' title ' : ' Descriptions '
} )
# self.fields['hadis_status_text'].widget = JsonEditorWidget(attrs={
# 'schema': json.dumps(hadis_status_text_schema),
# 'title': 'Status Texts'
# })
self . fields [ ' address ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( address_schema ) ,
' title ' : ' Addresses '
} )
self . fields [ ' explanation ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( explanation_schema ) ,
' title ' : ' Explanations '
} )
# self.fields['explanations'].widget = JsonEditorWidget(attrs={
# 'schema': json.dumps(explanations_schema),
# self.fields['explanation'].widget = JsonEditorWidget(attrs={
# 'schema': json.dumps(explanation_schema),
# 'title': 'Explanations'
# 'title': 'Explanations'
# })
# })
# self.fields['address_details'].widget = JsonEditorWidget(attrs={
# 'schema': json.dumps(address_details_schema),
# 'title': 'Address Details'
# })
# Custom Forms for JSON Fields
# Custom Forms for JSON Fields
@ -355,71 +90,11 @@ class HadisCollectionAdminForm(forms.ModelForm):
class Meta :
class Meta :
model = HadisCollection
model = HadisCollection
fields = ' __all__ '
fields = ' __all__ '
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
# Schema for title JSON field
title_schema = {
" type " : " array " ,
" title " : " Titles " ,
" items " : {
" type " : " object " ,
" title " : " Title " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for summary JSON field
summary_schema = {
" type " : " array " ,
" title " : " Summaries " ,
" items " : {
" type " : " object " ,
" title " : " Summary " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Summary Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
widgets = {
' title ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
' summary ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
}
}
# Apply JSON editor widgets
self . fields [ ' title ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_schema ) ,
' title ' : ' Titles '
} )
self . fields [ ' summary ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( summary_schema ) ,
' title ' : ' Summaries '
} )
class HadisTagAdminForm ( forms . ModelForm ) :
class HadisTagAdminForm ( forms . ModelForm ) :
""" Custom form for HadisTag with JSON editor widgets """
""" Custom form for HadisTag with JSON editor widgets """
@ -427,41 +102,10 @@ class HadisTagAdminForm(forms.ModelForm):
class Meta :
class Meta :
model = HadisTag
model = HadisTag
fields = ' __all__ '
fields = ' __all__ '
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
# Schema for title JSON field
title_schema = {
" type " : " array " ,
" title " : " Titles " ,
" items " : {
" type " : " object " ,
" title " : " Title " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
widgets = {
' title ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
}
}
# Apply JSON editor widgets
self . fields [ ' title ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_schema ) ,
' title ' : ' Titles '
} )
class HadisStatusAdminForm ( forms . ModelForm ) :
class HadisStatusAdminForm ( forms . ModelForm ) :
""" Custom form for HadisStatus with JSON editor widgets """
""" Custom form for HadisStatus with JSON editor widgets """
@ -469,71 +113,11 @@ class HadisStatusAdminForm(forms.ModelForm):
class Meta :
class Meta :
model = HadisStatus
model = HadisStatus
fields = ' __all__ '
fields = ' __all__ '
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
# Schema for title JSON field
title_schema = {
" type " : " array " ,
" title " : " Titles " ,
" items " : {
" type " : " object " ,
" title " : " Title " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for description JSON field
description_schema = {
" type " : " array " ,
" title " : " Descriptions " ,
" items " : {
" type " : " object " ,
" title " : " Description " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Description Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
widgets = {
' title ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
' description ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
}
}
# Apply JSON editor widgets
self . fields [ ' title ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_schema ) ,
' title ' : ' Titles '
} )
self . fields [ ' description ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( description_schema ) ,
' title ' : ' Descriptions '
} )
class HadisReferenceAdminForm ( forms . ModelForm ) :
class HadisReferenceAdminForm ( forms . ModelForm ) :
""" Custom form for HadisReference with JSON editor widgets """
""" Custom form for HadisReference with JSON editor widgets """
@ -541,41 +125,10 @@ class HadisReferenceAdminForm(forms.ModelForm):
class Meta :
class Meta :
model = HadisReference
model = HadisReference
fields = ' __all__ '
fields = ' __all__ '
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
# Schema for description JSON field
description_schema = {
" type " : " array " ,
" title " : " Descriptions " ,
" items " : {
" type " : " object " ,
" title " : " Description " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Description Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
widgets = {
' description ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
}
}
# Apply JSON editor widgets
self . fields [ ' description ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( description_schema ) ,
' title ' : ' Descriptions '
} )
# Inline Admin Classes
# Inline Admin Classes
class ReferenceImageInline ( TabularInline ) :
class ReferenceImageInline ( TabularInline ) :
@ -619,11 +172,11 @@ class HadisTagAdmin(ModelAdmin):
return self . _extract_first_text ( obj . title )
return self . _extract_first_text ( obj . title )
def _extract_first_text ( self , json_data ) :
def _extract_first_text ( self , json_data ) :
""" Helper to safely extract the first ' text ' from a JSON list """
""" Helper to safely extract the first ' titl e ' from a JSON list """
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
first_item = json_data [ 0 ]
first_item = json_data [ 0 ]
if isinstance ( first_item , dict ) :
if isinstance ( first_item , dict ) :
return first_item . get ( ' text ' , ' - ' )
return first_item . get ( ' titl e ' , ' - ' )
return ' - '
return ' - '
@ -651,11 +204,11 @@ class HadisStatusAdmin(ModelAdmin):
return self . _extract_first_text ( obj . description )
return self . _extract_first_text ( obj . description )
def _extract_first_text ( self , json_data ) :
def _extract_first_text ( self , json_data ) :
""" Helper to safely extract the first ' text ' from a JSON list """
""" Helper to safely extract the first ' titl e ' from a JSON list """
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
first_item = json_data [ 0 ]
first_item = json_data [ 0 ]
if isinstance ( first_item , dict ) :
if isinstance ( first_item , dict ) :
return first_item . get ( ' text ' , ' - ' )
return first_item . get ( ' titl e ' , ' - ' )
return ' - '
return ' - '
@ -675,7 +228,7 @@ class HadisAdmin(ModelAdmin):
' fields ' : ( ' category ' , ' number ' , ' title ' , ' title_narrator ' , ' status ' , ' slug ' )
' fields ' : ( ' category ' , ' number ' , ' title ' , ' title_narrator ' , ' status ' , ' slug ' )
} ) ,
} ) ,
( _ ( ' Content ' ) , {
( _ ( ' Content ' ) , {
' fields ' : ( ' text ' , ' translation ' , ' explanation ' , ' description ' )
' fields ' : ( ' text ' , ' translation ' , ' description ' )
} ) ,
} ) ,
( _ ( ' Status & Classification ' ) , {
( _ ( ' Status & Classification ' ) , {
' fields ' : ( ' hadis_status ' , ' tags ' )
' fields ' : ( ' hadis_status ' , ' tags ' )
@ -695,11 +248,11 @@ class HadisAdmin(ModelAdmin):
return self . _extract_first_text ( obj . title )
return self . _extract_first_text ( obj . title )
def _extract_first_text ( self , json_data ) :
def _extract_first_text ( self , json_data ) :
""" Helper to safely extract the first ' text ' from a JSON list """
""" Helper to safely extract the first ' titl e ' from a JSON list """
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
first_item = json_data [ 0 ]
first_item = json_data [ 0 ]
if isinstance ( first_item , dict ) :
if isinstance ( first_item , dict ) :
return first_item . get ( ' text ' , ' - ' )
return first_item . get ( ' titl e ' , ' - ' )
return ' - '
return ' - '
@ -770,11 +323,11 @@ class HadisCollectionAdmin(ModelAdmin):
return self . _extract_first_text ( obj . title )
return self . _extract_first_text ( obj . title )
def _extract_first_text ( self , json_data ) :
def _extract_first_text ( self , json_data ) :
""" Helper to safely extract the first ' text ' from a JSON list """
""" Helper to safely extract the first ' titl e ' from a JSON list """
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
first_item = json_data [ 0 ]
first_item = json_data [ 0 ]
if isinstance ( first_item , dict ) :
if isinstance ( first_item , dict ) :
return first_item . get ( ' text ' , ' - ' )
return first_item . get ( ' titl e ' , ' - ' )
return ' - '
return ' - '
@display ( description = _ ( " Collection " ) , header = True )
@display ( description = _ ( " Collection " ) , header = True )
@ -824,101 +377,12 @@ class HadisCorrectionAdminForm(forms.ModelForm):
class Meta :
class Meta :
model = HadisCorrection
model = HadisCorrection
fields = ' __all__ '
fields = ' __all__ '
def __init__ ( self , * args , * * kwargs ) :
super ( ) . __init__ ( * args , * * kwargs )
# Schema for title JSON field
title_schema = {
" type " : " array " ,
" title " : " Titles " ,
" items " : {
" type " : " object " ,
" title " : " Title " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Title Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for description JSON field
description_schema = {
" type " : " array " ,
" title " : " Descriptions " ,
" items " : {
" type " : " object " ,
" title " : " Description " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Description Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
}
# Schema for translation JSON field
translation_schema = {
" type " : " array " ,
" title " : " Translations " ,
" items " : {
" type " : " object " ,
" title " : " Translation " ,
" properties " : {
" language_code " : {
" type " : " string " ,
" title " : " Language Code " ,
" enum " : [ " en " , " fa " , " ar " , " ur " , " ru " ] ,
" options " : {
" enum_titles " : [ " English " , " Persian " , " Arabic " , " Urdu " , " Russian " ]
}
} ,
" text " : {
" type " : " string " ,
" title " : " Translation Text "
}
} ,
" required " : [ " language_code " , " text " ]
}
widgets = {
' title ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextInputWidget ) ,
' description ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
' translation ' : MultiLanguageJSONWidget ( input_widget_class = UnfoldAdminTextareaWidget ) ,
}
}
# Apply JSON editor widgets
self . fields [ ' title ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( title_schema ) ,
' title ' : ' Titles '
} )
self . fields [ ' description ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( description_schema ) ,
' title ' : ' Descriptions '
} )
self . fields [ ' translation ' ] . widget = JsonEditorWidget ( attrs = {
' schema ' : json . dumps ( translation_schema ) ,
' title ' : ' Translations '
} )
class HadisCorrectionAdmin ( ModelAdmin ) :
class HadisCorrectionAdmin ( ModelAdmin ) :
""" Admin for HadisCorrection model """
""" Admin for HadisCorrection model """
@ -951,11 +415,11 @@ class HadisCorrectionAdmin(ModelAdmin):
return self . _extract_first_text ( obj . title )
return self . _extract_first_text ( obj . title )
def _extract_first_text ( self , json_data ) :
def _extract_first_text ( self , json_data ) :
""" Helper to safely extract the first ' text ' from a JSON list """
""" Helper to safely extract the first ' titl e ' from a JSON list """
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
if json_data and isinstance ( json_data , list ) and len ( json_data ) > 0 :
first_item = json_data [ 0 ]
first_item = json_data [ 0 ]
if isinstance ( first_item , dict ) :
if isinstance ( first_item , dict ) :
return first_item . get ( ' text ' , ' - ' )
return first_item . get ( ' titl e ' , ' - ' )
return ' - '
return ' - '