diff --git a/tildes/alembic/versions/b761d0185ca0_groups_add_important_topic_tags.py b/tildes/alembic/versions/b761d0185ca0_groups_add_important_topic_tags.py new file mode 100644 index 0000000..ca4c115 --- /dev/null +++ b/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") diff --git a/tildes/scss/modules/_topic.scss b/tildes/scss/modules/_topic.scss index a87e2f0..9743436 100644 --- a/tildes/scss/modules/_topic.scss +++ b/tildes/scss/modules/_topic.scss @@ -133,6 +133,7 @@ .topic-tags { display: flex; flex-wrap: wrap; + align-items: center; margin: 0; } diff --git a/tildes/tildes/models/group/group.py b/tildes/tildes/models/group/group.py index a27b72f..6d13e73 100644 --- a/tildes/tildes/models/group/group.py +++ b/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 diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index ed0c3e8..ca9acc6 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/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