aboutsummaryrefslogtreecommitdiff
path: root/server/szurubooru/func/posts.py
diff options
context:
space:
mode:
authorShyam Sunder2020-06-04 21:01:28 -0400
committerShyam Sunder2020-06-04 21:01:28 -0400
commitc5358f7f83ef49f51d5ba557dde1b16ce2c83d1d (patch)
tree253e0be234540c266202993567d998a5c951947d /server/szurubooru/func/posts.py
parent4329b1620fe38c2a7bf44615cfb176daa2837590 (diff)
parentb0f1b8c2309277a7b170972d463b4e8d16a79ecc (diff)
client+server: add post pools feature
Diffstat (limited to 'server/szurubooru/func/posts.py')
-rw-r--r--server/szurubooru/func/posts.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py
index f0224b4..d8e984b 100644
--- a/server/szurubooru/func/posts.py
+++ b/server/szurubooru/func/posts.py
@@ -5,7 +5,7 @@ from datetime import datetime
import sqlalchemy as sa
from szurubooru import config, db, model, errors, rest
from szurubooru.func import (
- users, scores, comments, tags, util,
+ users, scores, comments, tags, pools, util,
mime, images, files, image_hash, serialization, snapshots)
@@ -176,6 +176,7 @@ class PostSerializer(serialization.BaseSerializer):
'hasCustomThumbnail': self.serialize_has_custom_thumbnail,
'notes': self.serialize_notes,
'comments': self.serialize_comments,
+ 'pools': self.serialize_pools,
}
def serialize_id(self) -> Any:
@@ -299,6 +300,13 @@ class PostSerializer(serialization.BaseSerializer):
self.post.comments,
key=lambda comment: comment.creation_time)]
+ def serialize_pools(self) -> List[Any]:
+ return [
+ pools.serialize_pool(pool)
+ for pool in sorted(
+ self.post.pools,
+ key=lambda pool: pool.creation_time)]
+
def serialize_post(
post: Optional[model.Post],
@@ -334,6 +342,22 @@ def get_post_by_id(post_id: int) -> model.Post:
return post
+def get_posts_by_ids(ids: List[int]) -> List[model.Post]:
+ if len(ids) == 0:
+ return []
+ posts = (
+ db.session.query(model.Post)
+ .filter(
+ sa.sql.or_(
+ model.Post.post_id == post_id
+ for post_id in ids))
+ .all())
+ id_order = {
+ v: k for k, v in enumerate(ids)
+ }
+ return sorted(posts, key=lambda post: id_order.get(post.post_id))
+
+
def try_get_current_post_feature() -> Optional[model.PostFeature]:
return (
db.session

© 2015 - 2026 Jakob L. Kreuze