def page_title(self): """returns a title according to the result set - used for the title in the HTML header """ vtitle = self._cw.form.get('vtitle') if vtitle: return self._cw._(vtitle) # class defined title will only be used if the resulting title doesn't # seem clear enough vtitle = getattr(self, 'title', None) or u'' if vtitle: vtitle = self._cw._(vtitle) rset = self.cw_rset if rset and rset.rowcount: if rset.rowcount == 1: try: entity = rset.complete_entity(0, 0) # use long_title to get context information if any clabel = entity.dc_long_title() except NotAnEntity: clabel = display_name(self._cw, rset.description[0][0]) clabel = u'%s (%s)' % (clabel, vtitle) else: etypes = rset.column_types(0) if len(etypes) == 1: etype = next(iter(etypes)) clabel = display_name(self._cw, etype, 'plural') else: clabel = u'#[*] (%s)' % vtitle else: clabel = vtitle return u'%s (%s)' % (clabel, self._cw.property_value('ui.site-title'))
def render_entity_attributes(self, entity): self.w(u'<h3>') entity.view('oneline', w=self.w) if entity.prefered: self.w(u' (<i>%s</i>)' % entity.prefered.view('oneline')) self.w(u'</h3>') try: persons = entity.reverse_primary_email except Unauthorized: persons = [] if persons: emailof = persons[0] self.field(display_name(self._cw, 'primary_email', 'object'), emailof.view('oneline')) pemaileid = emailof.eid else: pemaileid = None try: emailof = 'use_email' in self._cw.vreg.schema and entity.reverse_use_email or ( ) emailof = [e for e in emailof if not e.eid == pemaileid] except Unauthorized: emailof = [] if emailof: emailofstr = ', '.join(e.view('oneline') for e in emailof) self.field(display_name(self._cw, 'use_email', 'object'), emailofstr)
def state_header(self): state = self._cw.search_state if state[0] == 'normal': return _ = self._cw._ value = self._cw.view('oneline', self._cw.eid_rset(state[1][1])) msg = ' '.join( (_("searching for"), display_name(self._cw, state[1][3]), _("to associate with"), value, _("by relation"), '"', display_name(self._cw, state[1][2], state[1][0]), '"')) return self.w(u'<div class="stateMessage">%s</div>' % msg)
def field(self, label, value, row=True, show_label=True, w=None, tr=True, table=False): """read-only field""" if w is None: w = self.w if table: w(u'<tr class="entityfield">') else: w(u'<div class="entityfield">') if show_label and label: if tr: label = display_name(self._cw, label) if table: w(u'<th>%s</th>' % label) else: w(u'<span class="label">%s</span> ' % label) if table: if not (show_label and label): w(u'<td colspan="2">%s</td></tr>' % value) else: w(u'<td>%s</td></tr>' % value) else: w(u'<span>%s</span></div>' % value)
def call(self): req = self._cw rows_by_type = {} writer = self.csvwriter() rowdef_by_type = {} for index in range(len(self.cw_rset)): entity = self.cw_rset.complete_entity(index) if entity.e_schema not in rows_by_type: rowdef_by_type[entity.e_schema] = [ rs for rs, at in entity.e_schema.attribute_definitions() if at != 'Bytes' ] rows_by_type[entity.e_schema] = [[ display_name(req, rschema.type) for rschema in rowdef_by_type[entity.e_schema] ]] rows = rows_by_type[entity.e_schema] rows.append([ entity.printable_value(rs.type, format='text/plain') for rs in rowdef_by_type[entity.e_schema] ]) for rows in rows_by_type.values(): writer.writerows(rows) # use two empty lines as separator writer.writerows([[], []])
def render_title(self, w): title = self._cw._(self.title) if self.cw_rset: etypes = self.cw_rset.column_types(0) if len(etypes) == 1: plural = self.cw_rset.rowcount > 1 and 'plural' or '' etypelabel = display_name(self._cw, next(iter(etypes)), plural) title = u'%s - %s' % (title, etypelabel.lower()) w(title)
def _field_as_table(self, label, value, show_label=True, tr=True, w=None): w(u'<tr class="entityfield">') if show_label and label: if tr: label = display_name(self._cw, label) w(u'<th>%s</th>' % label) if not (show_label and label): w(u'<td colspan="2">%s</td></tr>' % value) else: w(u'<td>%s</td></tr>' % value)
def _compute_default_value(self, rschema, role): default = self._rules.get('novalue_label') if default is None: if self._rules.get('novalue_include_rtype'): default = self._cw._('<%s not specified>') % display_name( self._cw, rschema.type, role) else: default = self._cw._('<not specified>') else: default = self._cw._(default) return xml_escape(default)
def entity_types(self, eschemas): """return an iterator on formatted links to get a list of entities of each entity types """ req = self._cw for eschema in eschemas: if eschema.final or not eschema.may_have_permission('read', req): continue etype = eschema.type nb = req.execute('Any COUNT(X) WHERE X is %s' % etype)[0][0] if nb > 1: label = display_name(req, etype, 'plural') else: label = display_name(req, etype) url = self._cw.build_url(etype) etypelink = u' <a href="%s">%s</a> (%d)' % (xml_escape(url), label, nb) if eschema.has_perm(req, 'add'): yield (label, etypelink, self.add_entity_link(etype)) else: yield (label, etypelink, u'')
def _rel_label(self, entity, rschema, role, dispctrl): if rschema.final: showlabel = dispctrl.get('showlabel', self.show_attr_label) else: showlabel = dispctrl.get('showlabel', self.show_rel_label) if showlabel: if dispctrl.get('label'): label = self._cw._(dispctrl['label']) else: label = display_name(self._cw, rschema.type, role, context=entity.cw_etype) return label return u''
def restore_pending_inserts(self, form): """used to restore edition page as it was before clicking on 'search for <some entity type>' """ entity = form.edited_entity pending_inserts = set( get_pending_inserts(form._cw, form.edited_entity.eid)) for pendingid in pending_inserts: eidfrom, rtype, eidto = pendingid.split(':') pendingid = 'id' + pendingid if int(eidfrom) == entity.eid: # subject label = display_name(form._cw, rtype, 'subject', entity.cw_etype) reid = eidto else: label = display_name(form._cw, rtype, 'object', entity.cw_etype) reid = eidfrom jscall = "javascript: cancelPendingInsert('%s', 'tr', null, %s);" \ % (pendingid, entity.eid) rset = form._cw.eid_rset(reid) eview = form._cw.view('text', rset, row=0) yield rtype, pendingid, jscall, label, reid, eview
def cell_call(self, row, col, view=None, **kwargs): self._cw.add_js('cubicweb.ajax.js') entity = self.cw_rset.get_entity(row, col) title = display_name(self._cw, self.rtype, get_role(self), context=entity.cw_etype) box = SideBoxWidget(title, self.__regid__) related = self.related_boxitems(entity) unrelated = self.unrelated_boxitems(entity) box.extend(related) if related and unrelated: box.append(Separator()) box.extend(unrelated) box.render(self.w)
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 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 _field_as_div(self, label, value, show_label=True, w=None): self.w(u'<div class="row-fluid">') if show_label and label: self.w(u'<h6 class="span4">%s</h6>'% display_name(self._cw, label)) self.w(u'<div class="span8">%s</div>' % value) self.w(u'</div>') # row_fluid
def title(self): return self._cw.__('view all %s') % display_name( self._cw, self.etype, 'plural').lower()
def _build_entity_info(self, etype, eid, changes): return dict( etype=display_name(self._cw, etype), entity=self._build_entity_link(eid), eid=eid, changes=changes)
def _build_relation_info(self, rtype, eid_from, eid_to): return dict( rtype=display_name(self._cw, rtype), entity_from=self._build_entity_link(eid_from), entity_to=self._build_entity_link(eid_to) )
def render_title(self, w): w( display_name(self._cw, self.rtype, role(self), context=self.entity.cw_etype))
def delete_entity(self, args): eid, etype, title = args msg = self._cw._('deleted %(etype)s #%(eid)s (%(title)s)') etype = display_name(self._cw, etype).lower() self.w(msg % locals())
def title(self): etype = next(iter(self.cw_rset.column_types(0))) return display_name(self._cw, etype, form='plural')
def default_header(self): return display_name(self._cw, self.colid, self.role)