lot of messs

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-23 14:35:41 +00:00
parent edb64824be
commit 38bc015d96
17 changed files with 2448 additions and 303 deletions

View File

@@ -5,7 +5,13 @@ from django.contrib import admin
from unfold.admin import ModelAdmin
from igny8_core.admin.base import AccountAdminMixin, Igny8ModelAdmin
from .models import AIPrompt, IntegrationSettings, AuthorProfile, Strategy
from .global_settings_models import GlobalModuleSettings
from .global_settings_models import (
GlobalModuleSettings,
GlobalIntegrationSettings,
GlobalAIPrompt,
GlobalAuthorProfile,
GlobalStrategy,
)
from django.contrib import messages
from import_export.admin import ExportMixin, ImportExportMixin
@@ -328,6 +334,8 @@ class GlobalModuleSettingsAdmin(ModelAdmin):
'automation_enabled',
'site_builder_enabled',
'linker_enabled',
'optimizer_enabled',
'publisher_enabled',
]
fieldsets = (
@@ -339,6 +347,8 @@ class GlobalModuleSettingsAdmin(ModelAdmin):
'automation_enabled',
'site_builder_enabled',
'linker_enabled',
'optimizer_enabled',
'publisher_enabled',
),
'description': 'Platform-wide module enable/disable controls. Changes affect all accounts immediately.'
}),
@@ -350,4 +360,122 @@ class GlobalModuleSettingsAdmin(ModelAdmin):
def has_delete_permission(self, request, obj=None):
"""Prevent deletion of singleton"""
return False
return False
# =====================================================================================
# GLOBAL SETTINGS ADMIN - Platform-wide defaults
# =====================================================================================
@admin.register(GlobalIntegrationSettings)
class GlobalIntegrationSettingsAdmin(Igny8ModelAdmin):
"""Admin for global integration settings (singleton)"""
list_display = ["id", "is_active", "last_updated", "updated_by"]
readonly_fields = ["last_updated"]
fieldsets = (
("OpenAI Settings", {
"fields": ("openai_api_key", "openai_model", "openai_temperature", "openai_max_tokens"),
"description": "Global OpenAI configuration used by all accounts (unless overridden)"
}),
("Image Generation - Default Service", {
"fields": ("default_image_service",),
"description": "Choose which image generation service is used by default for all accounts"
}),
("Image Generation - DALL-E", {
"fields": ("dalle_api_key", "dalle_model", "dalle_size"),
"description": "Global DALL-E (OpenAI) image generation configuration"
}),
("Image Generation - Runware", {
"fields": ("runware_api_key", "runware_model"),
"description": "Global Runware image generation configuration"
}),
("Universal Image Settings", {
"fields": ("image_quality", "image_style", "max_in_article_images", "desktop_image_size", "mobile_image_size"),
"description": "Image quality, style, and sizing settings that apply to ALL providers (DALL-E, Runware, etc.)"
}),
("Status", {
"fields": ("is_active", "last_updated", "updated_by")
}),
)
def has_add_permission(self, request):
"""Only allow one instance (singleton pattern)"""
return not GlobalIntegrationSettings.objects.exists()
def has_delete_permission(self, request, obj=None):
"""Don't allow deletion of singleton"""
return False
@admin.register(GlobalAIPrompt)
class GlobalAIPromptAdmin(ExportMixin, Igny8ModelAdmin):
"""Admin for global AI prompt templates"""
list_display = ["prompt_type", "version", "is_active", "last_updated"]
list_filter = ["is_active", "prompt_type", "version"]
search_fields = ["prompt_type", "description"]
readonly_fields = ["last_updated", "created_at"]
fieldsets = (
("Basic Info", {
"fields": ("prompt_type", "description", "is_active", "version")
}),
("Prompt Content", {
"fields": ("prompt_value", "variables"),
"description": "Variables should be a list of variable names used in the prompt"
}),
("Timestamps", {
"fields": ("created_at", "last_updated")
}),
)
actions = ["increment_version"]
def increment_version(self, request, queryset):
"""Increment version for selected prompts"""
for prompt in queryset:
prompt.version += 1
prompt.save()
self.message_user(request, f"{queryset.count()} prompt(s) version incremented.", messages.SUCCESS)
increment_version.short_description = "Increment version"
@admin.register(GlobalAuthorProfile)
class GlobalAuthorProfileAdmin(ImportExportMixin, Igny8ModelAdmin):
"""Admin for global author profile templates"""
list_display = ["name", "category", "tone", "language", "is_active", "created_at"]
list_filter = ["is_active", "category", "tone", "language"]
search_fields = ["name", "description"]
readonly_fields = ["created_at", "updated_at"]
fieldsets = (
("Basic Info", {
"fields": ("name", "description", "category", "is_active")
}),
("Writing Style", {
"fields": ("tone", "language", "structure_template")
}),
("Timestamps", {
"fields": ("created_at", "updated_at")
}),
)
@admin.register(GlobalStrategy)
class GlobalStrategyAdmin(ImportExportMixin, Igny8ModelAdmin):
"""Admin for global strategy templates"""
list_display = ["name", "category", "is_active", "created_at"]
list_filter = ["is_active", "category"]
search_fields = ["name", "description"]
readonly_fields = ["created_at", "updated_at"]
fieldsets = (
("Basic Info", {
"fields": ("name", "description", "category", "is_active")
}),
("Strategy Configuration", {
"fields": ("prompt_types", "section_logic")
}),
("Timestamps", {
"fields": ("created_at", "updated_at")
}),
)