From 4d1f745e38b057f9685f600de1f65aecf69b4449 Mon Sep 17 00:00:00 2001 From: rr- Date: Sat, 28 May 2016 11:22:25 +0200 Subject: [PATCH] server/notes: fix note serialization --- server/szurubooru/func/posts.py | 6 ++++-- server/szurubooru/func/snapshots.py | 2 +- server/szurubooru/tests/func/test_posts.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index f7015f4..04622fd 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -57,7 +57,7 @@ def get_post_thumbnail_backup_path(post): def serialize_note(note): return { - 'polygon': note.path, + 'polygon': note.polygon, 'text': note.text, } @@ -81,7 +81,9 @@ def serialize_post(post, authenticated_user): 'flags': post.flags, 'tags': [tag.first_name for tag in post.tags], 'relations': [rel.post_id for rel in post.relations], - 'notes': sorted(serialize_note(note) for note in post.notes), + 'notes': sorted( + [ serialize_note(note) for note in post.notes], + key=lambda x: x['polygon']), 'user': users.serialize_user(post.user, authenticated_user), 'score': post.score, 'featureCount': post.feature_count, diff --git a/server/szurubooru/func/snapshots.py b/server/szurubooru/func/snapshots.py index 7fceeea..f899041 100644 --- a/server/szurubooru/func/snapshots.py +++ b/server/szurubooru/func/snapshots.py @@ -19,7 +19,7 @@ def get_post_snapshot(post): 'notes': sorted([{ 'polygon': note.polygon, 'text': note.text, - } for note in post.notes]), + } for note in post.notes], key=lambda x: x['polygon']), 'flags': post.flags, 'featured': post.is_featured, } diff --git a/server/szurubooru/tests/func/test_posts.py b/server/szurubooru/tests/func/test_posts.py index e032586..5d131b6 100644 --- a/server/szurubooru/tests/func/test_posts.py +++ b/server/szurubooru/tests/func/test_posts.py @@ -54,7 +54,7 @@ def test_get_post_thumbnail_backup_path(input_mime_type): def test_serialize_note(): note = db.PostNote() - note.path = [[0, 1], [1, 1], [1, 0], [0, 0]] + note.polygon = [[0, 1], [1, 1], [1, 0], [0, 0]] note.text = '...' assert posts.serialize_note(note) == { 'polygon': [[0, 1], [1, 1], [1, 0], [0, 0]],