be fe fixes

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-26 10:43:51 +00:00
parent 4fe68cc271
commit 1cbc347cdc
15 changed files with 5557 additions and 149 deletions

View File

@@ -348,19 +348,19 @@ class IntegrationViewSet(SiteSectorModelViewSet):
# Build response with synced counts
post_types_data = {}
for wp_type, type_config in content_types.get('post_types', {}).items():
# Map WP type to entity_type
entity_type_map = {
# Map WP type to content_type
content_type_map = {
'post': 'post',
'page': 'page',
'product': 'product',
'service': 'service',
}
entity_type = entity_type_map.get(wp_type, 'post')
content_type = content_type_map.get(wp_type, 'post')
# Count synced content
synced_count = Content.objects.filter(
site=site,
entity_type=entity_type,
content_type=content_type,
external_type=wp_type,
sync_status__in=['imported', 'synced']
).count()
@@ -379,8 +379,7 @@ class IntegrationViewSet(SiteSectorModelViewSet):
# Count synced taxonomies
synced_count = ContentTaxonomy.objects.filter(
site=site,
external_taxonomy=wp_tax,
sync_status__in=['imported', 'synced']
external_taxonomy=wp_tax
).count()
taxonomies_data[wp_tax] = {

View File

@@ -102,13 +102,14 @@ class ClusterSerializer(serializers.ModelSerializer):
return ContentIdeas.objects.filter(keyword_cluster_id=obj.id).count()
def get_content_count(self, obj):
"""Count generated content items linked to this cluster via tasks"""
"""Count generated content items linked to this cluster"""
if hasattr(obj, '_content_count'):
return obj._content_count
from igny8_core.modules.writer.models import Content
return Content.objects.filter(task__cluster_id=obj.id).count()
# Content links directly to clusters now (task field was removed in refactor)
return Content.objects.filter(cluster_id=obj.id).count()
@classmethod
def prefetch_keyword_stats(cls, clusters):
@@ -166,16 +167,16 @@ class ClusterSerializer(serializers.ModelSerializer):
)
idea_stats = {item['keyword_cluster_id']: item['count'] for item in idea_counts}
# Prefetch content counts (through writer.Tasks -> Content)
# Prefetch content counts (Content links directly to Clusters now)
from igny8_core.modules.writer.models import Content
content_counts = (
Content.objects
.filter(task__cluster_id__in=cluster_ids)
.values('task__cluster_id')
.filter(cluster_id__in=cluster_ids)
.values('cluster_id')
.annotate(count=Count('id'))
)
content_stats = {item['task__cluster_id']: item['count'] for item in content_counts}
content_stats = {item['cluster_id']: item['count'] for item in content_counts}
# Attach stats to each cluster object
for cluster in clusters:

View File

@@ -102,10 +102,6 @@ class ContentAdmin(SiteSectorAdminMixin, admin.ModelAdmin):
('Content', {
'fields': ('content_html',)
}),
('Taxonomy', {
'fields': ('taxonomy_terms',),
'description': 'Categories, tags, and other taxonomy terms'
}),
('WordPress Sync', {
'fields': ('external_id', 'external_url'),
'classes': ('collapse',)

View File

@@ -488,14 +488,12 @@ class ImagesViewSet(SiteSectorModelViewSet):
# Update by content_id if provided, otherwise by image IDs
if content_id:
try:
# Get the content object to also update images linked via task
# Get the content object to also update images linked directly to content
content = Content.objects.get(id=content_id)
# Update images linked directly to content OR via task (same logic as content_images endpoint)
# This ensures we update all images: featured + 1-6 in-article images
updated_count = queryset.filter(
Q(content=content) | Q(task=content.task)
).update(status=status_value)
# Update images linked directly to content (all images: featured + in-article)
# Note: task field was removed in refactor - images now link directly to content
updated_count = queryset.filter(content=content).update(status=status_value)
except Content.DoesNotExist:
return error_response(
error='Content not found',
@@ -670,8 +668,8 @@ class ImagesViewSet(SiteSectorModelViewSet):
'validation_errors': errors,
'publish_errors': publish_errors,
'metadata': {
'has_entity_type': bool(content.entity_type),
'entity_type': content.entity_type,
'has_entity_type': bool(content.content_type),
'entity_type': content.content_type,
'has_cluster_mapping': self._has_cluster_mapping(content),
'has_taxonomy_mapping': self._has_taxonomy_mapping(content),
}
@@ -691,9 +689,9 @@ class ImagesViewSet(SiteSectorModelViewSet):
validation_service = ContentValidationService()
# Persist metadata mappings if task exists
if content.task:
mapping_service = MetadataMappingService()
mapping_service.persist_task_metadata_to_content(content)
# Metadata is now persisted directly on content - no task linkage needed
# mapping_service = MetadataMappingService() # DEPRECATED
# mapping_service.persist_task_metadata_to_content(content) # DEPRECATED
errors = validation_service.validate_for_publish(content)
@@ -970,8 +968,8 @@ class ContentViewSet(SiteSectorModelViewSet):
'validation_errors': errors,
'publish_errors': publish_errors,
'metadata': {
'has_entity_type': bool(content.entity_type),
'entity_type': content.entity_type,
'has_entity_type': bool(content.content_type),
'entity_type': content.content_type,
'has_cluster_mapping': self._has_cluster_mapping(content),
'has_taxonomy_mapping': self._has_taxonomy_mapping(content),
}
@@ -991,9 +989,9 @@ class ContentViewSet(SiteSectorModelViewSet):
validation_service = ContentValidationService()
# Persist metadata mappings if task exists
if content.task:
mapping_service = MetadataMappingService()
mapping_service.persist_task_metadata_to_content(content)
# Metadata is now persisted directly on content - no task linkage needed
# mapping_service = MetadataMappingService() # DEPRECATED
# mapping_service.persist_task_metadata_to_content(content) # DEPRECATED
errors = validation_service.validate_for_publish(content)
@@ -1121,8 +1119,8 @@ class ContentViewSet(SiteSectorModelViewSet):
'validation_errors': errors,
'publish_errors': publish_errors,
'metadata': {
'has_entity_type': bool(content.entity_type),
'entity_type': content.entity_type,
'has_entity_type': bool(content.content_type),
'entity_type': content.content_type,
'has_cluster_mapping': self._has_cluster_mapping(content),
'has_taxonomy_mapping': self._has_taxonomy_mapping(content),
}
@@ -1142,9 +1140,9 @@ class ContentViewSet(SiteSectorModelViewSet):
validation_service = ContentValidationService()
# Persist metadata mappings if task exists
if content.task:
mapping_service = MetadataMappingService()
mapping_service.persist_task_metadata_to_content(content)
# Metadata is now persisted directly on content - no task linkage needed
# mapping_service = MetadataMappingService() # DEPRECATED
# mapping_service.persist_task_metadata_to_content(content) # DEPRECATED
errors = validation_service.validate_for_publish(content)
@@ -1272,8 +1270,8 @@ class ContentViewSet(SiteSectorModelViewSet):
'validation_errors': errors,
'publish_errors': publish_errors,
'metadata': {
'has_entity_type': bool(content.entity_type),
'entity_type': content.entity_type,
'has_entity_type': bool(content.content_type),
'entity_type': content.content_type,
'has_cluster_mapping': self._has_cluster_mapping(content),
'has_taxonomy_mapping': self._has_taxonomy_mapping(content),
}
@@ -1293,9 +1291,9 @@ class ContentViewSet(SiteSectorModelViewSet):
validation_service = ContentValidationService()
# Persist metadata mappings if task exists
if content.task:
mapping_service = MetadataMappingService()
mapping_service.persist_task_metadata_to_content(content)
# Metadata is now persisted directly on content - no task linkage needed
# mapping_service = MetadataMappingService() # DEPRECATED
# mapping_service.persist_task_metadata_to_content(content) # DEPRECATED
errors = validation_service.validate_for_publish(content)
@@ -1422,8 +1420,8 @@ class ContentViewSet(SiteSectorModelViewSet):
'validation_errors': errors,
'publish_errors': publish_errors,
'metadata': {
'has_entity_type': bool(content.entity_type),
'entity_type': content.entity_type,
'has_entity_type': bool(content.content_type),
'entity_type': content.content_type,
'has_cluster_mapping': self._has_cluster_mapping(content),
'has_taxonomy_mapping': self._has_taxonomy_mapping(content),
}
@@ -1443,9 +1441,9 @@ class ContentViewSet(SiteSectorModelViewSet):
validation_service = ContentValidationService()
# Persist metadata mappings if task exists
if content.task:
mapping_service = MetadataMappingService()
mapping_service.persist_task_metadata_to_content(content)
# Metadata is now persisted directly on content - no task linkage needed
# mapping_service = MetadataMappingService() # DEPRECATED
# mapping_service.persist_task_metadata_to_content(content) # DEPRECATED
errors = validation_service.validate_for_publish(content)
@@ -1466,7 +1464,7 @@ class ContentViewSet(SiteSectorModelViewSet):
def _has_taxonomy_mapping(self, content):
"""Helper to check if content has taxonomy mapping"""
# Check new M2M relationship
return content.taxonomies.exists()
return content.taxonomy_terms.exists()
@extend_schema_view(

File diff suppressed because it is too large Load Diff