mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Add pool input box in post details
This commit is contained in:
@ -34,3 +34,22 @@ def _bump_query_count() -> None:
|
||||
|
||||
|
||||
sa.event.listen(_engine, 'after_execute', lambda *args: _bump_query_count())
|
||||
|
||||
import time
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger("myapp.sqltime")
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
def before_cursor_execute(conn, cursor, statement,
|
||||
parameters, context, executemany):
|
||||
conn.info.setdefault('query_start_time', []).append(time.time())
|
||||
logger.info("Start Query: %s" % statement)
|
||||
|
||||
def after_cursor_execute(conn, cursor, statement,
|
||||
parameters, context, executemany):
|
||||
total = time.time() - conn.info['query_start_time'].pop(-1)
|
||||
logger.info("Total Time: %f" % total)
|
||||
|
||||
sa.event.listen(_engine, "before_cursor_execute", before_cursor_execute)
|
||||
sa.event.listen(_engine, "after_cursor_execute", after_cursor_execute)
|
||||
|
@ -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,14 @@ class PostSerializer(serialization.BaseSerializer):
|
||||
self.post.comments,
|
||||
key=lambda comment: comment.creation_time)]
|
||||
|
||||
def serialize_pools(self) -> 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],
|
||||
|
@ -48,7 +48,7 @@ def upgrade():
|
||||
op.create_table(
|
||||
'pool_post',
|
||||
sa.Column('pool_id', sa.Integer(), nullable=False),
|
||||
sa.Column('post_id', sa.Integer(), nullable=False),
|
||||
sa.Column('post_id', sa.Integer(), nullable=False, index=True),
|
||||
sa.Column('ord', sa.Integer(), nullable=False, index=True),
|
||||
sa.ForeignKeyConstraint(['pool_id'], ['pool.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['post_id'], ['post.id'], ondelete='CASCADE'),
|
||||
|
@ -2,7 +2,6 @@ import sqlalchemy as sa
|
||||
from sqlalchemy.ext.orderinglist import ordering_list
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from szurubooru.model.base import Base
|
||||
import szurubooru.model as model
|
||||
|
||||
|
||||
class PoolName(Base):
|
||||
@ -43,9 +42,9 @@ class PoolPost(Base):
|
||||
order = sa.Column('ord', sa.Integer, nullable=False, index=True)
|
||||
|
||||
pool = sa.orm.relationship('Pool', back_populates='_posts')
|
||||
post = sa.orm.relationship('Post')
|
||||
post = sa.orm.relationship('Post', back_populates='_pools')
|
||||
|
||||
def __init__(self, post: model.Post) -> None:
|
||||
def __init__(self, post) -> None:
|
||||
self.post_id = post.post_id
|
||||
|
||||
class Pool(Base):
|
||||
|
@ -2,7 +2,10 @@ from typing import List
|
||||
import sqlalchemy as sa
|
||||
from szurubooru.model.base import Base
|
||||
from szurubooru.model.comment import Comment
|
||||
from szurubooru.model.pool import PoolPost
|
||||
from sqlalchemy.ext.associationproxy import association_proxy
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.ext.orderinglist import ordering_list
|
||||
|
||||
|
||||
class PostFeature(Base):
|
||||
@ -224,6 +227,12 @@ class Post(Base):
|
||||
notes = sa.orm.relationship(
|
||||
'PostNote', cascade='all, delete-orphan', lazy='joined')
|
||||
comments = sa.orm.relationship('Comment', cascade='all, delete-orphan')
|
||||
_pools = sa.orm.relationship(
|
||||
'PoolPost',
|
||||
lazy='select',
|
||||
order_by='PoolPost.order',
|
||||
back_populates='post')
|
||||
pools = association_proxy('_pools', 'pool')
|
||||
|
||||
# dynamic columns
|
||||
tag_count = sa.orm.column_property(
|
||||
|
Reference in New Issue
Block a user