def cell_call(self, row, col): w = self.w _ = self._cw._ entity = self.cw_rset.get_entity(row, col) if entity.is_constant and isinstance(entity.first, (bool, numpy.bool_)): w(tags.span(_(unicode(entity.first_unit)))) else: w(u'<div style="display: inline">') # XXX values should be rounded at the data level first = unicode(str(round(entity.first, 2))) last = unicode(str(round(entity.last, 2))) w(tags.span(first + entity.safe_unit, style='font-size: 10px;')) w(u'<div class="info">') content = u"  %s  " % entity.view('sparkline') w(tags.a(content, href=entity.absolute_url(), escapecontent=False)) w(u'</div>') w(tags.span(last + entity.safe_unit, style='font-size: 10px;')) w(u' ') w(u'<div style="display: inline">') entity.view(self.inner_vid, label=_('[summary]'), w=w) w(u'</div>') url = entity.absolute_url(vid='tsxlexport') w( tags.span(tags.a(_(u'[export]'), href=url), klass='tsexport', escapecontent=False)) w(u'</div>')
class CWUsersTable(tableview.EntityTableView): __regid__ = 'cw.users-table' __select__ = is_instance('CWUser') columns = [ 'user', 'in_state', 'firstname', 'surname', 'in_group', 'primary_email', 'cw_source' ] layout_args = {'display_filter': 'top'} finalvid = 'editable-final' column_renderers = { 'user': tableview.EntityTableColRenderer( renderfunc=lambda w, x: w(tags.a(x.login, href=x.absolute_url())), sortfunc=lambda x: x.login), 'in_state': tableview.EntityTableColRenderer( renderfunc=lambda w, x: w( x.cw_adapt_to('IWorkflowable').printable_state), sortfunc=lambda x: x.cw_adapt_to('IWorkflowable').printable_state), 'in_group': tableview.EntityTableColRenderer(renderfunc=lambda w, x: x.view( 'reledit', rtype='in_group', role='subject', w=w)), 'primary_email': tableview.RelatedEntityColRenderer(getrelated=lambda x: x.primary_email and x.primary_email[0] or None), 'cw_source': tableview.RelatedEntityColRenderer( getrelated=lambda x: x.cw_source[0]), }
def call(self, basepath, maxentries=None, **kwargs): index = {} for entity in self.cw_rset.entities(): index.setdefault(self.group_key(entity, **kwargs), []).append(entity) displayed = sorted(index) if self.reversed: displayed = reversed(displayed) if maxentries is None: needmore = False else: needmore = len(index) > maxentries displayed = tuple(displayed)[:maxentries] w = self.w w(u'<ul class="boxListing">') for key in displayed: if key: w(u'<li>%s</li>\n' % self.index_link(basepath, key, index[key])) if needmore: url = self._cw.build_url('view', vid=self.__regid__, rql=self.cw_rset.printable_rql()) w(u'<li>%s</li>\n' % tags.a(u'[%s]' % self._cw._('see more'), href=url)) w(u'</ul>\n')
def cell_call(self, row, col, **kwargs): entity = self.cw_rset.get_entity(row, col) desc = uilib.cut(entity.dc_description(), 50) # NOTE remember camember: tags.a autoescapes self.w( tags.a(entity.view('breadcrumbtext'), href=entity.absolute_url(), title=desc))
def call(self, onsubmit=None): """ask for confirmation before real deletion""" req, w = self._cw, self.w _ = req._ if self.show_composite: req.add_css(('jquery-treeview/jquery.treeview.css', 'cubicweb.treeview.css')) w(u'<script type="text/javascript">updateMessage(\'%s\');</script>\n' % _('this action is not reversible!')) # XXX above message should have style of a warning w(u'<h4>%s</h4>\n' % _('Do you want to delete the following element(s)?')) form = self._cw.vreg['forms'].select(self.__regid__, req, rset=self.cw_rset, onsubmit=onsubmit) w(u'<ul>\n') page_size = req.property_value('navigation.page-size') for entity in self.cw_rset.entities(): # don't use outofcontext view or any other that may contain inline # edition form w(u'<li>%s' % tags.a(entity.view('textoutofcontext'), href=entity.absolute_url())) if self.show_composite: content = None for count, centity in enumerate( self._iter_composite_entities( entity, limit=page_size, )): if count == 0: w(u'<ul class="treeview">') if content is not None: w(u'<li>%s</li>' % content) if count == page_size - 1: w(u'<li class="last">%s</li></ul>' % _('And more composite entities')) break content = tags.a(centity.view('textoutofcontext'), href=centity.absolute_url()) else: if content is not None: w(u'<li class="last">%s</li></ul>' % content) w(u'</li>\n') w(u'</ul>\n') form.render(w=self.w)
def _render_export_url(self, form): out = [] w = out.append if form.edited_entity and isinstance(form.edited_entity.eid, int): url = form.edited_entity.absolute_url(vid='tsxlexport') # button triggers form validation w( tags.span(tags.a(form._cw._('[export]'), href=url), klass='tsexport', escapecontent=False)) return ''.join(unicode(x) for x in out)
def build_undo_link(self, txuuid, redirect_path=None, redirect_params=None): """ the kwargs are passed to build_url""" _ = self._cw._ redirect = {} if redirect_path: redirect['__redirectpath'] = redirect_path if redirect_params: if isinstance(redirect_params, dict): redirect['__redirectparams'] = self._cw.build_url_params(**redirect_params) else: redirect['__redirectparams'] = redirect_params link_url = self._cw.build_url('undo', txuuid=txuuid, **redirect) msg = u"<span class='undo'>%s</span>" % tags.a( _('undo'), href=link_url) return msg
def index_link(self, basepath, key, items): if key[0] is None: return label = u'%s [%s]' % (key[0], len(items)) etypes = set(entity.cw_etype for entity in items) vtitle = self._cw._('%(etype)s by %(author)s') % { 'etype': ', '.join( display_name(self._cw, etype, 'plural') for etype in etypes), 'author': label } url = self.index_url(basepath, key[1], vtitle=vtitle) title = self._cw._('archive for %(author)s') % {'author': key[0]} return tags.a(label, href=url, title=title)
def index_link(self, basepath, key, items): """represent a single month entry""" year, month = key label = u'%s %s [%s]' % (self._cw._( calendar.MONTHNAMES[int(month) - 1]), year, len(items)) etypes = set(entity.cw_etype for entity in items) vtitle = '%s %s' % (', '.join( display_name(self._cw, etype, 'plural') for etype in etypes), label) title = self._cw._('archive for %(month)s/%(year)s') % { 'month': month, 'year': year } url = self.index_url(basepath, key, vtitle=vtitle) return tags.a(label, href=url, title=title)
def focus_link(self, rset): return self.bk_linkbox_template % tags.a( self._cw._('focus on this selection'), href=self._cw.url(), id='focusLink')
def render_cell(self, w, rownum): url = self.data[rownum][1] if url and url.startswith('http'): url = tags.a(url, href=url) w(url or u' ')
def render(self, w): w(tags.a(self.label, href=self.href, **self.attrs))
def __str__(self): return tags.a(self.label, href=self.href, **self.attrs)
def index_link(self, basepath, key, items): url = self.index_url(basepath, key) if isinstance(key, (list, tuple)): key = ' '.join(key) return tags.a(key, href=url)