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.
161 lines
4.5 KiB
161 lines
4.5 KiB
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',),
|
|
}),
|
|
)
|
|
|
|
|
|
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',),
|
|
}),
|
|
)
|
|
|
|
|
|
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
|
|
|