Creditsupdates in fotoer wdigets adn hoemapge and singe site settigns page #Run MIgration 0033 #MAJOR
This commit is contained in:
@@ -444,6 +444,9 @@ class AIEngine:
|
||||
tokens_input = raw_response.get('input_tokens', 0)
|
||||
tokens_output = raw_response.get('output_tokens', 0)
|
||||
|
||||
# Extract site_id from save_result (could be from content, cluster, or task)
|
||||
site_id = save_result.get('site_id') or save_result.get('site')
|
||||
|
||||
# Deduct credits based on actual token usage
|
||||
CreditService.deduct_credits_for_operation(
|
||||
account=self.account,
|
||||
@@ -454,6 +457,7 @@ class AIEngine:
|
||||
model_used=raw_response.get('model', ''),
|
||||
related_object_type=self._get_related_object_type(function_name),
|
||||
related_object_id=save_result.get('id') or save_result.get('cluster_id') or save_result.get('task_id'),
|
||||
site=site_id,
|
||||
metadata={
|
||||
'function_name': function_name,
|
||||
'clusters_created': clusters_created,
|
||||
|
||||
@@ -340,6 +340,7 @@ class AutoClusterFunction(BaseAIFunction):
|
||||
return {
|
||||
'count': clusters_created,
|
||||
'clusters_created': clusters_created,
|
||||
'keywords_updated': keywords_updated
|
||||
'keywords_updated': keywords_updated,
|
||||
'site_id': site.id if site else None
|
||||
}
|
||||
|
||||
|
||||
@@ -329,6 +329,7 @@ class GenerateContentFunction(BaseAIFunction):
|
||||
'content_id': content_record.id,
|
||||
'task_id': task.id,
|
||||
'word_count': word_count,
|
||||
'site_id': task.site_id if task.site_id else None,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -233,9 +233,19 @@ class GenerateIdeasFunction(BaseAIFunction):
|
||||
cluster.status = 'mapped'
|
||||
cluster.save()
|
||||
|
||||
# Get site_id from the first cluster if available
|
||||
site_id = None
|
||||
if clusters:
|
||||
first_cluster = clusters[0]
|
||||
if first_cluster.site_id:
|
||||
site_id = first_cluster.site_id
|
||||
elif first_cluster.sector and first_cluster.sector.site_id:
|
||||
site_id = first_cluster.sector.site_id
|
||||
|
||||
return {
|
||||
'count': ideas_created,
|
||||
'ideas_created': ideas_created
|
||||
'ideas_created': ideas_created,
|
||||
'site_id': site_id
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -214,6 +214,7 @@ class GenerateImagePromptsFunction(BaseAIFunction):
|
||||
return {
|
||||
'count': prompts_created,
|
||||
'prompts_created': prompts_created,
|
||||
'site_id': content.site_id if content.site_id else None
|
||||
}
|
||||
|
||||
# Helper methods
|
||||
|
||||
@@ -196,7 +196,8 @@ class GenerateImagesFunction(BaseAIFunction):
|
||||
return {
|
||||
'count': 1,
|
||||
'images_created': 1,
|
||||
'image_id': image.id
|
||||
'image_id': image.id,
|
||||
'site_id': task.site_id if task.site_id else None
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ class OptimizeContentFunction(BaseAIFunction):
|
||||
'html_content': optimized_html,
|
||||
'meta_title': optimized_meta_title,
|
||||
'meta_description': optimized_meta_description,
|
||||
'site_id': content.site_id if content.site_id else None
|
||||
}
|
||||
|
||||
# Helper methods
|
||||
|
||||
Reference in New Issue
Block a user