def __init__(self, model, rels=None, **kw): BaseSqlaInspector.__init__(self, model, **kw) # We store the relations already treated by storing the primaryjoin that # they use, since the backref uses the same join string, we can avoid # recursive collection self.rels = rels or [] self.columns = self.collect_columns()
def _collect_relationship(self, main_infos, prop, result): """ collect a relationship header: * One To many : if {'export': {'reletad_key': 'remote_attr'}} is provided, we take all the related objects and join their remote attr's value with commas If an index is provided, only the related element of index 'index' is retrieved and it's attr value is returned In case of excel exports, a specific sheet is generated by table (see excel.py for more details) * Many To One : If a related_key is provided, we remove the associated foreign key from the output (we collect its associated title) and only the given key of the associated object will be exported If no related_key is provided, we use the relationship's title as prefix and for each attribute of the related object, we add a column If a callable is provided under the formatter key, it will be used to format the related object :param dict main_infos: The already collected datas about this column :param obj prop: The property mapper of the relationship :param list result: The actual collected headers :returns: a dict with the datas matching this header """ # No handling of the uselist relationships for the moment # Maybe with indexes ? ( to see: on row add, append headers on the fly # if needed ) if prop.uselist: # One to many pass else: if "related_key" in main_infos or 'formatter' in main_infos: self._merge_many_to_one_field(main_infos, prop, result) else: related_field_inspector = BaseSqlaInspector(prop.mapper) main_infos_list = [] for column in related_field_inspector.get_columns_only(): infos = self._get_prop_infos(column) if self._is_excluded(column, infos): continue infos['label'] = u"%s %s" % ( main_infos['label'], infos['label'] ) infos['__col__'] = main_infos['__col__'] infos['name'] = "%s %s" % (main_infos['name'], column.key) infos['key'] = main_infos['key'] infos['related_key'] = column.key main_infos_list.append(infos) return main_infos_list return main_infos
def __init__(self, model, excludes=(), exclude_relationships=False): BaseSqlaInspector.__init__(self, model) self.model = model self.excludes = excludes self.exclude_relationships = exclude_relationships self.columns = self._collect_columns()
def __init__(self, model, excludes=()): BaseSqlaInspector.__init__(self, model) self.model = model self.excludes = excludes self.columns = self._collect_columns()
def __init__(self, model, **kw): BaseExporter.__init__(self) BaseSqlaInspector.__init__(self, model, **kw) self.set_headers(self._collect_headers())