refactor stage 1
This commit is contained in:
@@ -287,3 +287,171 @@ class Images(SiteSectorBaseModel):
|
||||
title = content_title or task_title or 'Unknown'
|
||||
return f"{title} - {self.image_type}"
|
||||
|
||||
|
||||
class ContentClusterMap(SiteSectorBaseModel):
|
||||
"""Associates generated content with planner clusters + roles."""
|
||||
|
||||
ROLE_CHOICES = [
|
||||
('hub', 'Hub Page'),
|
||||
('supporting', 'Supporting Page'),
|
||||
('attribute', 'Attribute Page'),
|
||||
]
|
||||
|
||||
SOURCE_CHOICES = [
|
||||
('blueprint', 'Blueprint'),
|
||||
('manual', 'Manual'),
|
||||
('import', 'Import'),
|
||||
]
|
||||
|
||||
content = models.ForeignKey(
|
||||
Content,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='cluster_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
task = models.ForeignKey(
|
||||
Tasks,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='cluster_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
cluster = models.ForeignKey(
|
||||
'planner.Clusters',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='content_mappings',
|
||||
)
|
||||
role = models.CharField(max_length=50, choices=ROLE_CHOICES, default='hub')
|
||||
source = models.CharField(max_length=50, choices=SOURCE_CHOICES, default='blueprint')
|
||||
metadata = models.JSONField(default=dict, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'writer'
|
||||
db_table = 'igny8_content_cluster_map'
|
||||
unique_together = [['content', 'cluster', 'role']]
|
||||
indexes = [
|
||||
models.Index(fields=['cluster', 'role']),
|
||||
models.Index(fields=['content', 'role']),
|
||||
models.Index(fields=['task', 'role']),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
provider = self.content or self.task
|
||||
if provider:
|
||||
self.account = provider.account
|
||||
self.site = provider.site
|
||||
self.sector = provider.sector
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.cluster.name} ({self.get_role_display()})"
|
||||
|
||||
|
||||
class ContentTaxonomyMap(SiteSectorBaseModel):
|
||||
"""Maps content entities to blueprint taxonomies for syncing/publishing."""
|
||||
|
||||
SOURCE_CHOICES = [
|
||||
('blueprint', 'Blueprint'),
|
||||
('manual', 'Manual'),
|
||||
('import', 'Import'),
|
||||
]
|
||||
|
||||
content = models.ForeignKey(
|
||||
Content,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='taxonomy_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
task = models.ForeignKey(
|
||||
Tasks,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='taxonomy_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
taxonomy = models.ForeignKey(
|
||||
'site_building.SiteBlueprintTaxonomy',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='content_mappings',
|
||||
)
|
||||
source = models.CharField(max_length=50, choices=SOURCE_CHOICES, default='blueprint')
|
||||
metadata = models.JSONField(default=dict, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'writer'
|
||||
db_table = 'igny8_content_taxonomy_map'
|
||||
unique_together = [['content', 'taxonomy']]
|
||||
indexes = [
|
||||
models.Index(fields=['taxonomy']),
|
||||
models.Index(fields=['content', 'taxonomy']),
|
||||
models.Index(fields=['task', 'taxonomy']),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
provider = self.content or self.task
|
||||
if provider:
|
||||
self.account = provider.account
|
||||
self.site = provider.site
|
||||
self.sector = provider.sector
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.taxonomy.name}"
|
||||
|
||||
|
||||
class ContentAttributeMap(SiteSectorBaseModel):
|
||||
"""Stores structured attribute data tied to content/task records."""
|
||||
|
||||
SOURCE_CHOICES = [
|
||||
('blueprint', 'Blueprint'),
|
||||
('manual', 'Manual'),
|
||||
('import', 'Import'),
|
||||
]
|
||||
|
||||
content = models.ForeignKey(
|
||||
Content,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='attribute_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
task = models.ForeignKey(
|
||||
Tasks,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='attribute_mappings',
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
name = models.CharField(max_length=120)
|
||||
value = models.CharField(max_length=255, blank=True, null=True)
|
||||
source = models.CharField(max_length=50, choices=SOURCE_CHOICES, default='blueprint')
|
||||
metadata = models.JSONField(default=dict, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'writer'
|
||||
db_table = 'igny8_content_attribute_map'
|
||||
indexes = [
|
||||
models.Index(fields=['name']),
|
||||
models.Index(fields=['content', 'name']),
|
||||
models.Index(fields=['task', 'name']),
|
||||
]
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
provider = self.content or self.task
|
||||
if provider:
|
||||
self.account = provider.account
|
||||
self.site = provider.site
|
||||
self.sector = provider.sector
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
target = self.content or self.task
|
||||
return f"{target} – {self.name}"
|
||||
|
||||
Reference in New Issue
Block a user