588d95f889
Replace legacy FAQ, downloads, and release flows with project and blog publishing. Add configurable branding and theme fields plus clean-start Compose seeding support.
218 lines
6.9 KiB
Python
218 lines
6.9 KiB
Python
from django.contrib import admin
|
|
|
|
from apps.core.admin_video import video_admin_preview
|
|
from apps.core.video import VIDEO_ADMIN_FIELDSET
|
|
|
|
from .models import Article, ArticleCitation, ArticleSection, MainProduct, ProductVideo, SubProduct
|
|
|
|
|
|
class ArticleCitationInline(admin.TabularInline):
|
|
model = ArticleCitation
|
|
extra = 1
|
|
fields = ("text", "url", "order")
|
|
ordering = ("order",)
|
|
|
|
|
|
class ArticleSectionInline(admin.TabularInline):
|
|
model = ArticleSection
|
|
extra = 1
|
|
fields = ("title", "value_format", "value", "order")
|
|
ordering = ("order",)
|
|
|
|
|
|
class SubProductArticleInline(admin.StackedInline):
|
|
model = Article
|
|
fk_name = "sub_product"
|
|
extra = 0
|
|
fields = ("badge", "title", "description", "order")
|
|
ordering = ("order",)
|
|
show_change_link = True
|
|
|
|
|
|
class MainProductArticleInline(admin.StackedInline):
|
|
model = Article
|
|
fk_name = "main_product"
|
|
extra = 0
|
|
fields = ("badge", "title", "description", "order")
|
|
ordering = ("order",)
|
|
show_change_link = True
|
|
|
|
|
|
class ProductVideoInline(admin.StackedInline):
|
|
model = ProductVideo
|
|
fk_name = "main_product"
|
|
extra = 0
|
|
fields = (
|
|
"badge",
|
|
"title",
|
|
"description_format",
|
|
"description",
|
|
"video_source",
|
|
"video_url",
|
|
"video_file",
|
|
"video_poster",
|
|
"video_size",
|
|
"video_aspect_ratio",
|
|
"video_styled_background",
|
|
"order",
|
|
"is_active",
|
|
)
|
|
ordering = ("order",)
|
|
|
|
|
|
class SubProductInline(admin.StackedInline):
|
|
model = SubProduct
|
|
extra = 0
|
|
fields = ("name", "slug", "short_description", "image", "logo", "show_on_homepage", "homepage_order", "order", "is_active")
|
|
ordering = ("order",)
|
|
show_change_link = True
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
|
|
@admin.register(MainProduct)
|
|
class MainProductAdmin(admin.ModelAdmin):
|
|
list_display = ("name", "show_on_homepage", "homepage_order", "order", "is_active", "created_at")
|
|
list_filter = ("is_active", "show_on_homepage")
|
|
search_fields = ("name", "description")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
list_editable = ("order", "is_active", "show_on_homepage", "homepage_order")
|
|
inlines = [MainProductArticleInline, ProductVideoInline, SubProductInline]
|
|
fieldsets = (
|
|
(
|
|
None,
|
|
{
|
|
"fields": (
|
|
"name",
|
|
"slug",
|
|
"short_description",
|
|
)
|
|
},
|
|
),
|
|
("Description", {"fields": ("description_format", "description")}),
|
|
("Media", {"fields": ("image",)}),
|
|
("Homepage", {"fields": ("show_on_homepage", "homepage_order")}),
|
|
("Settings", {"fields": ("order", "is_active")}),
|
|
)
|
|
|
|
|
|
class SubProductVideoInline(admin.StackedInline):
|
|
model = ProductVideo
|
|
fk_name = "sub_product"
|
|
extra = 0
|
|
fields = (
|
|
"badge",
|
|
"title",
|
|
"description_format",
|
|
"description",
|
|
"video_source",
|
|
"video_url",
|
|
"video_file",
|
|
"video_poster",
|
|
"video_size",
|
|
"video_aspect_ratio",
|
|
"video_styled_background",
|
|
"order",
|
|
"is_active",
|
|
)
|
|
ordering = ("order",)
|
|
|
|
|
|
@admin.register(SubProduct)
|
|
class SubProductAdmin(admin.ModelAdmin):
|
|
list_display = (
|
|
"name",
|
|
"main_product",
|
|
"show_on_homepage",
|
|
"homepage_order",
|
|
"order",
|
|
"is_active",
|
|
"created_at",
|
|
)
|
|
list_filter = ("is_active", "main_product", "show_on_homepage")
|
|
search_fields = ("name", "description", "main_product__name")
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
list_editable = ("order", "is_active", "show_on_homepage", "homepage_order")
|
|
raw_id_fields = ("main_product",)
|
|
inlines = [SubProductArticleInline, SubProductVideoInline]
|
|
fieldsets = (
|
|
(
|
|
None,
|
|
{
|
|
"fields": (
|
|
"main_product",
|
|
"name",
|
|
"slug",
|
|
"short_description",
|
|
)
|
|
},
|
|
),
|
|
("Description", {"fields": ("description_format", "description")}),
|
|
("Media", {"fields": ("image", "logo")}),
|
|
("Homepage", {"fields": ("show_on_homepage", "homepage_order")}),
|
|
("Settings", {"fields": ("order", "is_active")}),
|
|
)
|
|
|
|
|
|
@admin.register(Article)
|
|
class ArticleAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "parent", "order", "created_at")
|
|
list_filter = ("main_product", "sub_product__main_product")
|
|
search_fields = ("title", "description", "main_product__name", "sub_product__name")
|
|
list_editable = ("order",)
|
|
raw_id_fields = ("main_product", "sub_product")
|
|
inlines = [ArticleSectionInline, ArticleCitationInline]
|
|
fieldsets = (
|
|
(None, {"fields": ("main_product", "sub_product", "badge", "title")}),
|
|
("Description", {"fields": ("description_format", "description")}),
|
|
("Citation Badge", {"fields": ("citation_count_display", "citation_count_label"), "description": "Number and optional label for the dashed citation circle badge. Both are optional — a label without a number shows an empty circle with the label; neither hides the badge entirely."}),
|
|
("Settings", {"fields": ("order",)}),
|
|
)
|
|
|
|
@admin.display(description="Parent")
|
|
def parent(self, obj):
|
|
if obj.main_product_id:
|
|
return obj.main_product
|
|
if obj.sub_product_id:
|
|
return obj.sub_product
|
|
return "—"
|
|
|
|
|
|
@admin.register(ProductVideo)
|
|
class ProductVideoAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "parent", "video_source", "video_size", "order", "is_active")
|
|
list_filter = ("video_source", "is_active", "main_product", "sub_product__main_product")
|
|
list_editable = ("order", "is_active")
|
|
search_fields = ("title", "description", "video_url", "main_product__name", "sub_product__name")
|
|
raw_id_fields = ("main_product", "sub_product")
|
|
readonly_fields = ("video_preview",)
|
|
fieldsets = (
|
|
(None, {"fields": ("main_product", "sub_product", "badge", "title", "description_format", "description")}),
|
|
VIDEO_ADMIN_FIELDSET,
|
|
("Settings", {"fields": ("order", "is_active")}),
|
|
)
|
|
|
|
@admin.display(description="Parent")
|
|
def parent(self, obj):
|
|
if obj.main_product_id:
|
|
return obj.main_product
|
|
if obj.sub_product_id:
|
|
return obj.sub_product
|
|
return "—"
|
|
|
|
@admin.display(description="Preview")
|
|
def video_preview(self, obj):
|
|
return video_admin_preview(obj)
|
|
|
|
|
|
@admin.register(ArticleSection)
|
|
class ArticleSectionAdmin(admin.ModelAdmin):
|
|
list_display = ("title", "article", "value_format", "order")
|
|
search_fields = ("title", "value", "article__title")
|
|
list_editable = ("order",)
|
|
raw_id_fields = ("article",)
|
|
fieldsets = (
|
|
(None, {"fields": ("article", "title")}),
|
|
("Content", {"fields": ("value_format", "value")}),
|
|
("Settings", {"fields": ("order",)}),
|
|
)
|