Esempio n. 1
0
def relationship_column(objA, objB):
    "Return model attribute on objA that has a relationship with objB"
    assert issubclass(objA, Base)
    assert issubclass(objB, Base)

    rel = related_classes(objA)

    if objB not in rel:
        return None

    for c in table_attribs(objA).values():
        if get_type(c) == objB:
            return c
Esempio n. 2
0
    def get_primitive_fields(self, object, object_type):
        print(object_type)
        list_of_primitives = {}
        for field in object:
            if (type(object[field]) is not list) and (type(object[field])
                                                      is not dict):
                list_of_primitives[field] = object[field]
            if type(object[field]) is dict:
                new_type = sqlalchemy_utils.get_type(
                    object_type.__dict__[field])
                new_object = self.upload_from_json(object[field], new_type)
                list_of_primitives[field] = new_object

        return list_of_primitives
Esempio n. 3
0
    def upload_from_json(self, objects, first_data_type):
        session = self.flask.session

        if type(first_data_type) is str:
            models_object = models.__dict__[first_data_type]
        else:
            models_object = first_data_type

        data_type = models_object

        to_upload = []
        dict_of_new_objects = {}
        list_of_fields = self.get_primitive_fields(objects, data_type)
        dict_of_new_objects = self.get_dict_of_new_objects(objects)

        first_parent = self.get_or_create_object_upload(
            session, models_object, list_of_fields)
        first_upload = Uploader(parent_node=first_parent,
                                dict_of_new_objects=dict_of_new_objects)
        to_upload.append(first_upload)

        while to_upload:
            new_to_upload = []
            for uploader in to_upload:
                for key in uploader.dict_of_new_objects:
                    new_obj_type = sqlalchemy_utils.get_type(
                        type(uploader.parent_node).__dict__[key])
                    list_of_new_objects = uploader.dict_of_new_objects[key]
                    for new_object in list_of_new_objects:
                        the_new_object = self.get_or_create_object_upload(
                            session, new_obj_type,
                            self.get_primitive_fields(new_object,
                                                      new_obj_type))
                        getattr(uploader.parent_node,
                                key).append(the_new_object)
                        dict_of_new_objects = self.get_dict_of_new_objects(
                            new_object)
                        if dict_of_new_objects:
                            new_uploader = Uploader(
                                parent_node=the_new_object,
                                dict_of_new_objects=dict_of_new_objects)
                            new_to_upload.append(new_uploader)
            to_upload = new_to_upload
        session.commit()
        return first_parent
        """
Esempio n. 4
0
 def test_calculated_column_property(self, Article):
     assert isinstance(get_type(Article.some_property), sa.Integer)
Esempio n. 5
0
 def test_column(self, Article):
     assert isinstance(get_type(Article.__table__.c.id), sa.Integer)
Esempio n. 6
0
 def test_column_property(self, Article):
     assert isinstance(get_type(Article.id.property), sa.Integer)
Esempio n. 7
0
 def test_instrumented_attribute(self, Article):
     assert isinstance(get_type(Article.id), sa.Integer)
Esempio n. 8
0
 def test_calculated_column_property(self, Article):
     assert isinstance(get_type(Article.some_property), sa.Integer)
Esempio n. 9
0
 def test_relationship_property(self, Article, User):
     assert get_type(Article.author) == User
Esempio n. 10
0
 def test_column_property(self, Article):
     assert isinstance(get_type(Article.id.property), sa.Integer)
Esempio n. 11
0
 def test_column(self, Article):
     assert isinstance(get_type(Article.__table__.c.id), sa.Integer)
Esempio n. 12
0
 def test_instrumented_attribute(self, Article):
     assert isinstance(get_type(Article.id), sa.Integer)
Esempio n. 13
0
 def test_relationship_property(self):
     assert get_type(self.Article.author) == self.User
Esempio n. 14
0
def column_model(obj):
    "Return model class for given model attribute/column"
    return get_type(obj)
Esempio n. 15
0
 def test_relationship_property(self, Article, User):
     assert get_type(Article.author) == User
Esempio n. 16
0
 def test_scalar_select(self, Article):
     query = sa.select([Article.id]).as_scalar()
     assert isinstance(get_type(query), sa.Integer)
Esempio n. 17
0
 def test_scalar_select(self, Article):
     query = sa.select([Article.id]).as_scalar()
     assert isinstance(get_type(query), sa.Integer)
Esempio n. 18
0
 def test_relationship_property(self):
     assert get_type(self.Article.author) == self.User