def cell_call(self, row, col): rset = self.cw_rset.get_entity(row, col).related(self.rtype, role(self)) self.w(u'<div class="mainInfo">') if self.title: self.w(tags.h1(self._cw._(self.title))) self.wview(self.vid, rset, 'noresult') self.w(u'</div>')
def box_item(self, entity, etarget, fname, label): """builds HTML link to edit relation between `entity` and `etarget`""" args = {role(self): entity.eid, target(self): etarget.eid} # for each target, provide a link to edit the relation jscall = js.cw.utils.callAjaxFuncThenReload(fname, self.rtype, args['subject'], args['object']) return u'[<a href="javascript: %s" class="action">%s</a>] %s' % ( xml_escape(str(jscall)), label, etarget.view('incontext'))
def unrelated_entities(self, entity): """returns the list of unrelated entities, using the entity's appropriate vocabulary function """ skip = set( str(e.eid) for e in entity.related(self.rtype, role(self), entities=True)) skip.add(None) skip.add(INTERNAL_FIELD_VALUE) filteretype = getattr(self, 'etype', None) entities = [] form = self._cw.vreg['forms'].select('edition', self._cw, rset=self.cw_rset, row=self.cw_row or 0) field = form.field_by_name(self.rtype, role(self), entity.e_schema) for _, eid in field.vocabulary(form): if eid not in skip: entity = self._cw.entity_from_eid(eid) if filteretype is None or entity.cw_etype == filteretype: entities.append(entity) return entities
def cell_call(self, row, col, view=None): rql = self.rql() if rql is None: entity = self.cw_rset.get_entity(row, col) rset = entity.related(self.rtype, role(self)) else: eid = self.cw_rset[row][col] rset = self._cw.execute(self.rql(), {'x': eid}) if not rset.rowcount: return self.w(u'<div class="%s">' % self.cssclass) self.w(u'<h4>%s</h4>\n' % self._cw._(self.title).capitalize()) self.wview(self.vid, rset) self.w(u'</div>')
def unrelated_entities(self, entity): """returns the list of unrelated entities if etype is not defined on the Box's class, the default behaviour is to use the entity's appropraite vocabulary function """ # use entity.unrelated if we've been asked for a particular etype if getattr(self, 'etype', None): rset = entity.unrelated(self.rtype, self.etype, role(self), ordermethod='fetch_order') self.paginate(self._cw, rset=rset, w=self.w) return rset.entities() super(AddRelationView, self).unrelated_entities(self)
def cell_call(self, row, col, rtype=None, target=None, etype=None): self.rtype = rtype or self._cw.form['rtype'] self.target = target or self._cw.form['target'] self.etype = etype or self._cw.form.get('etype') entity = self.cw_rset.get_entity(row, col) rschema = self._cw.vreg.schema.rschema(self.rtype) if not self.etype: if self.target == 'object': etypes = rschema.objects(entity.e_schema) else: etypes = rschema.subjects(entity.e_schema) if len(etypes) == 1: self.etype = etypes[0] self.w(u'<div id="%s">' % self.domid) self.w( u'<h1>%s</h1>' % self._cw._('relation %(relname)s of %(ent)s') % { 'relname': rschema.display_name(self._cw, role(self)), 'ent': entity.view('incontext') }) self.w(u'<ul class="list-unstyled">') for boxitem in self.unrelated_boxitems(entity): self.w('<li>%s</li>' % boxitem) self.w(u'</ul></div>')
def render_body(self, w): rset = self.entity.related(self.rtype, role(self)) self._cw.view(self.vid, rset, w=w)
def render_title(self, w): w( display_name(self._cw, self.rtype, role(self), context=self.entity.cw_etype))
def related_entities(self, entity): return entity.related(self.rtype, role(self), entities=True)