From c55fb2ef4190640e3c79e0c7a9160738e08de6c4 Mon Sep 17 00:00:00 2001 From: rr- Date: Fri, 29 Apr 2016 11:47:18 +0200 Subject: [PATCH] server/tags: output tag usage count --- API.md | 4 +++- server/szurubooru/func/tags.py | 1 + server/szurubooru/tests/api/test_tag_creating.py | 1 + server/szurubooru/tests/api/test_tag_merging.py | 1 + server/szurubooru/tests/api/test_tag_retrieving.py | 1 + server/szurubooru/tests/api/test_tag_updating.py | 1 + 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index 3da187e..419527c 100644 --- a/API.md +++ b/API.md @@ -1273,7 +1273,8 @@ A single tag. Tags are used to let users search for posts. "implications": , "suggestions": , "creationTime": , - "lastEditTime": + "lastEditTime": , + "usages": } ``` @@ -1288,6 +1289,7 @@ A single tag. Tags are used to let users search for posts. the user by the web client on usage. - ``: time the tag was created, formatted as per RFC 3339. - ``: time the tag was edited, formatted as per RFC 3339. +- ``: the number of posts the tag was used in. ## Detailed tag **Description** diff --git a/server/szurubooru/func/tags.py b/server/szurubooru/func/tags.py index 6dc01c2..e327e91 100644 --- a/server/szurubooru/func/tags.py +++ b/server/szurubooru/func/tags.py @@ -36,6 +36,7 @@ def serialize_tag(tag): relation.names[0].name for relation in tag.implications], 'creationTime': tag.creation_time, 'lastEditTime': tag.last_edit_time, + 'usages': tag.post_count, } def serialize_tag_with_details(tag): diff --git a/server/szurubooru/tests/api/test_tag_creating.py b/server/szurubooru/tests/api/test_tag_creating.py index 41b8463..24e79ab 100644 --- a/server/szurubooru/tests/api/test_tag_creating.py +++ b/server/szurubooru/tests/api/test_tag_creating.py @@ -46,6 +46,7 @@ def test_creating_simple_tags(test_ctx, fake_datetime): 'implications': [], 'creationTime': datetime.datetime(1997, 12, 1), 'lastEditTime': None, + 'usages': 0, } assert len(result['snapshots']) == 1 tag = tags.get_tag_by_name('tag1') diff --git a/server/szurubooru/tests/api/test_tag_merging.py b/server/szurubooru/tests/api/test_tag_merging.py index 2d7a2b6..92eeab8 100644 --- a/server/szurubooru/tests/api/test_tag_merging.py +++ b/server/szurubooru/tests/api/test_tag_merging.py @@ -41,6 +41,7 @@ def test_merging_without_usages(test_ctx, fake_datetime): 'implications': [], 'creationTime': datetime.datetime(1996, 1, 1), 'lastEditTime': None, + 'usages': 0, } assert 'snapshots' in result assert tags.try_get_tag_by_name('source') is None diff --git a/server/szurubooru/tests/api/test_tag_retrieving.py b/server/szurubooru/tests/api/test_tag_retrieving.py index e7979ef..f95a407 100644 --- a/server/szurubooru/tests/api/test_tag_retrieving.py +++ b/server/szurubooru/tests/api/test_tag_retrieving.py @@ -57,6 +57,7 @@ def test_retrieving_single(test_ctx): 'lastEditTime': None, 'suggestions': [], 'implications': [], + 'usages': 0, }, 'snapshots': [], } diff --git a/server/szurubooru/tests/api/test_tag_updating.py b/server/szurubooru/tests/api/test_tag_updating.py index 0dfe570..2646cca 100644 --- a/server/szurubooru/tests/api/test_tag_updating.py +++ b/server/szurubooru/tests/api/test_tag_updating.py @@ -53,6 +53,7 @@ def test_simple_updating(test_ctx, fake_datetime): 'implications': [], 'creationTime': datetime.datetime(1996, 1, 1), 'lastEditTime': datetime.datetime(1997, 12, 1), + 'usages': 0, } assert len(result['snapshots']) == 1 assert tags.try_get_tag_by_name('tag1') is None