minor changes
This commit is contained in:
@@ -156,13 +156,30 @@ def _tags_from_text(text):
|
||||
return pairs
|
||||
|
||||
|
||||
def _managed_creator_names(project):
|
||||
"""Slugified usernames of the owner + contributors — the creator tags that
|
||||
sync_creator_tags manages automatically. Creator tags that are NOT backed
|
||||
by an account (e.g. an offline artist) are treated as manual and stay
|
||||
editable/removable."""
|
||||
names = {slugify_tag(project.owner.username)}
|
||||
names.update(
|
||||
slugify_tag(c.user.username)
|
||||
for c in project.contributors.select_related('user')
|
||||
)
|
||||
return names
|
||||
|
||||
|
||||
def _apply_tags(project, raw_tags, actor):
|
||||
"""Replace a project's manual tags (auto-creating new ones). Creator tags
|
||||
are managed separately by sync_creator_tags."""
|
||||
"""Replace a project's manual tags (auto-creating new ones). Account-backed
|
||||
creator tags (owner + contributors) are managed by sync_creator_tags and
|
||||
preserved; any other creator tag is editable like any other manual tag."""
|
||||
creator_cat = TagCategory.objects.filter(slug='creator').first()
|
||||
to_delete = project.tag_links.all()
|
||||
if creator_cat is not None:
|
||||
to_delete = to_delete.exclude(tag__category=creator_cat)
|
||||
to_delete = to_delete.exclude(
|
||||
tag__category=creator_cat,
|
||||
tag__name__in=_managed_creator_names(project),
|
||||
)
|
||||
to_delete.delete()
|
||||
|
||||
for category_slug, name in _tags_from_text(raw_tags):
|
||||
@@ -178,11 +195,18 @@ def _apply_tags(project, raw_tags, actor):
|
||||
|
||||
|
||||
def _current_tags(project):
|
||||
"""Serialize a project's non-creator tags back to 'category:name' form."""
|
||||
"""Serialize a project's editable tags back to 'category:name' form.
|
||||
|
||||
Account-backed creator tags (owner + contributors) are auto-managed and
|
||||
hidden; manual creator tags (no matching account) remain visible so they
|
||||
can be removed."""
|
||||
creator_cat = TagCategory.objects.filter(slug='creator').first()
|
||||
qs = project.tag_links.select_related('tag__category').all()
|
||||
if creator_cat is not None:
|
||||
qs = qs.exclude(tag__category=creator_cat)
|
||||
qs = qs.exclude(
|
||||
tag__category=creator_cat,
|
||||
tag__name__in=_managed_creator_names(project),
|
||||
)
|
||||
return ' '.join(f'{tl.tag.category.slug}:{tl.tag.name}' for tl in qs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user