ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: more refactory
Date Mon, 27 Mar 2017 12:32:55 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-132-Models-cascading-deletion-raises-constraint-errors bc8d5535f -> 3220d4701


more refactory


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3220d470
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3220d470
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3220d470

Branch: refs/heads/ARIA-132-Models-cascading-deletion-raises-constraint-errors
Commit: 3220d4701c6154088f638908fa5450794714c5b0
Parents: bc8d553
Author: max-orlov <maxim@gigaspaces.com>
Authored: Mon Mar 27 15:32:51 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Mon Mar 27 15:32:51 2017 +0300

----------------------------------------------------------------------
 aria/modeling/relationship.py     | 39 ++++++++++++++++++----------------
 aria/modeling/service_changes.py  |  5 -----
 aria/modeling/service_instance.py | 18 ++++++++--------
 aria/modeling/service_template.py | 12 +++++------
 4 files changed, 36 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3220d470/aria/modeling/relationship.py
----------------------------------------------------------------------
diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py
index 459c355..4c9232c 100644
--- a/aria/modeling/relationship.py
+++ b/aria/modeling/relationship.py
@@ -78,12 +78,14 @@ def one_to_one_self(model_class, fk):
         model_class=model_class.__name__,
         column=fk
     )
-
-    return relationship(
-        _get_class_for_table(model_class, model_class.__tablename__).__name__,
-        primaryjoin=primaryjoin,
-        remote_side=remote_side,
-        post_update=True,
+    return _relationship(
+        model_class,
+        model_class.__tablename__,
+        relationship_kwargs={
+            'primaryjoin': primaryjoin,
+            'remote_side': remote_side,
+            'post_update': True
+        }
     )
 
 
@@ -108,9 +110,8 @@ def one_to_many_self(model_class, fk, dict_key=None):
         model_class,
         model_class.__tablename__,
         relationship_kwargs={
-            'remote_side': '{model_class}.{remote_column}'.format(model_class=model_class.__name__,
-                                                                  remote_column=fk
-                                                                 )
+            'remote_side': '{model_class}.{remote_column}'.format(
+                model_class=model_class.__name__, remote_column=fk)
         },
         back_populates=False,
         dict_key=dict_key
@@ -144,6 +145,8 @@ def one_to_one(model_class,
                        false to disable
     :type back_populates: basestring|bool
     """
+    if back_populates is None:
+        back_populates = model_class.__tablename__
 
     return _relationship(model_class,
                          other_table,
@@ -156,7 +159,7 @@ def one_to_many(model_class,
                 child_table,
                 child_fk=None,
                 dict_key=None,
-                child_property=None):
+                back_populates=None):
     """
     Declare a one-to-many relationship property. The property value would be a list or dict
of
     instances of the child table's model.
@@ -177,14 +180,16 @@ def one_to_many(model_class,
     :param dict_key: If set the value will be a dict with this key as the dict key; otherwise
will
                      be a list
     :type dict_key: basestring
-    :param child_property: Override name of matching many-to-one property at child table;
set to
+    :param back_populates: Override name of matching many-to-one property at child table;
set to
                            false to disable
-    :type child_property: basestring|bool
+    :type back_populates: basestring|bool
     """
+    if back_populates is None:
+        back_populates = model_class.__tablename__
     return _relationship(
         model_class,
         child_table,
-        relationship_kwargs={'back_populates': child_property or model_class.__tablename__},
+        back_populates=back_populates,
         other_fk=child_fk,
         dict_key=dict_key)
 
@@ -217,14 +222,12 @@ def many_to_one(model_class,
                             false to disable
     :type back_populates: basestring|bool
     """
-    relationship_kwargs = {}
-    if back_populates is not False:
-        relationship_kwargs['back_populates'] = back_populates or \
-                                                formatting.pluralize(model_class.__tablename__)
+    if back_populates is None:
+        back_populates = formatting.pluralize(model_class.__tablename__)
 
     return _relationship(model_class,
                          parent_table,
-                         relationship_kwargs=relationship_kwargs,
+                         back_populates=back_populates,
                          fk=fk,
                          other_fk=parent_fk)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3220d470/aria/modeling/service_changes.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_changes.py b/aria/modeling/service_changes.py
index 0eb8972..6c13b0f 100644
--- a/aria/modeling/service_changes.py
+++ b/aria/modeling/service_changes.py
@@ -265,7 +265,6 @@ class ServiceModificationBase(ModelMixin):
     # endregion
 
     # region many_to_one relationships
-    pass
     @declared_attr
     def service(cls):
         return relationship.many_to_one(cls, 'service', back_populates='modifications')
@@ -275,7 +274,3 @@ class ServiceModificationBase(ModelMixin):
     # region many_to_many relationships
 
     # endregion
-
-
-
-

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3220d470/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index df446d9..f322c92 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -117,7 +117,7 @@ class ServiceBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
 
     @declared_attr
     def substitution(cls):
-        return relationship.one_to_one(cls, 'substitution')
+        return relationship.one_to_one(cls, 'substitution', back_populates=False)
 
     # endregion
 
@@ -439,12 +439,12 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
     @declared_attr
     def outbound_relationships(cls):
         return relationship.one_to_many(
-            cls, 'relationship', child_fk='source_node_fk', child_property='source_node')
+            cls, 'relationship', child_fk='source_node_fk', back_populates='source_node')
 
     @declared_attr
     def inbound_relationships(cls):
         return relationship.one_to_many(
-            cls, 'relationship', child_fk='target_node_fk', child_property='target_node')
+            cls, 'relationship', child_fk='target_node_fk', back_populates='target_node')
 
     # endregion
 
@@ -928,7 +928,7 @@ class SubstitutionBase(InstanceModelMixin):
 
     @declared_attr
     def service(cls):
-        return relationship.one_to_one(cls, 'service')
+        return relationship.one_to_one(cls, 'service', back_populates=False)
 
     @declared_attr
     def substitution_template(cls):
@@ -1028,15 +1028,15 @@ class SubstitutionMappingBase(InstanceModelMixin):
 
     @declared_attr
     def node(cls):
-        return relationship.one_to_one(cls, 'node')
+        return relationship.one_to_one(cls, 'node', back_populates=False)
 
     @declared_attr
     def capability(cls):
-        return relationship.one_to_one(cls, 'capability')
+        return relationship.one_to_one(cls, 'capability', back_populates=False)
 
     @declared_attr
     def requirement_template(cls):
-        return relationship.one_to_one(cls, 'requirement_template')
+        return relationship.one_to_one(cls, 'requirement_template', back_populates=False)
 
     # endregion
 
@@ -1176,7 +1176,7 @@ class RelationshipBase(InstanceModelMixin):
 
     @declared_attr
     def target_capability(cls):
-        return relationship.one_to_one(cls, 'capability')
+        return relationship.one_to_one(cls, 'capability', back_populates=False)
 
     # endregion
 
@@ -1617,7 +1617,7 @@ class OperationBase(InstanceModelMixin):
 
     @declared_attr
     def plugin_specification(cls):
-        return relationship.one_to_one(cls, 'plugin_specification')
+        return relationship.one_to_one(cls, 'plugin_specification', back_populates=False)
 
     # endregion
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3220d470/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 302248b..88441f9 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -163,7 +163,7 @@ class ServiceTemplateBase(TemplateModelMixin): # pylint: disable=too-many-public
 
     @declared_attr
     def substitution_template(cls):
-        return relationship.one_to_one(cls, 'substitution_template')
+        return relationship.one_to_one(cls, 'substitution_template', back_populates=False)
 
     @declared_attr
     def node_types(cls):
@@ -999,15 +999,15 @@ class SubstitutionTemplateMappingBase(TemplateModelMixin):
 
     @declared_attr
     def node_template(cls):
-        return relationship.one_to_one(cls, 'node_template')
+        return relationship.one_to_one(cls, 'node_template', back_populates=False)
 
     @declared_attr
     def capability_template(cls):
-        return relationship.one_to_one(cls, 'capability_template')
+        return relationship.one_to_one(cls, 'capability_template', back_populates=False)
 
     @declared_attr
     def requirement_template(cls):
-        return relationship.one_to_one(cls, 'requirement_template')
+        return relationship.one_to_one(cls, 'requirement_template', back_populates=False)
 
     # endregion
 
@@ -1169,7 +1169,7 @@ class RequirementTemplateBase(TemplateModelMixin):
 
     @declared_attr
     def relationship_template(cls):
-        return relationship.one_to_one(cls, 'relationship_template')
+        return relationship.one_to_one(cls, 'relationship_template', back_populates=False)
 
     # endregion
 
@@ -1797,7 +1797,7 @@ class OperationTemplateBase(TemplateModelMixin):
 
     @declared_attr
     def plugin_specification(cls):
-        return relationship.one_to_one(cls, 'plugin_specification')
+        return relationship.one_to_one(cls, 'plugin_specification', back_populates=False)
 
     # endregion
 


Mime
View raw message