From ce6df542cc17c9583301d979d3cb1d7b395b3688 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Fri, 11 May 2018 01:32:39 +0200 Subject: [PATCH] Add ratings_embedded_schema to node_types Ratings, like attachments, are a common feature in node_types. By adding this schema definition, we reduce code duplication. No functional changes are introduced introduced in this commit. --- pillar/api/node_types/__init__.py | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pillar/api/node_types/__init__.py b/pillar/api/node_types/__init__.py index 53f4e1cf..6ea1fac5 100644 --- a/pillar/api/node_types/__init__.py +++ b/pillar/api/node_types/__init__.py @@ -40,6 +40,51 @@ attachments_embedded_schema = { }, } +# TODO (fsiddi) reference this schema in all node_types that allow ratings +ratings_embedded_schema = { + 'type': 'dict', + # Total count of positive ratings (updated at every rating action) + 'schema': { + 'positive': { + 'type': 'integer', + }, + # Total count of negative ratings (updated at every rating action) + 'negative': { + 'type': 'integer', + }, + # Collection of ratings, keyed by user + 'ratings': { + 'type': 'list', + 'schema': { + 'type': 'dict', + 'schema': { + 'user': { + 'type': 'objectid', + 'data_relation': { + 'resource': 'users', + 'field': '_id', + 'embeddable': False + } + }, + 'is_positive': { + 'type': 'boolean' + }, + # Weight of the rating based on user rep and the context. + # Currently we have the following weights: + # - 1 auto null + # - 2 manual null + # - 3 auto valid + # - 4 manual valid + 'weight': { + 'type': 'integer' + } + } + } + }, + 'hot': {'type': 'float'}, + }, +} + # Import after defining the common embedded schemas, to prevent dependency cycles. from pillar.api.node_types.asset import node_type_asset from pillar.api.node_types.blog import node_type_blog