new keywirds and ideas export fix
This commit is contained in:
@@ -1901,4 +1901,58 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
|
||||
request=request
|
||||
)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='export', url_name='export')
|
||||
def export(self, request):
|
||||
"""
|
||||
Export content ideas to CSV
|
||||
Query params: search, status, keyword_cluster_id, content_type, content_structure, ids (comma-separated)
|
||||
If 'ids' parameter is provided, ONLY those IDs will be exported (other filters are ignored).
|
||||
"""
|
||||
# Get base queryset with site/sector/account filtering
|
||||
queryset = self.get_queryset()
|
||||
|
||||
# Handle IDs filter for bulk export of selected records
|
||||
ids_param = request.query_params.get('ids', '')
|
||||
if ids_param:
|
||||
try:
|
||||
ids_list = [int(id_str.strip()) for id_str in ids_param.split(',') if id_str.strip()]
|
||||
if ids_list:
|
||||
queryset = queryset.filter(id__in=ids_list)
|
||||
except (ValueError, TypeError):
|
||||
queryset = self.filter_queryset(queryset)
|
||||
else:
|
||||
queryset = self.filter_queryset(queryset)
|
||||
|
||||
ideas = queryset.all()
|
||||
|
||||
# Generate CSV
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename="ideas.csv"'
|
||||
|
||||
writer = csv.writer(response)
|
||||
# Header row
|
||||
writer.writerow([
|
||||
'ID', 'Title', 'Description', 'Primary Focus Keywords', 'Target Keywords',
|
||||
'Cluster', 'Content Type', 'Content Structure', 'Status',
|
||||
'Estimated Word Count', 'Created At',
|
||||
])
|
||||
|
||||
# Data rows
|
||||
for idea in ideas:
|
||||
writer.writerow([
|
||||
idea.id,
|
||||
idea.idea_title,
|
||||
idea.description or '',
|
||||
idea.primary_focus_keywords or '',
|
||||
idea.target_keywords or '',
|
||||
idea.keyword_cluster.name if idea.keyword_cluster else '',
|
||||
idea.content_type or '',
|
||||
idea.content_structure or '',
|
||||
idea.status or '',
|
||||
idea.estimated_word_count or '',
|
||||
idea.created_at.isoformat() if idea.created_at else '',
|
||||
])
|
||||
|
||||
return response
|
||||
|
||||
# REMOVED: generate_idea action - idea generation function removed
|
||||
|
||||
Reference in New Issue
Block a user