mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Compare commits
11 Commits
781e1af9e0
...
d7ffdb0997
Author | SHA1 | Date | |
---|---|---|---|
d7ffdb0997 | |||
0971745615 | |||
27f94be56d | |||
98227e562e | |||
5244718e0f | |||
ac64c1ca50 | |||
ff788a5e30 | |||
0acc522bfc | |||
a5cf49a94a | |||
374f4a5fa9 | |||
3875ec173f |
@ -36,6 +36,7 @@ $button-disabled-background-color = #CCC
|
|||||||
$post-thumbnail-border-color = $main-color
|
$post-thumbnail-border-color = $main-color
|
||||||
$post-thumbnail-no-tags-border-color = #F44
|
$post-thumbnail-no-tags-border-color = #F44
|
||||||
$default-tag-category-background-color = $active-tab-background-color
|
$default-tag-category-background-color = $active-tab-background-color
|
||||||
|
$default-pool-category-background-color = $active-tab-background-color
|
||||||
$new-tag-background-color = #DFC
|
$new-tag-background-color = #DFC
|
||||||
$new-tag-text-color = black
|
$new-tag-text-color = black
|
||||||
$implied-tag-background-color = #FFC
|
$implied-tag-background-color = #FFC
|
||||||
|
@ -31,12 +31,12 @@
|
|||||||
outline: none
|
outline: none
|
||||||
border-right: 20px solid transparent
|
border-right: 20px solid transparent
|
||||||
&:before
|
&:before
|
||||||
content: ' ';
|
content: ' '
|
||||||
display: block;
|
display: block
|
||||||
position: relative;
|
position: relative
|
||||||
width: 100%;
|
width: 100%
|
||||||
height: 20px;
|
height: 20px
|
||||||
bottom: 20px;
|
bottom: 20px
|
||||||
|
|
||||||
.thumbnail
|
.thumbnail
|
||||||
width: 100%
|
width: 100%
|
||||||
@ -47,6 +47,7 @@
|
|||||||
background-position: 50% 30%
|
background-position: 50% 30%
|
||||||
position: absolute
|
position: absolute
|
||||||
display: inline-block
|
display: inline-block
|
||||||
|
box-shadow: 0 0 0 1px rgba(0,0,0,0.2)
|
||||||
|
|
||||||
.thumbnail-1, .thumbnail.empty
|
.thumbnail-1, .thumbnail.empty
|
||||||
right: -4px
|
right: -4px
|
||||||
|
@ -14,26 +14,26 @@
|
|||||||
background: $top-navigation-color
|
background: $top-navigation-color
|
||||||
|
|
||||||
.pool-name
|
.pool-name
|
||||||
flex: 1 1;
|
flex: 1 1
|
||||||
text-align: center;
|
text-align: center
|
||||||
overflow: hidden;
|
overflow: hidden
|
||||||
white-space: nowrap;
|
white-space: nowrap
|
||||||
-o-text-overflow: ellipsis;
|
-o-text-overflow: ellipsis
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis
|
||||||
|
|
||||||
.first, .last
|
.first, .last
|
||||||
flex-basis: 1em;
|
flex-basis: 1em
|
||||||
|
|
||||||
.first, .prev, .next, .last
|
.first, .prev, .next, .last
|
||||||
flex: 0 1;
|
flex: 0 1
|
||||||
white-space: nowrap;
|
white-space: nowrap
|
||||||
|
|
||||||
>span
|
>span
|
||||||
padding-top: 2px
|
padding-top: 2px
|
||||||
padding-bottom: 2px
|
padding-bottom: 2px
|
||||||
margin: 0 .25em;
|
margin: 0 .25em
|
||||||
|
|
||||||
|
|
||||||
.darktheme .pool-navigator-container .pool-info-wrapper
|
.darktheme .pool-navigator-container .pool-info-wrapper
|
||||||
border: 1px solid $top-navigation-color-darktheme
|
border: 1px solid $top-navigation-color-darktheme
|
||||||
background: $window-color-darktheme
|
background: $window-color-darktheme
|
||||||
|
@ -14,7 +14,6 @@ const EmptyView = require("../views/empty_view.js");
|
|||||||
const fields = [
|
const fields = [
|
||||||
"id",
|
"id",
|
||||||
"names",
|
"names",
|
||||||
"posts",
|
|
||||||
"creationTime",
|
"creationTime",
|
||||||
"postCount",
|
"postCount",
|
||||||
"category",
|
"category",
|
||||||
@ -101,11 +100,13 @@ class PoolListController {
|
|||||||
return uri.formatClientLink("pools", parameters);
|
return uri.formatClientLink("pools", parameters);
|
||||||
},
|
},
|
||||||
requestPage: (offset, limit) => {
|
requestPage: (offset, limit) => {
|
||||||
|
const canEditPosts = api.hasPrivilege("pools:edit") || api.hasPrivilege("pools:edit:posts");
|
||||||
|
const effectiveFields = fields.concat([canEditPosts ? "posts": "postsMicro"]);
|
||||||
return PoolList.search(
|
return PoolList.search(
|
||||||
this._ctx.parameters.query,
|
this._ctx.parameters.query,
|
||||||
offset,
|
offset,
|
||||||
limit,
|
limit,
|
||||||
fields
|
effectiveFields
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
pageRenderer: (pageCtx) => {
|
pageRenderer: (pageCtx) => {
|
||||||
|
@ -17,11 +17,6 @@ class PostMainController extends BasePostController {
|
|||||||
constructor(ctx, editMode) {
|
constructor(ctx, editMode) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
|
||||||
let poolPostsNearby = Promise.resolve({results: []});
|
|
||||||
if (api.hasPrivilege("pools:list") && api.hasPrivilege("pools:view")) {
|
|
||||||
poolPostsNearby = PostList.getNearbyPoolPosts(ctx.parameters.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
let parameters = ctx.parameters;
|
let parameters = ctx.parameters;
|
||||||
Promise.all([
|
Promise.all([
|
||||||
Post.get(ctx.parameters.id),
|
Post.get(ctx.parameters.id),
|
||||||
@ -29,10 +24,9 @@ class PostMainController extends BasePostController {
|
|||||||
ctx.parameters.id,
|
ctx.parameters.id,
|
||||||
parameters ? parameters.query : null
|
parameters ? parameters.query : null
|
||||||
),
|
),
|
||||||
poolPostsNearby
|
|
||||||
]).then(
|
]).then(
|
||||||
(responses) => {
|
(responses) => {
|
||||||
const [post, aroundResponse, poolPostsNearby] = responses;
|
const [post, aroundResponse] = responses;
|
||||||
let aroundPool = null;
|
let aroundPool = null;
|
||||||
|
|
||||||
// remove junk from query, but save it into history so that it can
|
// remove junk from query, but save it into history so that it can
|
||||||
@ -47,13 +41,13 @@ class PostMainController extends BasePostController {
|
|||||||
)
|
)
|
||||||
: uri.formatClientLink("post", ctx.parameters.id);
|
: uri.formatClientLink("post", ctx.parameters.id);
|
||||||
router.replace(url, ctx.state, false);
|
router.replace(url, ctx.state, false);
|
||||||
parameters.query.split(" ").forEach((item) => {
|
misc.splitByWhitespace(parameters.query).forEach((item) => {
|
||||||
const found = item.match(/^pool:([0-9]+)/i);
|
const found = item.match(/^pool:([0-9]+)/i);
|
||||||
if (found) {
|
if (found) {
|
||||||
const activePool = parseInt(found[1]);
|
const activePool = parseInt(found[1]);
|
||||||
poolPostsNearby.forEach((nearbyPosts) => {
|
post.pools.map((pool) => {
|
||||||
if (nearbyPosts.pool.id == activePool) {
|
if (pool.id == activePool) {
|
||||||
aroundPool = nearbyPosts
|
aroundPool = pool;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -63,7 +57,6 @@ class PostMainController extends BasePostController {
|
|||||||
this._post = post;
|
this._post = post;
|
||||||
this._view = new PostMainView({
|
this._view = new PostMainView({
|
||||||
post: post,
|
post: post,
|
||||||
poolPostsNearby: poolPostsNearby,
|
|
||||||
editMode: editMode,
|
editMode: editMode,
|
||||||
prevPostId: aroundPool
|
prevPostId: aroundPool
|
||||||
? (aroundPool.previousPost ? aroundPool.previousPost.id : null)
|
? (aroundPool.previousPost ? aroundPool.previousPost.id : null)
|
||||||
|
@ -16,9 +16,9 @@ class PoolNavigatorControl extends events.EventTarget {
|
|||||||
views.replaceContent(
|
views.replaceContent(
|
||||||
this._hostNode,
|
this._hostNode,
|
||||||
template({
|
template({
|
||||||
pool: poolPostNearby.pool,
|
pool: poolPostNearby,
|
||||||
parameters: { query: `pool:${poolPostNearby.pool.id}` },
|
parameters: { query: `pool:${poolPostNearby.id}` },
|
||||||
linkClass: misc.makeCssName(poolPostNearby.pool.category, "pool"),
|
linkClass: misc.makeCssName(poolPostNearby.category, "pool"),
|
||||||
canViewPosts: api.hasPrivilege("posts:view"),
|
canViewPosts: api.hasPrivilege("posts:view"),
|
||||||
canViewPools: api.hasPrivilege("pools:view"),
|
canViewPools: api.hasPrivilege("pools:view"),
|
||||||
firstPost: poolPostNearby.firstPost,
|
firstPost: poolPostNearby.firstPost,
|
||||||
|
@ -13,8 +13,8 @@ class PoolNavigatorListControl extends events.EventTarget {
|
|||||||
this._poolPostNearby = poolPostNearby;
|
this._poolPostNearby = poolPostNearby;
|
||||||
this._indexToNode = {};
|
this._indexToNode = {};
|
||||||
|
|
||||||
for (let [i, entry] of this._poolPostNearby.entries()) {
|
for (const entry of this._poolPostNearby) {
|
||||||
this._installPoolNavigatorNode(entry, i);
|
this._installPoolNavigatorNode(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ class PoolNavigatorListControl extends events.EventTarget {
|
|||||||
return this._hostNode;
|
return this._hostNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
_installPoolNavigatorNode(poolPostNearby, i) {
|
_installPoolNavigatorNode(poolPostNearby) {
|
||||||
const poolListItemNode = document.createElement("div");
|
const poolListItemNode = document.createElement("div");
|
||||||
const poolControl = new PoolNavigatorControl(
|
const poolControl = new PoolNavigatorControl(
|
||||||
poolListItemNode,
|
poolListItemNode,
|
||||||
|
@ -36,7 +36,7 @@ class Pool extends events.EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get posts() {
|
get posts() {
|
||||||
return this._posts;
|
return this._postsMicro || this._posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
get postCount() {
|
get postCount() {
|
||||||
@ -51,6 +51,22 @@ class Pool extends events.EventTarget {
|
|||||||
return this._lastEditTime;
|
return this._lastEditTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get firstPost() {
|
||||||
|
return this._firstPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
get lastPost() {
|
||||||
|
return this._lastPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
get previousPost() {
|
||||||
|
return this._previousPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
get nextPost() {
|
||||||
|
return this._nextPost;
|
||||||
|
}
|
||||||
|
|
||||||
set names(value) {
|
set names(value) {
|
||||||
this._names = value;
|
this._names = value;
|
||||||
}
|
}
|
||||||
@ -169,10 +185,15 @@ class Pool extends events.EventTarget {
|
|||||||
_creationTime: response.creationTime,
|
_creationTime: response.creationTime,
|
||||||
_lastEditTime: response.lastEditTime,
|
_lastEditTime: response.lastEditTime,
|
||||||
_postCount: response.postCount || 0,
|
_postCount: response.postCount || 0,
|
||||||
|
_postsMicro: response.postsMicro,
|
||||||
|
_firstPost: response.firstPost || null,
|
||||||
|
_lastPost: response.lastPost || null,
|
||||||
|
_previousPost: response.previousPost || null,
|
||||||
|
_nextPost: response.nextPost || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let obj of [this, this._orig]) {
|
for (let obj of [this, this._orig]) {
|
||||||
obj._posts.sync(response.posts);
|
obj._posts.sync(response.posts || []);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(this, map);
|
Object.assign(this, map);
|
||||||
|
@ -16,14 +16,6 @@ class PostList extends AbstractList {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getNearbyPoolPosts(id) {
|
|
||||||
return api.get(
|
|
||||||
uri.formatApiLink("post", id, "pools-nearby", {
|
|
||||||
fields: "id",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static search(text, offset, limit, fields) {
|
static search(text, offset, limit, fields) {
|
||||||
return api
|
return api
|
||||||
.get(
|
.get(
|
||||||
|
@ -30,7 +30,7 @@ class PoolCreateView extends events.EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let node of this._formNode.querySelectorAll(
|
for (let node of this._formNode.querySelectorAll(
|
||||||
"input, select, textarea, posts"
|
"input, select, textarea"
|
||||||
)) {
|
)) {
|
||||||
node.addEventListener("change", (e) => {
|
node.addEventListener("change", (e) => {
|
||||||
this.dispatchEvent(new CustomEvent("change"));
|
this.dispatchEvent(new CustomEvent("change"));
|
||||||
|
@ -58,7 +58,7 @@ class PostMainView {
|
|||||||
this._installSidebar(ctx);
|
this._installSidebar(ctx);
|
||||||
this._installCommentForm();
|
this._installCommentForm();
|
||||||
this._installComments(ctx.post.comments);
|
this._installComments(ctx.post.comments);
|
||||||
this._installPoolNavigators(ctx.poolPostsNearby);
|
this._installPoolNavigators(ctx);
|
||||||
|
|
||||||
const showPreviousImage = () => {
|
const showPreviousImage = () => {
|
||||||
if (ctx.prevPostId) {
|
if (ctx.prevPostId) {
|
||||||
@ -139,7 +139,7 @@ class PostMainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_installPoolNavigators(poolPostsNearby) {
|
_installPoolNavigators(ctx) {
|
||||||
const poolNavigatorsContainerNode = document.querySelector(
|
const poolNavigatorsContainerNode = document.querySelector(
|
||||||
"#content-holder .pool-navigators-container"
|
"#content-holder .pool-navigators-container"
|
||||||
);
|
);
|
||||||
@ -149,7 +149,7 @@ class PostMainView {
|
|||||||
|
|
||||||
this.poolNavigatorsControl = new PoolNavigatorListControl(
|
this.poolNavigatorsControl = new PoolNavigatorListControl(
|
||||||
poolNavigatorsContainerNode,
|
poolNavigatorsContainerNode,
|
||||||
poolPostsNearby,
|
ctx.post.pools,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,19 +281,6 @@ def get_posts_around(
|
|||||||
ctx, post_id, lambda post: _serialize_post(ctx, post)
|
ctx, post_id, lambda post: _serialize_post(ctx, post)
|
||||||
)
|
)
|
||||||
|
|
||||||
@rest.routes.get("/post/(?P<post_id>[^/]+)/pools-nearby/?")
|
|
||||||
def get_pools_around(
|
|
||||||
ctx: rest.Context, params: Dict[str, str]
|
|
||||||
) -> rest.Response:
|
|
||||||
auth.verify_privilege(ctx.user, "posts:list")
|
|
||||||
auth.verify_privilege(ctx.user, "posts:view")
|
|
||||||
auth.verify_privilege(ctx.user, "pools:list")
|
|
||||||
_search_executor_config.user = ctx.user
|
|
||||||
post = _get_post(params)
|
|
||||||
results = posts.get_pools_nearby(post)
|
|
||||||
return posts.serialize_pool_posts_nearby(results)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@rest.routes.post("/posts/reverse-search/?")
|
@rest.routes.post("/posts/reverse-search/?")
|
||||||
def get_posts_by_image(
|
def get_posts_by_image(
|
||||||
|
@ -108,6 +108,7 @@ class PoolSerializer(serialization.BaseSerializer):
|
|||||||
"lastEditTime": self.serialize_last_edit_time,
|
"lastEditTime": self.serialize_last_edit_time,
|
||||||
"postCount": self.serialize_post_count,
|
"postCount": self.serialize_post_count,
|
||||||
"posts": self.serialize_posts,
|
"posts": self.serialize_posts,
|
||||||
|
"postsMicro": self.serialize_posts_micro,
|
||||||
}
|
}
|
||||||
|
|
||||||
def serialize_id(self) -> Any:
|
def serialize_id(self) -> Any:
|
||||||
@ -143,6 +144,14 @@ class PoolSerializer(serialization.BaseSerializer):
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def serialize_posts_micro(self) -> Any:
|
||||||
|
posts_micro = []
|
||||||
|
for i, rel in enumerate(self.pool.posts):
|
||||||
|
posts_micro.append(posts.serialize_micro_post(rel, None))
|
||||||
|
if i == 2:
|
||||||
|
break
|
||||||
|
return posts_micro
|
||||||
|
|
||||||
|
|
||||||
def serialize_pool(
|
def serialize_pool(
|
||||||
pool: model.Pool, options: List[str] = []
|
pool: model.Pool, options: List[str] = []
|
||||||
|
@ -9,6 +9,7 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
from szurubooru import config, db, errors, model, rest
|
from szurubooru import config, db, errors, model, rest
|
||||||
from szurubooru.func import (
|
from szurubooru.func import (
|
||||||
|
auth,
|
||||||
comments,
|
comments,
|
||||||
files,
|
files,
|
||||||
image_hash,
|
image_hash,
|
||||||
@ -345,8 +346,10 @@ class PostSerializer(serialization.BaseSerializer):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def serialize_pools(self) -> List[Any]:
|
def serialize_pools(self) -> List[Any]:
|
||||||
|
if not auth.has_privilege(self.auth_user, "pools:list"):
|
||||||
|
return []
|
||||||
return [
|
return [
|
||||||
pools.serialize_micro_pool(pool)
|
{**pools.serialize_micro_pool(pool), **get_pool_posts_nearby(self.post, pool)} if auth.has_privilege(self.auth_user, "pools:view") else pools.serialize_micro_pool(pool)
|
||||||
for pool in sorted(
|
for pool in sorted(
|
||||||
self.post.pools, key=lambda pool: pool.creation_time
|
self.post.pools, key=lambda pool: pool.creation_time
|
||||||
)
|
)
|
||||||
@ -977,46 +980,37 @@ def search_by_image(image_content: bytes) -> List[Tuple[float, model.Post]]:
|
|||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
PoolPostsNearby = namedtuple('PoolPostsNearby', 'pool first_post prev_post next_post last_post')
|
def serialize_safe_post(
|
||||||
def get_pools_nearby(
|
post: Optional[model.Post]
|
||||||
post: model.Post
|
) -> rest.Response:
|
||||||
) -> List[PoolPostsNearby]:
|
return {"id": getattr(post, "post_id", None)} if post else None
|
||||||
response = []
|
|
||||||
pools = post.pools
|
|
||||||
|
|
||||||
for pool in pools:
|
|
||||||
prev_post_id = None
|
|
||||||
next_post_id = None
|
|
||||||
first_post_id = pool.posts[0].post_id,
|
|
||||||
last_post_id = pool.posts[-1].post_id,
|
|
||||||
|
|
||||||
for previous_item, current_item, next_item in _get_nearby_iter(pool.posts):
|
def serialize_id_post(
|
||||||
if post.post_id == current_item.post_id:
|
post_id: Optional[int]
|
||||||
if previous_item != None:
|
) -> rest.Response:
|
||||||
prev_post_id = previous_item.post_id
|
return serialize_safe_post(try_get_post_by_id(post_id)) if post_id else None
|
||||||
if next_item != None:
|
|
||||||
next_post_id = next_item.post_id
|
|
||||||
break
|
|
||||||
|
|
||||||
resp_entry = PoolPostsNearby(
|
|
||||||
pool=pool,
|
|
||||||
first_post=first_post_id,
|
|
||||||
last_post=last_post_id,
|
|
||||||
prev_post=prev_post_id,
|
|
||||||
next_post=next_post_id,
|
|
||||||
)
|
|
||||||
response.append(resp_entry)
|
|
||||||
return response
|
|
||||||
|
|
||||||
def serialize_pool_posts_nearby(
|
def get_pool_posts_nearby(
|
||||||
nearby: List[PoolPostsNearby]
|
post: model.Post, pool: model.Pool
|
||||||
) -> Optional[rest.Response]:
|
) -> rest.Response:
|
||||||
return [
|
prev_post_id = None
|
||||||
{
|
next_post_id = None
|
||||||
"pool": pools.serialize_micro_pool(entry.pool),
|
first_post_id = pool.posts[0].post_id,
|
||||||
"firstPost": {"id": getattr(try_get_post_by_id(entry.first_post), "post_id", None)} if entry.first_post else None,
|
last_post_id = pool.posts[-1].post_id,
|
||||||
"lastPost": {"id": getattr(try_get_post_by_id(entry.last_post), "post_id", None)} if entry.last_post else None,
|
|
||||||
"previousPost": {"id": getattr(try_get_post_by_id(entry.prev_post), "post_id", None)} if entry.prev_post else None,
|
for previous_item, current_item, next_item in _get_nearby_iter(pool.posts):
|
||||||
"nextPost": {"id": getattr(try_get_post_by_id(entry.next_post), "post_id", None)} if entry.next_post else None,
|
if post.post_id == current_item.post_id:
|
||||||
} for entry in nearby
|
if previous_item != None:
|
||||||
]
|
prev_post_id = previous_item.post_id
|
||||||
|
if next_item != None:
|
||||||
|
next_post_id = next_item.post_id
|
||||||
|
break
|
||||||
|
|
||||||
|
return {
|
||||||
|
"firstPost": serialize_id_post(first_post_id),
|
||||||
|
"lastPost": serialize_id_post(last_post_id),
|
||||||
|
"previousPost": serialize_id_post(prev_post_id),
|
||||||
|
"nextPost": serialize_id_post(next_post_id),
|
||||||
|
}
|
||||||
|
@ -127,7 +127,8 @@ def test_trying_to_retrieve_single_without_privileges(
|
|||||||
{"post_id": 999},
|
{"post_id": 999},
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
|
||||||
|
def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_post_factory):
|
||||||
p1 = post_factory(id=1)
|
p1 = post_factory(id=1)
|
||||||
p2 = post_factory(id=2)
|
p2 = post_factory(id=2)
|
||||||
p3 = post_factory(id=3)
|
p3 = post_factory(id=3)
|
||||||
@ -139,42 +140,11 @@ def test_get_pool_post_around(user_factory, post_factory, pool_factory, pool_pos
|
|||||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
||||||
db.session.add_all(pool_posts)
|
db.session.add_all(pool_posts)
|
||||||
|
|
||||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 2})
|
result = posts.get_pool_posts_nearby(p1, pool)
|
||||||
assert result[0]["previousPost"]["id"] == 1 and result[0]["nextPost"]["id"] == 3
|
assert result["previousPost"] == None and result["nextPost"]["id"] == 2
|
||||||
|
|
||||||
def test_get_pool_post_around_start(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
result = posts.get_pool_posts_nearby(p2, pool)
|
||||||
p1 = post_factory(id=1)
|
assert result["previousPost"]["id"] == 1 and result["nextPost"]["id"] == 3
|
||||||
p2 = post_factory(id=2)
|
|
||||||
p3 = post_factory(id=3)
|
|
||||||
db.session.add_all([p1, p2, p3])
|
|
||||||
|
|
||||||
pool = pool_factory(id=1)
|
result = posts.get_pool_posts_nearby(p3, pool)
|
||||||
db.session.add(pool)
|
assert result["previousPost"]["id"] == 2 and result["nextPost"] == None
|
||||||
|
|
||||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
|
||||||
db.session.add_all(pool_posts)
|
|
||||||
|
|
||||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 1})
|
|
||||||
assert result[0]["previousPost"] == None and result[0]["nextPost"]["id"] == 2
|
|
||||||
|
|
||||||
def test_get_pool_post_around_end(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
|
||||||
p1 = post_factory(id=1)
|
|
||||||
p2 = post_factory(id=2)
|
|
||||||
p3 = post_factory(id=3)
|
|
||||||
db.session.add_all([p1, p2, p3])
|
|
||||||
|
|
||||||
pool = pool_factory(id=1)
|
|
||||||
db.session.add(pool)
|
|
||||||
|
|
||||||
pool_posts = [pool_post_factory(pool=pool, post=p1), pool_post_factory(pool=pool, post=p2), pool_post_factory(pool=pool, post=p3)]
|
|
||||||
db.session.add_all(pool_posts)
|
|
||||||
|
|
||||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 3})
|
|
||||||
assert result[0]["previousPost"]["id"] == 2 and result[0]["nextPost"] == None
|
|
||||||
|
|
||||||
def test_get_pool_post_around_no_pool(user_factory, post_factory, pool_factory, pool_post_factory, context_factory):
|
|
||||||
p1 = post_factory(id=1)
|
|
||||||
db.session.add(p1)
|
|
||||||
|
|
||||||
result = api.post_api.get_pools_around(context_factory(user=user_factory(rank=model.User.RANK_REGULAR)), {"post_id": 1})
|
|
||||||
assert result == []
|
|
||||||
|
@ -105,7 +105,14 @@ def test_serialize_post(
|
|||||||
pool_category_factory,
|
pool_category_factory,
|
||||||
config_injector,
|
config_injector,
|
||||||
):
|
):
|
||||||
config_injector({"data_url": "http://example.com/", "secret": "test"})
|
config_injector({
|
||||||
|
"privileges": {
|
||||||
|
"pools:list": model.User.RANK_REGULAR,
|
||||||
|
"pools:view": model.User.RANK_REGULAR,
|
||||||
|
},
|
||||||
|
"data_url": "http://example.com/",
|
||||||
|
"secret": "test"
|
||||||
|
})
|
||||||
with patch("szurubooru.func.comments.serialize_comment"), patch(
|
with patch("szurubooru.func.comments.serialize_comment"), patch(
|
||||||
"szurubooru.func.users.serialize_micro_user"
|
"szurubooru.func.users.serialize_micro_user"
|
||||||
), patch("szurubooru.func.posts.files.has"):
|
), patch("szurubooru.func.posts.files.has"):
|
||||||
@ -249,6 +256,10 @@ def test_serialize_post(
|
|||||||
"description": "desc",
|
"description": "desc",
|
||||||
"category": "test-cat1",
|
"category": "test-cat1",
|
||||||
"postCount": 1,
|
"postCount": 1,
|
||||||
|
"firstPost": {"id": 1},
|
||||||
|
"lastPost": {"id": 1},
|
||||||
|
"previousPost": None,
|
||||||
|
"nextPost": None,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
@ -256,6 +267,10 @@ def test_serialize_post(
|
|||||||
"description": "desc2",
|
"description": "desc2",
|
||||||
"category": "test-cat2",
|
"category": "test-cat2",
|
||||||
"postCount": 1,
|
"postCount": 1,
|
||||||
|
"firstPost": {"id": 1},
|
||||||
|
"lastPost": {"id": 1},
|
||||||
|
"previousPost": None,
|
||||||
|
"nextPost": None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"user": "post author",
|
"user": "post author",
|
||||||
|
@ -866,43 +866,43 @@ def test_tumbleweed(
|
|||||||
verify_unpaged("-special:tumbleweed", [1, 2, 3])
|
verify_unpaged("-special:tumbleweed", [1, 2, 3])
|
||||||
|
|
||||||
|
|
||||||
def test_sort_pool(
|
def test_sort_pool(
|
||||||
post_factory, pool_factory, pool_category_factory, verify_unpaged
|
post_factory, pool_factory, pool_category_factory, verify_unpaged
|
||||||
):
|
):
|
||||||
post1 = post_factory(id=1)
|
post1 = post_factory(id=1)
|
||||||
post2 = post_factory(id=2)
|
post2 = post_factory(id=2)
|
||||||
post3 = post_factory(id=3)
|
post3 = post_factory(id=3)
|
||||||
post4 = post_factory(id=4)
|
post4 = post_factory(id=4)
|
||||||
pool1 = pool_factory(
|
pool1 = pool_factory(
|
||||||
id=1,
|
id=1,
|
||||||
names=["pool1"],
|
names=["pool1"],
|
||||||
description="desc",
|
description="desc",
|
||||||
category=pool_category_factory("test-cat1"),
|
category=pool_category_factory("test-cat1"),
|
||||||
)
|
)
|
||||||
pool1.posts = [post1, post4, post3]
|
pool1.posts = [post1, post4, post3]
|
||||||
pool2 = pool_factory(
|
pool2 = pool_factory(
|
||||||
id=2,
|
id=2,
|
||||||
names=["pool2"],
|
names=["pool2"],
|
||||||
description="desc",
|
description="desc",
|
||||||
category=pool_category_factory("test-cat2"),
|
category=pool_category_factory("test-cat2"),
|
||||||
)
|
)
|
||||||
pool2.posts = [post3, post4, post2]
|
pool2.posts = [post3, post4, post2]
|
||||||
db.session.add_all(
|
db.session.add_all(
|
||||||
[
|
[
|
||||||
post1,
|
post1,
|
||||||
post2,
|
post2,
|
||||||
post3,
|
post3,
|
||||||
post4,
|
post4,
|
||||||
pool1,
|
pool1,
|
||||||
pool2
|
pool2
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
verify_unpaged("pool:1 sort:pool", [1, 4, 3])
|
verify_unpaged("pool:1 sort:pool", [1, 4, 3])
|
||||||
verify_unpaged("pool:2 sort:pool", [3, 4, 2])
|
verify_unpaged("pool:2 sort:pool", [3, 4, 2])
|
||||||
verify_unpaged("pool:1 pool:2 sort:pool", [4, 3])
|
verify_unpaged("pool:1 pool:2 sort:pool", [4, 3])
|
||||||
verify_unpaged("pool:2 pool:1 sort:pool", [3, 4])
|
verify_unpaged("pool:2 pool:1 sort:pool", [3, 4])
|
||||||
verify_unpaged("sort:pool", [1, 2, 3, 4])
|
verify_unpaged("sort:pool", [1, 2, 3, 4])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Reference in New Issue
Block a user