def test_get_column_attribute(self): val = [1, 2, 3, 4] test_row = TestModel(json_list=val) dialect = self.engine.dialect attr = utils.get_column_attribute(test_row, 'json_list', dialect=dialect) self.assertEquals(attr, json.dumps(val)) attr = utils.get_column_attribute(test_row, 'json_list') self.assertEquals(attr, val)
def build_row_dict(cls, ut_row, session, deleted=False, user_id=None, use_dirty=True): """ :param ut_row: the row from the user table :param deleted: whether or not the row is deleted :param user_id: the user that is performing the update on this row :param use_dirty: whether to use the dirty fields from ut_row or not :return: a dictionary of key value pairs to be inserted into the archive table :rtype: dict """ at_data = { 'va_deleted': deleted, 'va_updated_at': datetime.now(), 'va_data': ut_row._to_dict(utils.get_dialect(session), use_dirty=use_dirty), } version = cls._latest_version(session, ut_row, use_dirty=use_dirty) at_data['va_version'] = 0 if version is None else version + 1 for col_name in cls._version_col_names: at_data[col_name] = utils.get_column_attribute(ut_row, col_name, use_dirty=use_dirty) if user_id is not None: at_data['user_id'] = user_id return at_data
def _to_dict(self, dialect, use_dirty=True): """ :param dialect: a :py:class:`~sqlalchemy.engine.interfaces.Dialect` corresponding to the \ SQL dialect being used. :param use_dirty: whether to make a dict of the fields as they stand, or the fields \ before the row was updated :return: a dictionary of key value pairs representing this row. :rtype: dict """ return { cn: utils.get_column_attribute(self, c, use_dirty=use_dirty, dialect=dialect) for c, cn in utils.get_column_keys_and_names(self) if c not in self.va_ignore_columns }