181 lines
5.1 KiB
Python
181 lines
5.1 KiB
Python
from sets.admin import *
|
|
from .models import *
|
|
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
# from nested_inline.admin import NestedStackedInline, NestedTabularInline, NestedModelAdmin, NestedInline
|
|
from super_inlines.admin import SuperInlineModelAdmin, SuperModelAdmin
|
|
|
|
|
|
|
|
|
|
|
|
class Admin_Inline_WidgetForBlock(SuperInlineModelAdmin, Admin_Trans_BaseIconStackedInline):
|
|
# class Admin_Inline_WidgetForBlock(Admin_Trans_BaseIconTabularInline, SuperInlineModelAdmin):
|
|
|
|
def formfield_for_dbfield(self, db_field, request, **kwargs):
|
|
field = super(Admin_Inline_WidgetForBlock, self).formfield_for_dbfield(db_field, request, **kwargs)
|
|
return sets_for_formfield_for_dbfield(field, db_field)
|
|
# return field
|
|
|
|
model = WidgetForBlock
|
|
extra = 0
|
|
# fields = ['title', 'description', 'picture', 'bg_color', 'but_title', 'but_color', 'url']
|
|
fieldsets = [
|
|
(None, {
|
|
'classes': [],
|
|
'fields': [
|
|
(
|
|
# 'title',
|
|
'name', 'description', 'text',
|
|
'picture'
|
|
),
|
|
('bg_color', ),
|
|
('but_title', 'but_color', 'but_icon'),
|
|
('url', 'order'),
|
|
]
|
|
})
|
|
]
|
|
|
|
|
|
|
|
class Admin_StackedInline_Block(Admin_Trans_GenericBaseIconStackedInline, SuperInlineModelAdmin):
|
|
# class Admin_StackedInline_Block(Admin_Trans_GenericBaseIconStackedInline):
|
|
|
|
def formfield_for_dbfield(self, db_field, request, **kwargs):
|
|
field = super(Admin_StackedInline_Block, self).formfield_for_dbfield(db_field, request, **kwargs)
|
|
return sets_for_formfield_for_dbfield(field, db_field)
|
|
|
|
model = Block
|
|
extra = 0
|
|
fieldsets = [
|
|
(None, {
|
|
'classes': [],
|
|
'fields': [
|
|
('block_type',
|
|
# 'title',
|
|
'name', 'description', 'picture'),
|
|
('bg_color', 'bg_image'),
|
|
('but_title', 'but_color', 'but_icon'),
|
|
('url',),
|
|
('child_in_row_count', 'order'),
|
|
]
|
|
})
|
|
]
|
|
|
|
inlines = [Admin_Inline_WidgetForBlock]
|
|
|
|
|
|
|
|
|
|
|
|
# class Admin_StaticPage(NestedModelAdmin, Admin_Trans_BaseModelViewPage):
|
|
class Admin_StaticPage(SuperModelAdmin, Admin_Trans_BaseModelViewPage):
|
|
|
|
|
|
fieldsets = [
|
|
(None, {
|
|
'classes': ['wide'],
|
|
'fields': ('name',
|
|
'url',
|
|
# 'title',
|
|
'description', 'text',
|
|
'picture',
|
|
'order',
|
|
)
|
|
}),
|
|
('SEO', {
|
|
'classes': ['wide', 'collapse'],
|
|
'fields': (
|
|
'seo_title', 'seo_description', 'seo_keywords', 'seo_text',
|
|
)
|
|
}),
|
|
]
|
|
|
|
|
|
list_display = [
|
|
'image_thumb',
|
|
'id',
|
|
'name', 'url',
|
|
# 'title',
|
|
'order', 'modifiedDT', 'createDT'
|
|
]
|
|
|
|
list_display_links = ['id']
|
|
list_editable = ['order']
|
|
|
|
list_filter = ['modifiedDT', 'createDT']
|
|
search_fields = ['name', 'title']
|
|
# filter_horizontal = ['options']
|
|
|
|
inlines = [Admin_StackedInline_Block]
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
if request.user.is_superuser:
|
|
return True
|
|
|
|
if obj.url in ('main', 'spec_technics', 'works'):
|
|
return False
|
|
|
|
admin.site.register(StaticPage,Admin_StaticPage)
|
|
|
|
class Admin_Block(Admin_Trans_BaseModelViewPage):
|
|
fieldsets = [
|
|
(None, {
|
|
'classes': [],
|
|
'fields': [
|
|
('block_type',
|
|
# 'title',
|
|
'name', 'description', 'picture'),
|
|
('bg_color', 'bg_image'),
|
|
('but_title', 'but_color', 'but_icon'),
|
|
('url',),
|
|
('child_in_row_count', 'order'),
|
|
]
|
|
})
|
|
]
|
|
|
|
inlines = [Admin_Inline_WidgetForBlock]
|
|
|
|
list_display = ['name', 'block_type', 'enable', 'content_type', 'object_id']
|
|
list_editable = ['enable']
|
|
search_fields = ['name']
|
|
list_filter = ['block_type', 'enable', 'content_type']
|
|
|
|
def has_delete_permission(self, request, obj=None):
|
|
if request.user.is_superuser:
|
|
return True
|
|
|
|
if obj.name in ('About US', 'machines', 'works'):
|
|
return False
|
|
|
|
admin.site.register(Block, Admin_Block)
|
|
|
|
class Admin_Option(Admin_Trans_BaseModel):
|
|
|
|
# def get_fieldsets(self, request, obj=None):
|
|
# fieldsets = super(type(self), self).get_fieldsets(request, obj)
|
|
# fieldsets.insert(
|
|
# 1, ('Контент', {
|
|
# 'classes': ['wide'],
|
|
# 'fields': (
|
|
# 'opt_type', 'prefix', 'value', 'picture'
|
|
# )
|
|
#
|
|
# })
|
|
# )
|
|
# return fieldsets
|
|
fieldsets = [
|
|
(_('Контент'), {
|
|
'classes': ['wide'],
|
|
'fields': (
|
|
'name', 'opt_type', 'prefix', 'value', 'picture'
|
|
)
|
|
}),
|
|
]
|
|
|
|
list_display = ['image_thumb', 'opt_type', 'name', 'prefix', 'value']
|
|
list_editable = ['value', 'prefix']
|
|
list_filter = ['opt_type']
|
|
|
|
admin.site.register(Option,Admin_Option)
|