Refactor keyword handling: Replace 'intent' with 'country' across backend and frontend

- Updated AutomationService to include estimated_word_count.
- Increased stage_1_batch_size from 20 to 50 in AutomationViewSet.
- Changed Keywords model to replace 'intent' property with 'country'.
- Adjusted ClusteringService to allow a maximum of 50 keywords for clustering.
- Modified admin and management commands to remove 'intent' and use 'country' instead.
- Updated serializers to reflect the change from 'intent' to 'country'.
- Adjusted views and filters to use 'country' instead of 'intent'.
- Updated frontend forms, filters, and pages to replace 'intent' with 'country'.
- Added migration to remove 'intent' field and add 'country' field to SeedKeyword model.
This commit is contained in:
IGNY8 VPS (Salman)
2025-12-17 07:37:36 +00:00
parent 9f826c92f8
commit 7ad06c6227
30 changed files with 240 additions and 205 deletions

View File

@@ -13,7 +13,7 @@ class KeywordSerializer(serializers.ModelSerializer):
keyword = serializers.CharField(read_only=True) # From seed_keyword.keyword
volume = serializers.IntegerField(read_only=True) # From seed_keyword.volume or volume_override
difficulty = serializers.IntegerField(read_only=True) # From seed_keyword.difficulty or difficulty_override
intent = serializers.CharField(read_only=True) # From seed_keyword.intent
country = serializers.CharField(read_only=True) # From seed_keyword.country
# SeedKeyword relationship
# Optional for create - can either provide seed_keyword_id OR custom keyword fields
@@ -24,11 +24,11 @@ class KeywordSerializer(serializers.ModelSerializer):
custom_keyword = serializers.CharField(write_only=True, required=False, allow_blank=False)
custom_volume = serializers.IntegerField(write_only=True, required=False, allow_null=True)
custom_difficulty = serializers.IntegerField(write_only=True, required=False, allow_null=True)
custom_intent = serializers.ChoiceField(
custom_country = serializers.ChoiceField(
write_only=True,
required=False,
choices=['informational', 'navigational', 'transactional', 'commercial'],
default='informational'
choices=['US', 'CA', 'GB', 'AE', 'AU', 'IN', 'PK'],
default='US'
)
# Overrides
@@ -50,11 +50,11 @@ class KeywordSerializer(serializers.ModelSerializer):
'keyword',
'volume',
'difficulty',
'intent',
'country',
'custom_keyword', # Write-only field for creating custom keywords
'custom_volume', # Write-only
'custom_difficulty', # Write-only
'custom_intent', # Write-only
'custom_country', # Write-only
'volume_override',
'difficulty_override',
'cluster_id',
@@ -67,7 +67,7 @@ class KeywordSerializer(serializers.ModelSerializer):
'sector_id',
'account_id',
]
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id', 'keyword', 'volume', 'difficulty', 'intent']
read_only_fields = ['id', 'created_at', 'updated_at', 'account_id', 'keyword', 'volume', 'difficulty', 'country']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -106,7 +106,7 @@ class KeywordSerializer(serializers.ModelSerializer):
custom_keyword = validated_data.pop('custom_keyword', None)
custom_volume = validated_data.pop('custom_volume', None)
custom_difficulty = validated_data.pop('custom_difficulty', None)
custom_intent = validated_data.pop('custom_intent', None) or 'informational'
custom_country = validated_data.pop('custom_country', None) or 'US'
# Get site and sector - they're passed as objects via save() in the view
site = validated_data.get('site')
@@ -132,7 +132,7 @@ class KeywordSerializer(serializers.ModelSerializer):
defaults={
'volume': custom_volume or 0,
'difficulty': custom_difficulty or 0,
'intent': custom_intent or 'informational',
'country': custom_country or 'US',
'is_active': True,
}
)
@@ -162,7 +162,7 @@ class KeywordSerializer(serializers.ModelSerializer):
validated_data.pop('custom_keyword', None)
validated_data.pop('custom_volume', None)
validated_data.pop('custom_difficulty', None)
validated_data.pop('custom_intent', None)
validated_data.pop('custom_country', None)
# seed_keyword_id is optional for updates - only update if provided
if 'seed_keyword_id' in validated_data: