Browse Source

Add group-specific "important tags" for topics

This enables (manually, so far) setting "important tags" for individual
groups. Topics in the group with any of these tags will have them shown
in listings next to the group name (similar to how spoiler and nsfw work
globally).
merge-requests/85/head
Deimos 5 years ago
parent
commit
ce591be3b0
  1. 31
      tildes/alembic/versions/b761d0185ca0_groups_add_important_topic_tags.py
  2. 1
      tildes/scss/modules/_topic.scss
  3. 3
      tildes/tildes/models/group/group.py
  4. 6
      tildes/tildes/models/topic/topic.py

31
tildes/alembic/versions/b761d0185ca0_groups_add_important_topic_tags.py

@ -0,0 +1,31 @@
"""Groups: add important_topic_tags
Revision ID: b761d0185ca0
Revises: 679090fd4977
Create Date: 2019-10-26 01:51:21.231463
"""
from alembic import op
import sqlalchemy as sa
from tildes.lib.database import TagList
# revision identifiers, used by Alembic.
revision = "b761d0185ca0"
down_revision = "679090fd4977"
branch_labels = None
depends_on = None
def upgrade():
op.add_column(
"groups",
sa.Column(
"important_topic_tags", TagList(), server_default="{}", nullable=False
),
)
def downgrade():
op.drop_column("groups", "important_topic_tags")

1
tildes/scss/modules/_topic.scss

@ -133,6 +133,7 @@
.topic-tags {
display: flex;
flex-wrap: wrap;
align-items: center;
margin: 0;
}

3
tildes/tildes/models/group/group.py

@ -57,6 +57,9 @@ class Group(DatabaseModel):
Boolean, nullable=False, server_default="false"
)
common_topic_tags: List[str] = Column(TagList, nullable=False, server_default="{}")
important_topic_tags: List[str] = Column(
TagList, nullable=False, server_default="{}"
)
# Create a GiST index on path as well as the btree one that will be created by the
# index=True/unique=True keyword args to Column above. The GiST index supports

6
tildes/tildes/models/topic/topic.py

@ -165,13 +165,15 @@ class Topic(DatabaseModel):
"""Return only the topic's "important" tags."""
global_important_tags = ["nsfw", "spoiler"]
important_tags = set(self.group.important_topic_tags + global_important_tags)
# used with startswith() to check for sub-tags
global_important_prefixes = tuple([f"{tag}." for tag in global_important_tags])
important_prefixes = tuple([f"{tag}." for tag in important_tags])
return [
tag
for tag in self.tags
if tag in global_important_tags or tag.startswith(global_important_prefixes)
if tag in important_tags or tag.startswith(important_prefixes)
]
@property

Loading…
Cancel
Save