From 6d29f3fc6ac6f5c5e0b7d3cecd8fa879ca50e73f Mon Sep 17 00:00:00 2001 From: Ekaterina Fedorova Date: Thu, 10 Apr 2014 13:45:09 +0400 Subject: [PATCH] Use plural for class_definition Add cascade deletetion for class_definitions Change-Id: I21a7674b17d2be727d86db64c114c024f32ade1d --- muranoapi/api/v1/__init__.py | 2 +- muranoapi/db/catalog/api.py | 4 ++-- muranoapi/db/models.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/muranoapi/api/v1/__init__.py b/muranoapi/api/v1/__init__.py index bbe05d16..b9cd4ccb 100644 --- a/muranoapi/api/v1/__init__.py +++ b/muranoapi/api/v1/__init__.py @@ -28,7 +28,7 @@ PKG_PARAMS_MAP = {'display_name': 'name', 'package_type': 'type', 'description': 'description', 'author': 'author', - 'classes': 'class_definition'} + 'classes': 'class_definitions'} def get_draft(environment_id=None, session_id=None): diff --git a/muranoapi/db/catalog/api.py b/muranoapi/db/catalog/api.py index f65f9900..d580a3fd 100644 --- a/muranoapi/db/catalog/api.py +++ b/muranoapi/db/catalog/api.py @@ -280,7 +280,7 @@ def package_search(filters, context): if 'search' in filters.keys(): fk_fields = {'categories': 'Category', 'tags': 'Tag', - 'class_definition': 'Class'} + 'class_definitions': 'Class'} conditions = [] for attr in dir(pkg): @@ -357,7 +357,7 @@ def package_upload(values, tenant_id): composite_attr_to_func = {'categories': _get_categories, 'tags': _get_tags, - 'class_definition': _get_class_definitions} + 'class_definitions': _get_class_definitions} with session.begin(): for attr, func in composite_attr_to_func.iteritems(): if values.get(attr): diff --git a/muranoapi/db/models.py b/muranoapi/db/models.py index 3e037bbf..3cd4bc18 100644 --- a/muranoapi/db/models.py +++ b/muranoapi/db/models.py @@ -281,7 +281,8 @@ class Package(BASE, ModificationsTrackedObject): secondary=package_to_category, cascade='save-update, merge', lazy='joined') - class_definition = sa_orm.relationship("Class", lazy='joined') + class_definitions = sa_orm.relationship( + "Class", cascade='save-update, merge, delete', lazy='joined') def to_dict(self): d = self.__dict__.copy() @@ -289,7 +290,7 @@ class Package(BASE, ModificationsTrackedObject): 'archive', 'logo', 'ui_definition'] - nested_objects = ['categories', 'tags', 'class_definition'] + nested_objects = ['categories', 'tags', 'class_definitions'] for key in not_serializable: if key in d.keys(): del d[key]