diff --git a/client/html/help_search_posts.tpl b/client/html/help_search_posts.tpl
index a9e1a8e..85dffce 100644
--- a/client/html/help_search_posts.tpl
+++ b/client/html/help_search_posts.tpl
@@ -70,6 +70,10 @@
type |
given type of posts. <value> can be either image , animation (or animated or anim ), flash (or swf ) or video (or webm ). |
+
+ flag |
+ having given flag. <value> can be either loop or sound . |
+
content-checksum |
having given SHA1 checksum |
diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py
index 4fcc087..a10780c 100644
--- a/server/szurubooru/func/posts.py
+++ b/server/szurubooru/func/posts.py
@@ -222,7 +222,7 @@ class PostSerializer(serialization.BaseSerializer):
return get_post_thumbnail_url(self.post)
def serialize_flags(self) -> Any:
- return self.post.flags
+ return [x for x in self.post.flags.split(',') if x]
def serialize_tags(self) -> Any:
return [
@@ -356,7 +356,7 @@ def create_post(
post.safety = model.Post.SAFETY_SAFE
post.user = user
post.creation_time = datetime.utcnow()
- post.flags = []
+ post.flags = ''
post.type = ''
post.checksum = ''
@@ -628,7 +628,7 @@ def update_post_flags(post: model.Post, flags: List[str]) -> None:
raise InvalidPostFlagError(
'Flag must be one of %r.' % list(FLAG_MAP.values()))
target_flags.append(flag)
- post.flags = target_flags
+ post.flags = ','.join(target_flags)
def feature_post(post: model.Post, user: Optional[model.User]) -> None:
diff --git a/server/szurubooru/func/snapshots.py b/server/szurubooru/func/snapshots.py
index 240c3bc..b6a13e0 100644
--- a/server/szurubooru/func/snapshots.py
+++ b/server/szurubooru/func/snapshots.py
@@ -29,7 +29,7 @@ def get_post_snapshot(post: model.Post) -> Dict[str, Any]:
'source': post.source,
'safety': post.safety,
'checksum': post.checksum,
- 'flags': post.flags,
+ 'flags': sorted(post.flags.split(',')),
'featured': post.is_featured,
'tags': sorted([tag.first_name for tag in post.tags]),
'relations': sorted([rel.post_id for rel in post.relations]),
diff --git a/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py b/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py
new file mode 100644
index 0000000..04e0764
--- /dev/null
+++ b/server/szurubooru/migrations/versions/1cd4c7b22846_change_flags_column_to_string.py
@@ -0,0 +1,63 @@
+'''
+Change flags column to string
+
+Revision ID: 1cd4c7b22846
+Created at: 2018-09-21 19:37:27.686568
+'''
+
+import sqlalchemy as sa
+from alembic import op
+
+revision = '1cd4c7b22846'
+down_revision = 'a39c7f98a7fa'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ conn = op.get_bind()
+ op.alter_column('post', 'flags', new_column_name='oldflags')
+ op.add_column('post', sa.Column(
+ 'flags', sa.Unicode(200), default='', nullable=True))
+ posts = sa.Table(
+ 'post',
+ sa.MetaData(),
+ sa.Column('id', sa.Integer, primary_key=True),
+ sa.Column('flags', sa.Unicode(200), default='', nullable=True),
+ sa.Column('oldflags', sa.PickleType(), nullable=True),
+ )
+ for row in conn.execute(posts.select()):
+ newflag = ','.join(row.oldflags)
+ conn.execute(
+ # pylint: disable=no-value-for-parameter
+ posts.update().where(
+ posts.c.id == row.id
+ ).values(
+ flags=newflag
+ )
+ )
+ op.drop_column('post', 'oldflags')
+
+
+def downgrade():
+ conn = op.get_bind()
+ op.alter_column('post', 'flags', new_column_name='oldflags')
+ op.add_column('post', sa.Column('flags', sa.PickleType(), nullable=True))
+ posts = sa.Table(
+ 'post',
+ sa.MetaData(),
+ sa.Column('id', sa.Integer, primary_key=True),
+ sa.Column('flags', sa.PickleType(), nullable=True),
+ sa.Column('oldflags', sa.Unicode(200), default='', nullable=True),
+ )
+ for row in conn.execute(posts.select()):
+ newflag = [x for x in row.oldflags.split(',') if x]
+ conn.execute(
+ # pylint: disable=no-value-for-parameter
+ posts.update().where(
+ posts.c.id == row.id
+ ).values(
+ flags=newflag
+ )
+ )
+ op.drop_column('post', 'oldflags')
diff --git a/server/szurubooru/model/post.py b/server/szurubooru/model/post.py
index d682c1b..c0e3b13 100644
--- a/server/szurubooru/model/post.py
+++ b/server/szurubooru/model/post.py
@@ -169,7 +169,7 @@ class Post(Base):
last_edit_time = sa.Column('last_edit_time', sa.DateTime)
safety = sa.Column('safety', sa.Unicode(32), nullable=False)
source = sa.Column('source', sa.Unicode(200))
- flags = sa.Column('flags', sa.PickleType, default=None)
+ flags = sa.Column('flags', sa.Unicode(200), default='')
# content description
type = sa.Column('type', sa.Unicode(32), nullable=False)
diff --git a/server/szurubooru/search/configs/post_search_config.py b/server/szurubooru/search/configs/post_search_config.py
index 8baa0dd..3d5b0ee 100644
--- a/server/szurubooru/search/configs/post_search_config.py
+++ b/server/szurubooru/search/configs/post_search_config.py
@@ -35,6 +35,14 @@ def _safety_transformer(value: str) -> str:
return search_util.enum_transformer(available_values, value)
+def _flag_transformer(value: str) -> str:
+ available_values = {
+ 'loop': model.Post.FLAG_LOOP,
+ 'sound': model.Post.FLAG_SOUND,
+ }
+ return '%' + search_util.enum_transformer(available_values, value) + '%'
+
+
def _create_score_filter(score: int) -> Filter:
def wrapper(
query: SaQuery,
@@ -326,6 +334,12 @@ class PostSearchConfig(BaseSearchConfig):
['note-text'],
_note_filter
),
+
+ (
+ ['flag'],
+ search_util.create_str_filter(
+ model.Post.flags, _flag_transformer)
+ ),
])
@property