def test_intscore_entity_selector(self): with self.admin_access.web_request() as req: rset = req.execute('Any E WHERE E eid 1') selector = score_entity(lambda x: None) self.assertEqual(selector(None, req, rset=rset), 0) selector = score_entity(lambda x: "something") self.assertEqual(selector(None, req, rset=rset), 1) selector = score_entity(lambda x: object) self.assertEqual(selector(None, req, rset=rset), 1) rset = req.execute('Any G LIMIT 2 WHERE G is CWGroup') selector = score_entity(lambda x: 10) self.assertEqual(selector(None, req, rset=rset), 20) selector = score_entity(lambda x: 10, mode='any') self.assertEqual(selector(None, req, rset=rset), 10)
class CWSourceSyncAction(action.Action): __regid__ = 'cw.source-sync' __select__ = (action.Action.__select__ & match_user_groups('managers') & one_line_rset() & is_instance('CWSource') & score_entity(lambda x: x.name != 'system')) title = _('synchronize') category = 'mainactions' order = 20 def url(self): entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) return entity.absolute_url(vid=self.__regid__)
class CWSourceSyncView(EntityView): __regid__ = 'cw.source-sync' __select__ = (match_user_groups('managers') & one_line_rset() & is_instance('CWSource') & score_entity(lambda x: x.name != 'system')) title = _('synchronize') def entity_call(self, entity): import_log_eid = self._cw.call_service('source-sync', source_eid=entity.eid) msg = self._cw._( 'Synchronization has been requested, refresh this page in a few ' 'minutes.') import_log = self._cw.entity_from_eid(import_log_eid) url = import_log.absolute_url(__message=msg) raise Redirect(url)
class AttachmentsDownloadBox(component.EntityCtxComponent): """ A box containing all downloadable attachments concerned by Person. """ __regid__ = 'drh.concerned_by_box' __select__ = (component.EntityCtxComponent.__select__ & is_instance('Person') & score_entity(lambda x: x.concerned_by)) title = _('concerned_by') order = 0 def render_body(self, w): for attachment in self.entity.concerned_by: idownloadable = attachment.cw_adapt_to('IDownloadable') w(u'<div><a href="%s"><img src="%s" alt="%s"/> %s</a>' % (xml_escape(idownloadable.download_url()), self._cw.uiprops['DOWNLOAD_ICON'], _('download icon'), xml_escape(attachment.dc_title()))) w(u'</div>')
class ViewSameCWEType(action.Action): """when displaying the schema of a CWEType, offer to list entities of that type """ __regid__ = 'entitiesoftype' __select__ = one_line_rset() & is_instance('CWEType') & score_entity( lambda x: not x.final) category = 'mainactions' order = 40 @property def etype(self): return self.cw_rset.get_entity(0, 0).name @property def title(self): return self._cw.__('view all %s') % display_name( self._cw, self.etype, 'plural').lower() def url(self): return self._cw.build_url(self.etype)
class TimeSeriesPlotView(baseviews.EntityView): __regid__ = 'ts_plot' __select__ = is_instance( 'TimeSeries', 'NonPeriodicTimeSeries') & score_entity(lambda x: not x.is_constant) title = None onload = u"init_ts_plot('%(figid)s', [%(plotdata)s]);" def dump_plot(self, ts): plot = [(datetime2ticks(x), y) for x, y in ts.compressed_timestamped_array()] return dumps(plot) def call(self, width=None, height=None): req = self._cw w = self.w if req.ie_browser(): req.add_js('excanvas.js') req.add_js(('jquery.flot.js', 'jquery.flot.selection.js', 'cubes.timeseries.js')) width = width or req.form.get('width', 700) height = height or req.form.get('height', 400) figid = u'figure%s' % req.varmaker.next() w( t.div(u'', id='main%s' % figid, style='width: %spx; height: %spx;' % (width, height))) w( t.div(u'', id='overview%s' % figid, style='width: %spx; height: %spx;' % (width, height / 3))) w(t.button(req._('Zoom reset'), id='reset', klass='validateButton')) plotdata = ("{label: '%s', data: %s}" % (xml_escape(ts.dc_title()), self.dump_plot(ts)) for ts in self.cw_rset.entities()) req.html_headers.add_onload(self.onload % { 'figid': figid, 'plotdata': ','.join(plotdata) })
class WFHistoryView(EntityView): __regid__ = 'wfhistory' __select__ = (relation_possible('wf_info_for', role='object') & score_entity(lambda x: x.cw_adapt_to('IWorkflowable'). workflow_history)) title = _('Workflow history') def cell_call(self, row, col, view=None, title=title): _ = self._cw._ eid = self.cw_rset[row][col] sel = 'Any FS,TS,C,D' rql = ' ORDERBY D DESC WHERE WF wf_info_for X,'\ 'WF from_state FS, WF to_state TS, WF comment C,'\ 'WF creation_date D' if self._cw.vreg.schema.eschema('CWUser').has_perm(self._cw, 'read'): sel += ',U,WF' rql += ', WF owned_by U?' headers = (_('from_state'), _('to_state'), _('comment'), _('date'), _('CWUser')) else: sel += ',WF' headers = (_('from_state'), _('to_state'), _('comment'), _('date')) sel += ',FSN,TSN,CF' rql = '%s %s, FS name FSN, TS name TSN, WF comment_format CF, X eid %%(x)s' % ( sel, rql) try: rset = self._cw.execute(rql, {'x': eid}) except Unauthorized: return if rset: if title: self.w(u'<h2>%s</h2>\n' % _(title)) self.wview('table', rset, headers=headers, cellvids={2: 'editable-final'})