diff options
| author | rr- | 2016-04-24 16:34:06 +0200 |
|---|---|---|
| committer | rr- | 2016-04-24 16:37:11 +0200 |
| commit | 52f4018bee838868943f87528e188a4e35302799 (patch) | |
| tree | 48ff092298139aeacc3526573346eda1c222f161 /server/szurubooru/func/util.py | |
| parent | 8fb536c8f0aa4e4a398f1d1db05151a3dd897c6f (diff) | |
server/comments+posts: add rating
Diffstat (limited to 'server/szurubooru/func/util.py')
| -rw-r--r-- | server/szurubooru/func/util.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/server/szurubooru/func/util.py b/server/szurubooru/func/util.py index 6c14d96..83d3931 100644 --- a/server/szurubooru/func/util.py +++ b/server/szurubooru/func/util.py @@ -1,7 +1,31 @@ import datetime import re +from sqlalchemy.inspection import inspect from szurubooru.errors import ValidationError +def get_resource_info(entity): + serializers = { + 'tag': lambda tag: tag.first_name, + 'tag_category': lambda category: category.name, + 'comment': lambda comment: comment.comment_id, + 'post': lambda post: post.post_id, + } + + resource_type = entity.__table__.name + assert resource_type in serializers + + primary_key = inspect(entity).identity + assert primary_key is not None + assert len(primary_key) == 1 + + resource_repr = serializers[resource_type](entity) + assert resource_repr + + resource_id = primary_key[0] + assert resource_id + + return (resource_type, resource_id, resource_repr) + def is_valid_email(email): ''' Return whether given email address is valid or empty. ''' return not email or re.match(r'^[^@]*@[^@]*\.[^@]*$', email) |