def _model_tree_iteration(self, model, visited, context): model = IModel(model) if model in visited: self.log('Skiping already validated model: %r', model) return visited.append(model) yield self._validate_model(model, context) if IQueryModel.providedBy(model): querymodel = yield model.query_items(offset=0, limit=10) items = yield querymodel.fetch_items() else: try: items = yield model.fetch_items() except NotSupported: self.info('Not iteration further down the model %r because ' 'it doesnt support fetching items', model) return for item in items: try: submodel = yield item.fetch() except Unauthorized: continue if IModel.providedBy(submodel): subcontext = context.descend(submodel) yield self._model_tree_iteration(submodel, visited, subcontext)
def _format_attribute_item(self, item, context): model = yield safe_fetch(item) if not IModel.providedBy(model): defer.returnValue("") result = yield self._format_attribute(model, context.descend(model), context, html_links(item)) defer.returnValue(result)
def _build_tree(self, tree, model, limit, context): if not IModel.providedBy(model): return items = yield model.fetch_items() # [dict of attributes added by this level, list of child rows] tree.append([dict(), list()]) for item in items: submodel = yield safe_fetch(item) if not submodel: continue if not IAttribute.providedBy(submodel): if limit > 0: if IModel.providedBy(submodel): subcontext = context.descend(submodel) yield self._build_tree(tree[-1][1], submodel, limit - 1, subcontext) else: column_name = item.label or item.name tree[-1][0][(column_name, limit)] = (item, context)
def _build_tree(self, tree, model, limit, context): if not IModel.providedBy(model): return items = yield model.fetch_items() #FIXME: column ordering do not work ordered = self._order_items(model, items) # [dict of attributes added by this level, list of child rows] tree.append([dict(), list()]) for item in ordered: #FIXME: should not need to fetch model for this m = yield item.fetch() if not IAttribute.providedBy(m): if limit > 0: submodel = yield item.fetch() if IModel.providedBy(submodel): subcontext = context.descend(submodel) yield self._build_tree(tree[-1][1], submodel, limit - 1, subcontext) else: column_name = item.label or item.name tree[-1][0][(column_name, limit)] = (item, context)
def _model_tree_iteration(self, model, visited, context): model = IModel(model) if model in visited: self.log('Skiping already validated model: %r', model) return visited.append(model) yield self._validate_model(model, context) items = yield model.fetch_items() for item in items: submodel = yield item.fetch() if IModel.providedBy(submodel): subcontext = context.descend(submodel) yield self._model_tree_iteration(submodel, visited, subcontext)
def _wrap_source(self, source, view, model_factory): if source is None: return source if IReference.providedBy(source): return source if IModel.providedBy(source): return self._init_model(source, view) if not IModelFactory.providedBy(model_factory): if callable(model_factory): ctx = self.model.make_context(key=self.name, view=view) d = model_factory(source, ctx) d.addCallback(self._got_model_factory, source, view) return d return self._got_model_factory(model_factory, source, view)
def _render_items(self, model, markup, context): try: items = yield model.fetch_items() if not items: return except NotSupported: return array_deepness = render_array(model) if array_deepness: markup.div(_class='array')( self._render_array(model, array_deepness, context)).close() else: ordered = self._order_items(model, items) ul = markup.ul(_class="items") for item in ordered: submodel = yield safe_fetch(item) li = markup.li() if item.reference: url = item.reference.resolve(context) markup.span(_class='name')( html.tags.a(href=url)(item.label or item.name)).close() else: markup.span(_class='name')(item.label or item.name).close() if IAttribute.providedBy(submodel): li.append(self._format_attribute_item(item, context)) else: markup.span(_class="value").close() if item.desc: markup.span(_class='desc')(item.desc).close() array_deepness = render_array(item) if submodel and array_deepness: if IModel.providedBy(submodel): array = self._render_array( submodel, array_deepness, context) markup.div(_class='array')(array).close() li.close() ul.close()
def _render_items(self, model, markup, context): items = yield model.fetch_items() if not items: return array_deepness = render_array(model) if array_deepness: markup.div(_class='array')( self._render_array(model, array_deepness, context)).close() else: ordered = self._order_items(model, items) ul = markup.ul(_class="items") for item in ordered: li = markup.li() url = item.reference.resolve(context) markup.span(_class='name')( html.tags.a(href=url)(item.label or item.name)).close() #FIXME: shouldn't need to fetch the model for that m = yield item.fetch() if IAttribute.providedBy(m): li.append(self._format_attribute_item(item, context)) else: markup.span(_class="value").close() if item.desc: markup.span(_class='desc')(item.desc).close() array_deepness = render_array(item) if array_deepness: submodel = yield item.fetch() if IModel.providedBy(submodel): array = self._render_array(submodel, array_deepness, context) markup.div(_class='array')(array).close() li.close() ul.close() markup.hr()