From ba3678dec13a4bb309a935f2a552606a9dfdb9dc Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 10 May 2016 11:57:05 +0200 Subject: [PATCH] server/posts: implement FLAG_MAP --- server/szurubooru/db/post.py | 1 - server/szurubooru/func/posts.py | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/szurubooru/db/post.py b/server/szurubooru/db/post.py index cf98397b..2fdcb4e2 100644 --- a/server/szurubooru/db/post.py +++ b/server/szurubooru/db/post.py @@ -91,7 +91,6 @@ class Post(Base): TYPE_FLASH = 'flash' FLAG_LOOP = 'loop' - ALL_FLAGS = [FLAG_LOOP] # basic meta post_id = Column('id', Integer, primary_key=True) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 6cf1d8c0..7dce0e9c 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -30,7 +30,9 @@ TYPE_MAP = { db.Post.TYPE_VIDEO: 'video', db.Post.TYPE_FLASH: 'flash', } -# TODO: FLAG_MAP +FLAG_MAP = { + db.Post.FLAG_LOOP: 'loop', +} def get_post_content_url(post): return '%s/posts/%d.%s' % ( @@ -150,7 +152,7 @@ def update_post_safety(post, safety): safety = util.flip(SAFETY_MAP).get(safety, None) if not safety: raise InvalidPostSafetyError( - 'Safety can be either of %r.', list(SAFETY_MAP.values())) + 'Safety can be either of %r.' % list(SAFETY_MAP.values())) post.safety = safety def update_post_source(post, source): @@ -261,11 +263,14 @@ def update_post_notes(post, notes): db.PostNote(polygon=note['polygon'], text=note['text'])) def update_post_flags(post, flags): + target_flags = [] for flag in flags: - if flag not in db.Post.ALL_FLAGS: + flag = util.flip(FLAG_MAP).get(flag, None) + if not flag: raise InvalidPostFlagError( - 'Flag must be one of %r.' % db.Post.ALL_FLAGS) - post.flags = flags + 'Flag must be one of %r.' % list(FLAG_MAP.values())) + target_flags.append(flag) + post.flags = target_flags def feature_post(post, user): post_feature = db.PostFeature()