From 590d0757351521ac30b15ae5e2a4d12d594ac185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 25 Oct 2016 12:22:44 +0200 Subject: [PATCH] New schema for attachments, using propertyschema/valueschema. --- pillar/api/node_types/__init__.py | 20 ++++++++++++++++++++ pillar/api/node_types/asset.py | 23 ++--------------------- pillar/api/node_types/page.py | 23 ++--------------------- pillar/api/node_types/post.py | 23 ++--------------------- 4 files changed, 26 insertions(+), 63 deletions(-) diff --git a/pillar/api/node_types/__init__.py b/pillar/api/node_types/__init__.py index 86a05647..56ab6381 100644 --- a/pillar/api/node_types/__init__.py +++ b/pillar/api/node_types/__init__.py @@ -6,3 +6,23 @@ _file_embedded_schema = { 'embeddable': True } } + +_attachments_embedded_schema = { + 'type': 'dict', + # TODO: will be renamed to 'keyschema' in Cerberus 1.0 + 'propertyschema': { + 'type': 'string', + 'regex': '^[a-zA-Z0-9_ ]+$', + }, + 'valueschema': { + 'type': 'dict', + 'schema': { + 'oid': 'objectid', + 'collection': { + 'type': 'string', + 'allowed': ['files'], + 'default': 'files', + }, + }, + }, +} diff --git a/pillar/api/node_types/asset.py b/pillar/api/node_types/asset.py index 59dec10d..e53ce807 100644 --- a/pillar/api/node_types/asset.py +++ b/pillar/api/node_types/asset.py @@ -1,4 +1,4 @@ -from pillar.api.node_types import _file_embedded_schema +from pillar.api.node_types import _file_embedded_schema, _attachments_embedded_schema node_type_asset = { 'name': 'asset', @@ -27,26 +27,7 @@ node_type_asset = { # We point to the original file (and use it to extract any relevant # variation useful for our scope). 'file': _file_embedded_schema, - 'attachments': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'field': {'type': 'string'}, - 'files': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'file': _file_embedded_schema, - 'slug': {'type': 'string', 'minlength': 1}, - 'size': {'type': 'string'} - } - } - } - } - } - }, + 'attachments': _attachments_embedded_schema, # Tags for search 'tags': { 'type': 'list', diff --git a/pillar/api/node_types/page.py b/pillar/api/node_types/page.py index 9e16845b..8f6ef27a 100644 --- a/pillar/api/node_types/page.py +++ b/pillar/api/node_types/page.py @@ -1,4 +1,4 @@ -from pillar.api.node_types import _file_embedded_schema +from pillar.api.node_types import _attachments_embedded_schema node_type_page = { 'name': 'page', @@ -22,26 +22,7 @@ node_type_page = { 'url': { 'type': 'string' }, - 'attachments': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'field': {'type': 'string'}, - 'files': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'file': _file_embedded_schema, - 'slug': {'type': 'string', 'minlength': 1}, - 'size': {'type': 'string'} - } - } - } - } - } - } + 'attachments': _attachments_embedded_schema, }, 'form_schema': { 'attachments': {'visible': False}, diff --git a/pillar/api/node_types/post.py b/pillar/api/node_types/post.py index a554589d..a3e07126 100644 --- a/pillar/api/node_types/post.py +++ b/pillar/api/node_types/post.py @@ -1,4 +1,4 @@ -from pillar.api.node_types import _file_embedded_schema +from pillar.api.node_types import _attachments_embedded_schema node_type_post = { 'name': 'post', @@ -26,26 +26,7 @@ node_type_post = { 'url': { 'type': 'string' }, - 'attachments': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'field': {'type': 'string'}, - 'files': { - 'type': 'list', - 'schema': { - 'type': 'dict', - 'schema': { - 'file': _file_embedded_schema, - 'slug': {'type': 'string', 'minlength': 1}, - 'size': {'type': 'string'} - } - } - } - } - } - } + 'attachments': _attachments_embedded_schema, }, 'form_schema': { 'attachments': {'visible': False},