old automation cleanup adn status feilds of planner udpate

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-03 05:13:53 +00:00
parent 7df6e190fc
commit c9f082cb12
40 changed files with 1832 additions and 2134 deletions

View File

@@ -0,0 +1,114 @@
# Generated migration for unified status refactor
from django.db import migrations, models
def migrate_status_data(apps, schema_editor):
"""Transform existing status data to new values"""
Keywords = apps.get_model('planner', 'Keywords')
Clusters = apps.get_model('planner', 'Clusters')
ContentIdeas = apps.get_model('planner', 'ContentIdeas')
# Keywords: pending→new, active→mapped, archived→mapped+disabled=true
Keywords.objects.filter(status='pending').update(status='new')
Keywords.objects.filter(status='active').update(status='mapped')
# Handle archived: set to mapped and mark as disabled
archived_keywords = Keywords.objects.filter(status='archived')
for kw in archived_keywords:
kw.status = 'mapped'
kw.disabled = True
kw.save()
# Clusters: active (with ideas)→mapped, active (no ideas)→new
# Check if cluster has any related ideas using the reverse relationship
for cluster in Clusters.objects.all():
if cluster.ideas.exists():
cluster.status = 'mapped'
else:
cluster.status = 'new'
cluster.save()
# ContentIdeas: scheduled→queued, published→completed, new stays new
ContentIdeas.objects.filter(status='scheduled').update(status='queued')
ContentIdeas.objects.filter(status='published').update(status='completed')
def reverse_status_data(apps, schema_editor):
"""Reverse migration: restore old status values"""
Keywords = apps.get_model('planner', 'Keywords')
Clusters = apps.get_model('planner', 'Clusters')
ContentIdeas = apps.get_model('planner', 'ContentIdeas')
# Keywords: new→pending, mapped→active (or archived if disabled)
Keywords.objects.filter(status='new').update(status='pending')
Keywords.objects.filter(status='mapped', disabled=False).update(status='active')
Keywords.objects.filter(status='mapped', disabled=True).update(status='archived', disabled=False)
# Clusters: all back to 'active'
Clusters.objects.all().update(status='active')
# ContentIdeas: queued→scheduled, completed→published
ContentIdeas.objects.filter(status='queued').update(status='scheduled')
ContentIdeas.objects.filter(status='completed').update(status='published')
class Migration(migrations.Migration):
dependencies = [
('planner', '0005_field_rename_implementation'),
]
operations = [
# Step 1: Add disabled field to all models (with default=False)
migrations.AddField(
model_name='clusters',
name='disabled',
field=models.BooleanField(default=False, help_text='Exclude from processes'),
),
migrations.AddField(
model_name='keywords',
name='disabled',
field=models.BooleanField(default=False, help_text='Exclude from processes'),
),
migrations.AddField(
model_name='contentideas',
name='disabled',
field=models.BooleanField(default=False, help_text='Exclude from processes'),
),
# Step 2: Alter Keywords status field choices
migrations.AlterField(
model_name='keywords',
name='status',
field=models.CharField(
choices=[('new', 'New'), ('mapped', 'Mapped')],
default='new',
max_length=50
),
),
# Step 3: Alter Clusters status field (add choices, change default)
migrations.AlterField(
model_name='clusters',
name='status',
field=models.CharField(
choices=[('new', 'New'), ('mapped', 'Mapped')],
default='new',
max_length=50
),
),
# Step 4: Alter ContentIdeas status field choices
migrations.AlterField(
model_name='contentideas',
name='status',
field=models.CharField(
choices=[('new', 'New'), ('queued', 'Queued'), ('completed', 'Completed')],
default='new',
max_length=50
),
),
# Step 5: Data migration - transform existing records
migrations.RunPython(migrate_status_data, reverse_status_data),
]

View File

@@ -560,7 +560,7 @@ class KeywordViewSet(SiteSectorModelViewSet):
volume=int(row.get('volume', 0) or 0),
difficulty=int(row.get('difficulty', 0) or 0),
intent=row.get('intent', 'informational') or 'informational',
status=row.get('status', 'pending') or 'pending',
status=row.get('status', 'new') or 'new',
site=site,
sector=sector,
account=account
@@ -1080,8 +1080,8 @@ class ContentIdeasViewSet(SiteSectorModelViewSet):
created_tasks.append(task.id)
# Update idea status
idea.status = 'scheduled'
# Update idea status to queued
idea.status = 'queued'
idea.save()
except Exception as e:
errors.append({