server/posts: add hasCustomThumbnail to post info

This commit is contained in:
rr- 2016-05-01 20:15:28 +02:00
parent ce095816d9
commit 067e438b8c
12 changed files with 54 additions and 30 deletions

44
API.md
View file

@ -1334,27 +1334,28 @@ One file together with its metadata posted to the site.
```json5
{
"id": <id>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"safety": <safety>,
"source": <source>,
"type": <type>,
"checksum": <checksum>,
"canvasWidth": <canvas-width>,
"canvasHeight": <canvas-height>,
"contentUrl": <content-url>,
"thumbnailUrl": <thumbnail-url>,
"flags": <flags>,
"tags": <tags>,
"relations": <relations>,
"notes": <notes>,
"user": <user>,
"score": <score>,
"ownScore": <own-score>,
"featureCount": <feature-count>,
"lastFeatureTime": <last-feature-time>,
"favoritedBy": <favorited-by>
"id": <id>,
"creationTime": <creation-time>,
"lastEditTime": <last-edit-time>,
"safety": <safety>,
"source": <source>,
"type": <type>,
"checksum": <checksum>,
"canvasWidth": <canvas-width>,
"canvasHeight": <canvas-height>,
"contentUrl": <content-url>,
"thumbnailUrl": <thumbnail-url>,
"flags": <flags>,
"tags": <tags>,
"relations": <relations>,
"notes": <notes>,
"user": <user>,
"score": <score>,
"ownScore": <own-score>,
"featureCount": <feature-count>,
"lastFeatureTime": <last-feature-time>,
"favoritedBy": <favorited-by>,
"hasCustomThumbnail": <has-custom-thumbnail>
}
```
@ -1403,6 +1404,7 @@ One file together with its metadata posted to the site.
- `<last-feature-time>`: the last time the post was featured, formatted as per
RFC 3339.
- `<favorited-by>`: list of users, serialized as [user resources](#user).
- `<has-custom-thumbnail>`: whether the post uses custom thumbnail.
## Detailed post
**Description**

View file

@ -9,6 +9,9 @@ def delete(path):
if os.path.exists(full_path):
os.unlink(full_path)
def has(path):
return os.path.exists(_get_full_path(path))
def get(path):
full_path = _get_full_path(path)
if not os.path.exists(full_path):

View file

@ -85,6 +85,7 @@ def serialize_post(post, authenticated_user):
'lastFeatureTime': post.last_feature_time,
'favoritedBy': [users.serialize_user(rel.user, authenticated_user) \
for rel in post.favorited_by],
'hasCustomThumbnail': files.has(get_post_thumbnail_backup_path(post)),
}
if authenticated_user:

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, posts
@pytest.fixture
def test_ctx(config_injector, context_factory, post_factory, user_factory):
def test_ctx(
tmpdir, config_injector, context_factory, post_factory, user_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user'],
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, comments, scores
@pytest.fixture
def test_ctx(config_injector, context_factory, user_factory, comment_factory):
def test_ctx(
tmpdir, config_injector, context_factory, user_factory, comment_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user', 'mod'],
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, comments
@pytest.fixture
def test_ctx(context_factory, config_injector, user_factory, comment_factory):
def test_ctx(
tmpdir, context_factory, config_injector, user_factory, comment_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user', 'mod', 'admin'],
'rank_names': {'regular_user': 'Peasant'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, comments
@pytest.fixture
def test_ctx(config_injector, context_factory, user_factory, comment_factory):
def test_ctx(
tmpdir, config_injector, context_factory, user_factory, comment_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user', 'mod'],
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord', 'mod': 'King'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, posts
@pytest.fixture
def test_ctx(config_injector, context_factory, user_factory, post_factory):
def test_ctx(
tmpdir, config_injector, context_factory, user_factory, post_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user', 'mod'],
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, posts
@pytest.fixture
def test_ctx(context_factory, config_injector, user_factory, post_factory):
def test_ctx(
tmpdir, context_factory, config_injector, user_factory, post_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'privileges': {
'posts:feature': 'regular_user',

View file

@ -3,8 +3,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, posts, scores
@pytest.fixture
def test_ctx(config_injector, context_factory, user_factory, post_factory):
def test_ctx(
tmpdir, config_injector, context_factory, user_factory, post_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'ranks': ['anonymous', 'regular_user'],
'rank_names': {'anonymous': 'Peasant', 'regular_user': 'Lord'},

View file

@ -4,8 +4,10 @@ from szurubooru import api, db, errors
from szurubooru.func import util, posts
@pytest.fixture
def test_ctx(context_factory, config_injector, user_factory, post_factory):
def test_ctx(
tmpdir, context_factory, config_injector, user_factory, post_factory):
config_injector({
'data_dir': str(tmpdir),
'data_url': 'http://example.com',
'privileges': {
'posts:list': 'regular_user',

View file

@ -65,7 +65,8 @@ def test_serialize_empty_post():
assert posts.serialize_post(None, None) is None
def test_serialize_post(post_factory, user_factory, tag_factory):
with unittest.mock.patch('szurubooru.func.users.serialize_user'):
with unittest.mock.patch('szurubooru.func.users.serialize_user'), \
unittest.mock.patch('szurubooru.func.posts.files.has', return_value=True):
users.serialize_user.side_effect = lambda user, auth_user: user.name
auth_user = user_factory(name='auth user')
@ -140,6 +141,7 @@ def test_serialize_post(post_factory, user_factory, tag_factory):
'featureCount': 1,
'lastFeatureTime': datetime.datetime(1999, 1, 1),
'favoritedBy': ['fav1'],
'hasCustomThumbnail': True,
}
def test_serialize_post_with_details(post_factory, comment_factory, user_factory):