You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
551 lines
17 KiB
551 lines
17 KiB
<<<<<<< HEAD
|
|
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from dj_category.admin import BaseCategoryAdmin
|
|
from ajaxdatatable.admin import AjaxDatatable
|
|
from django.http import JsonResponse
|
|
from django.urls import path
|
|
from django.db.models import Q
|
|
from django.utils.safestring import mark_safe
|
|
from django.forms.widgets import RadioSelect
|
|
|
|
from apps.hadis.models import *
|
|
from django import forms
|
|
from utils.json_editor_field import JsonEditorWidget
|
|
|
|
# Define color choices
|
|
COLOR_CHOICES = [
|
|
('red', _('Red')),
|
|
('blue', _('Blue')),
|
|
('green', _('Green')),
|
|
('yellow', _('Yellow')),
|
|
('orange', _('Orange')),
|
|
('purple', _('Purple')),
|
|
('pink', _('Pink')),
|
|
('brown', _('Brown')),
|
|
('gray', _('Gray')),
|
|
('black', _('Black')),
|
|
]
|
|
|
|
class ColorRadioSelect(RadioSelect):
|
|
template_name = 'admin/widgets/color_radio.html'
|
|
option_template_name = 'admin/widgets/color_radio_option.html'
|
|
|
|
|
|
def get_links_schema():
|
|
return {
|
|
'type': "array",
|
|
'format': 'table',
|
|
'title': ' ',
|
|
'items': {
|
|
'type': 'object',
|
|
'title': str(_('Link')),
|
|
'properties': {
|
|
'text': {'type': 'string', "format": "textarea",'title': str(_('text'))},
|
|
'link': {'type': 'string', "format": "textarea", 'title': str(_('link'))},
|
|
}
|
|
}
|
|
}
|
|
|
|
class HadisOverviewForm(forms.ModelForm):
|
|
status_color = forms.ChoiceField(
|
|
choices=COLOR_CHOICES,
|
|
widget=ColorRadioSelect(),
|
|
required=False
|
|
)
|
|
|
|
class Meta:
|
|
model = HadisOverview
|
|
fields = '__all__'
|
|
widgets = {
|
|
'links': JsonEditorWidget(attrs={'schema': get_links_schema}),
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(HadisTag)
|
|
class HadisTagAdmin(AjaxDatatable):
|
|
list_display = ['title', 'status']
|
|
search_fields = ['title']
|
|
|
|
|
|
class ReferenceImageInline(admin.TabularInline):
|
|
model = ReferenceImage
|
|
extra = 1
|
|
verbose_name_plural = _('Reference Images')
|
|
fields = ('thumbnail', 'priority')
|
|
|
|
|
|
@admin.register(HadisReference)
|
|
class HadisReferenceAdmin(AjaxDatatable):
|
|
list_display = ['hadis', 'book', 'created_at']
|
|
list_filter = ['book']
|
|
search_fields = ['hadis__title', 'hadis__number', 'description']
|
|
autocomplete_fields = ['hadis', 'book']
|
|
readonly_fields = ['created_at']
|
|
inlines = [ReferenceImageInline]
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('hadis', 'book', 'description')
|
|
}),
|
|
)
|
|
|
|
|
|
|
|
|
|
@admin.register(HadisOverview)
|
|
class HadisOverviewAdmin(AjaxDatatable):
|
|
change_form_template = 'admin/hadisowerview_change_form.html'
|
|
form = HadisOverviewForm
|
|
ordering = ['hadis__number']
|
|
list_display = ['hadis', 'status', 'created_at']
|
|
search_fields = ['hadis__title', 'hadis__number', 'status_text',]
|
|
autocomplete_fields = ['hadis', 'tags']
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('hadis', 'status', 'status_color', 'status_text')
|
|
}),
|
|
(_('Reference Information'), {
|
|
'fields': ('address', 'share_link',),
|
|
}),
|
|
(_('Additional Information'), {
|
|
'fields': ('links', 'tags', 'created_at'),
|
|
'classes': ('collapse',),
|
|
=======
|
|
from django import forms
|
|
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from unfold.admin import ModelAdmin, TabularInline
|
|
from unfold.contrib.forms.widgets import WysiwygWidget
|
|
from unfold.decorators import display, action
|
|
from utils.json_editor_field import JsonEditorWidget
|
|
import json
|
|
|
|
from utils.admin import dovoodi_admin_site,dovoodi_admin_site
|
|
from ..models import (
|
|
Hadis, HadisReference, HadisTag, HadisStatus, ReferenceImage,
|
|
HadisCollection, HadisInCollection, HadisCorrection
|
|
)
|
|
|
|
|
|
# Custom Forms for JSON Fields
|
|
class HadisAdminForm(forms.ModelForm):
|
|
"""Custom form for Hadis with JSON editor widgets"""
|
|
|
|
class Meta:
|
|
model = Hadis
|
|
fields = '__all__'
|
|
widgets = {
|
|
'explanation': WysiwygWidget(),
|
|
}
|
|
|
|
def __init__(self, *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"]
|
|
}
|
|
}
|
|
|
|
# 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'
|
|
})
|
|
|
|
|
|
# Inline Admin Classes
|
|
class ReferenceImageInline(TabularInline):
|
|
"""Inline for ReferenceImage in HadisReference admin"""
|
|
model = ReferenceImage
|
|
extra = 0
|
|
fields = ('thumbnail', 'priority')
|
|
ordering = ('priority',)
|
|
|
|
|
|
class HadisReferenceInline(TabularInline):
|
|
"""Inline for HadisReference in Hadis admin"""
|
|
model = HadisReference
|
|
extra = 0
|
|
fields = ('book_reference',)
|
|
readonly_fields = ('created_at',)
|
|
|
|
|
|
# Main Admin Classes
|
|
class HadisTagAdmin(ModelAdmin):
|
|
"""Admin for HadisTag model"""
|
|
list_display = ('title', 'status', 'created_at')
|
|
list_filter = ('status', 'created_at')
|
|
search_fields = ('title',)
|
|
readonly_fields = ('created_at', 'updated_at')
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('title', 'status')
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
>>>>>>> develop
|
|
}),
|
|
)
|
|
|
|
|
|
<<<<<<< HEAD
|
|
class HadisOverviewInline(admin.StackedInline):
|
|
change_form_template = 'admin/hadisowerview_change_form.html'
|
|
form = HadisOverviewForm
|
|
model = HadisOverview
|
|
autocomplete_fields = ['tags', ]
|
|
can_delete = False
|
|
verbose_name_plural = _('Hadis Overview')
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('status', 'status_color', 'status_text', 'address', 'share_link', 'links', 'tags',),
|
|
}),
|
|
)
|
|
extra = 1
|
|
min_num = 1
|
|
|
|
|
|
@admin.register(Hadis)
|
|
class HadisAdmin(AjaxDatatable):
|
|
# form = HadisForm
|
|
list_display = ['number', 'title', 'category', 'status', 'created_at']
|
|
list_filter = ['status', 'category']
|
|
search_fields = ['title', 'text', 'number']
|
|
readonly_fields = ['created_at', 'updated_at']
|
|
autocomplete_fields = ['category']
|
|
inlines = [HadisOverviewInline]
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('number', 'title', 'category', 'status')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('text', 'translation'),
|
|
'classes': ('collapse',),
|
|
=======
|
|
class HadisStatusAdmin(ModelAdmin):
|
|
"""Admin for HadisStatus model"""
|
|
list_display = ('title', 'color', 'order')
|
|
list_filter = ('color',)
|
|
search_fields = ('title',)
|
|
ordering = ('order',)
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('title', 'color', 'order')
|
|
}),
|
|
)
|
|
|
|
|
|
class HadisAdmin(ModelAdmin):
|
|
"""Admin for Hadis model"""
|
|
form = HadisAdminForm
|
|
list_display = ('number', 'title', 'category', 'status', 'hadis_status', 'created_at')
|
|
list_filter = ('status', 'hadis_status', 'category', 'created_at')
|
|
search_fields = ('title', 'text', 'category__title')
|
|
readonly_fields = ('created_at', 'updated_at', 'share_link')
|
|
ordering = ('category', 'number')
|
|
inlines = [HadisReferenceInline]
|
|
filter_horizontal = ('tags',)
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('category', 'number', 'title', 'status')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('text', 'translation', 'explanation')
|
|
}),
|
|
(_('Status & Classification'), {
|
|
'fields': ('hadis_status', 'hadis_status_text', 'tags')
|
|
}),
|
|
(_('Additional Information'), {
|
|
'fields': ('address', 'links', 'share_link'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
>>>>>>> develop
|
|
}),
|
|
)
|
|
|
|
|
|
<<<<<<< HEAD
|
|
def get_form(self, request, obj=None, **kwargs):
|
|
form = super().get_form(request, obj, **kwargs)
|
|
if obj is None:
|
|
form.base_fields['category'].widget.can_add_related = False
|
|
|
|
return form
|
|
|
|
=======
|
|
class HadisReferenceAdmin(ModelAdmin):
|
|
"""Admin for HadisReference model"""
|
|
list_display = ('hadis', 'book_reference', 'created_at')
|
|
list_filter = ('created_at', 'book_reference')
|
|
search_fields = ('hadis__title', 'book_reference__title')
|
|
readonly_fields = ('created_at',)
|
|
inlines = [ReferenceImageInline]
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('hadis', 'book_reference')
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
class ReferenceImageAdmin(ModelAdmin):
|
|
"""Admin for ReferenceImage model"""
|
|
list_display = ('reference', 'thumbnail', 'priority')
|
|
list_filter = ('priority',)
|
|
search_fields = ('reference__hadis__title', 'reference__book__title')
|
|
ordering = ('reference', 'priority')
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('reference', 'thumbnail', 'priority')
|
|
}),
|
|
)
|
|
|
|
|
|
class HadisInCollectionInline(TabularInline):
|
|
"""Inline for HadisInCollection in HadisCollection admin"""
|
|
model = HadisInCollection
|
|
extra = 0
|
|
fields = ('hadis', 'order')
|
|
ordering = ('order',)
|
|
|
|
|
|
class HadisCollectionAdmin(ModelAdmin):
|
|
"""Admin for HadisCollection model"""
|
|
list_display = ('title', 'slug', 'status', 'order', 'created_at')
|
|
list_filter = ('status', 'created_at')
|
|
search_fields = ('title', 'slug', 'summary')
|
|
readonly_fields = ('slug', 'created_at', 'updated_at')
|
|
ordering = ('order',)
|
|
inlines = [HadisInCollectionInline]
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('title', 'slug', 'summary', 'status', 'order', 'thumbnail')
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
class HadisInCollectionAdmin(ModelAdmin):
|
|
"""Admin for HadisInCollection model"""
|
|
list_display = ('hadis', 'collection', 'order', 'created_at')
|
|
list_filter = ('collection', 'created_at')
|
|
search_fields = ('hadis__title', 'collection__title')
|
|
readonly_fields = ('created_at',)
|
|
ordering = ('collection', 'order')
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('hadis', 'collection', 'order')
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
class HadisCorrectionAdminForm(forms.ModelForm):
|
|
"""Custom form for HadisCorrection with JSON editor widgets"""
|
|
|
|
class Meta:
|
|
model = HadisCorrection
|
|
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"]
|
|
}
|
|
}
|
|
|
|
# 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):
|
|
"""Admin for HadisCorrection model"""
|
|
form = HadisCorrectionAdminForm
|
|
list_display = ('hadis', 'title', 'slug', 'created_at')
|
|
list_filter = ('created_at', 'hadis__category')
|
|
search_fields = ('hadis__title', 'title', 'slug')
|
|
readonly_fields = ('slug', 'created_at', 'updated_at', 'share_link')
|
|
ordering = ('-created_at',)
|
|
|
|
fieldsets = (
|
|
(None, {
|
|
'fields': ('hadis', 'title', 'slug')
|
|
}),
|
|
(_('Content'), {
|
|
'fields': ('description', 'translation')
|
|
}),
|
|
(_('Additional Information'), {
|
|
'fields': ('share_link',),
|
|
'classes': ('collapse',)
|
|
}),
|
|
(_('Timestamps'), {
|
|
'fields': ('created_at', 'updated_at'),
|
|
'classes': ('collapse',)
|
|
}),
|
|
)
|
|
|
|
|
|
# Register models with dovoodi admin site
|
|
dovoodi_admin_site.register(HadisTag, HadisTagAdmin)
|
|
dovoodi_admin_site.register(HadisStatus, HadisStatusAdmin)
|
|
dovoodi_admin_site.register(Hadis, HadisAdmin)
|
|
dovoodi_admin_site.register(HadisReference, HadisReferenceAdmin)
|
|
dovoodi_admin_site.register(ReferenceImage, ReferenceImageAdmin)
|
|
dovoodi_admin_site.register(HadisCollection, HadisCollectionAdmin)
|
|
dovoodi_admin_site.register(HadisInCollection, HadisInCollectionAdmin)
|
|
dovoodi_admin_site.register(HadisCorrection, HadisCorrectionAdmin)
|
|
>>>>>>> develop
|