Ejemplo n.º 1
0
def filter_display(
    q: sqla.sql.Select,
    user: orm_users.User,
) -> sqla.sql.Select:
    item_feed = orm_items.Item.feed
    q = q.join(item_feed)

    q = feeds_filter.filter_display(q, user)

    return q
Ejemplo n.º 2
0
def filter_display(
    q: sqla.sql.Select,
    user: orm_users.User,
) -> sqla.sql.Select:
    feed_users = orm_feeds.Feed.users.and_(
        orm_users.User.UserID == user.UserID,
    )
    q = q.join(feed_users)

    return q
Ejemplo n.º 3
0
def filter_lang(
    q: sqla.sql.Select,
    lang: schema_feeds.Language,
) -> sqla.sql.Select:
    item_feed = orm_items.Item.feed

    q = q.join(item_feed)

    q = feeds_filter.filter_languages(q, [lang])

    return q
Ejemplo n.º 4
0
def filter_like(
    q: sqla.sql.Select,
    score: schema_items.Like,
    user: orm_users.User,
) -> sqla.sql.Select:
    item_likes = orm_items.Item.likes.and_(
        orm_items.Like.UserID == user.UserID, )

    q = q.join(item_likes)

    q = q.where(orm_items.Like.Score == score.name)

    return q
Ejemplo n.º 5
0
def filter_magic(
    q: sqla.sql.Select,
    user: orm_users.User,
    unscored: bool = True,
) -> sqla.sql.Select:
    item_magic = orm_items.Item.magic.and_(
        orm_items.Magic.UserID == user.UserID, )

    q = q.join(item_magic, isouter=True)

    q_where = orm_items.Item.magic.any(orm_items.Magic.UserID == user.UserID)
    if unscored:
        q_where = ~q_where

    q = q.where(q_where)

    return q
Ejemplo n.º 6
0
def filter_tags(
    q: sqla.sql.Select,
    tags: typing.List[orm_feeds.Tag],
    user: orm_users.User,
) -> sqla.sql.Select:
    feed_tags = orm_feeds.Feed.tags.and_(
        orm_feeds.Tag.UserID == user.UserID,
    )
    q = q.join(feed_tags)

    q = q.where(
        orm_feeds.Tag.TagID.in_(
            [tag_it.TagID for tag_it in tags]
        )
    )

    return q
Ejemplo n.º 7
0
def order_magic(
    q: sqla.sql.Select,
    user: orm_users.User,
    desc: bool = True,
) -> sqla.sql.Select:
    item_magic = orm_items.Item.magic.and_(
        orm_items.Magic.UserID == user.UserID,
    )

    q = q.join(item_magic, isouter=True)

    magic_score = orm_items.Magic.Score
    if desc:
        magic_score = sqla.desc(magic_score)

    q = q.order_by(magic_score)

    return q