diff options
| author | rr- | 2016-05-29 12:38:47 +0200 |
|---|---|---|
| committer | rr- | 2016-05-29 12:41:22 +0200 |
| commit | abef6e5c35bcabab3586310ee7333c0c891d119b (patch) | |
| tree | 514a4d3bfa1c58577679b8d18546ee6c94db5948 /server | |
| parent | 9b0c2012a7798510f1350310c9de2449f16a3ef1 (diff) | |
server/info: return who featured the post and when
Diffstat (limited to 'server')
| -rw-r--r-- | server/szurubooru/api/info_api.py | 10 | ||||
| -rw-r--r-- | server/szurubooru/func/posts.py | 7 | ||||
| -rw-r--r-- | server/szurubooru/tests/api/test_info.py | 6 |
3 files changed, 18 insertions, 5 deletions
diff --git a/server/szurubooru/api/info_api.py b/server/szurubooru/api/info_api.py index 29043b7..0dad5f8 100644 --- a/server/szurubooru/api/info_api.py +++ b/server/szurubooru/api/info_api.py @@ -2,7 +2,7 @@ import datetime import os from szurubooru import config from szurubooru.api.base_api import BaseApi -from szurubooru.func import posts +from szurubooru.func import posts, users class InfoApi(BaseApi): def __init__(self): @@ -11,11 +11,15 @@ class InfoApi(BaseApi): self._cache_result = None def get(self, ctx): - featured_post = posts.try_get_featured_post() + post_feature = posts.try_get_current_post_feature() return { 'postCount': posts.get_post_count(), 'diskUsage': self._get_disk_usage(), - 'featuredPost': posts.serialize_post(featured_post, ctx.user), + 'featuredPost': posts.serialize_post(post_feature.post, ctx.user) \ + if post_feature else None, + 'featuringTime': post_feature.time if post_feature else None, + 'featuringUser': users.serialize_user(post_feature.user, ctx.user) \ + if post_feature else None, } def _get_disk_usage(self): diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 04622fd..51d9952 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -126,11 +126,14 @@ def get_post_by_id(post_id): raise PostNotFoundError('Post %r not found.' % post_id) return post -def try_get_featured_post(): - post_feature = db.session \ +def try_get_current_post_feature(): + return db.session \ .query(db.PostFeature) \ .order_by(db.PostFeature.time.desc()) \ .first() + +def try_get_featured_post(): + post_feature = try_get_current_post_feature() return post_feature.post if post_feature else None def create_post(content, tag_names, user): diff --git a/server/szurubooru/tests/api/test_info.py b/server/szurubooru/tests/api/test_info.py index 561f212..3a9ce4b 100644 --- a/server/szurubooru/tests/api/test_info.py +++ b/server/szurubooru/tests/api/test_info.py @@ -12,6 +12,8 @@ def test_info_api( 'postCount': 2, 'diskUsage': 3, 'featuredPost': None, + 'featuringTime': None, + 'featuringUser': None, } directory.join('test2.txt').write('abc') with fake_datetime('13:59'): @@ -19,10 +21,14 @@ def test_info_api( 'postCount': 2, 'diskUsage': 3, # still 3 - it's cached 'featuredPost': None, + 'featuringTime': None, + 'featuringUser': None, } with fake_datetime('14:01'): assert info_api.get(context_factory()) == { 'postCount': 2, 'diskUsage': 6, # cache expired 'featuredPost': None, + 'featuringTime': None, + 'featuringUser': None, } |