class MonnaiePrimaryView(tabs.TabbedPrimaryView): __select__ = tabs.PrimaryTab.__select__ & is_instance('Monnaie') tabs = [ _('tab_monnaie'), _('tab_changes'), ] default_tab = 'tab_monnaie'
class TimepointFacet(facet.RQLPathFacet): __regid__ = "timepoint-facet" __select__ = is_instance("CWUpload") path = ["X related_processing P", "P status S"] order = 1 filter_variable = "S" title = _("Status")
class ResultFormPrimaryView(PrimaryView): """ Class that define how to display an UploadForm entity. The table display may be tuned by specifing the 'upload-table' class in a css. """ __select__ = PrimaryView.__select__ & is_instance("UploadForm") def display_form(self, entity): """ Generate the html code. """ # Get the source entity src_entity = entity.reverse_result_form[0] # Switch base on the source entity if isinstance(src_entity, CWUpload): # Get the json form json_data = json.load(entity.data) else: # Get the data from the description field json_data = {} if entity.description is not None and len(entity.description) > 2: for splitter in ["returncode: ", "stdout: ", "stderr: "]: json_data[splitter[:-2]] = entity.description[1:-1].split( splitter)[1] for key, value in json_data.iteritems(): for splitter in ["returncode: ", "stdout: ", "stderr: "]: value = value.split(splitter)[0] json_data[key] = value # Display a title self.w(u'<div class="page-header">') self.w(u'<h2>{0}</h2>'.format(xml_escape(entity.dc_title()))) self.w(u'</div>') self.w(u'<table class="upload-table">') # Display the form for label, attribute in json_data.iteritems(): self.w(u'<tr><td><b>{0}</b></td><td>{1}</td></tr>'.format( self._cw._(label), attribute)) # Link to the upload entity self.w(u'<tr><td></td><td>{0}</td></tr>'.format( src_entity.view("outofcontext"))) self.w(u'</table>') def call(self, rset=None): """ Create the form primary view. """ # Get the entity that contains the form entity = self.cw_rset.get_entity(0, 0) # Display the form self.display_form(entity)
class ChangeOOCTView(baseviews.OutOfContextTextView): """:__regid__: *textoutofcontext* Similar to the `text` view, but called when an entity is considered out of context (see description of outofcontext HTML view for more information on this). By default it displays what's returned by the `dc_long_title()` method of the entity. """ __regid__ = 'textoutofcontext2' __select__ = baseviews.OutOfContextTextView.__select__ & is_instance( 'Change') def cell_call(self, row, col): entity = self.cw_rset.get_entity(row, col) self.w(entity.dc_long_title2())
class ChangeOOCView(baseviews.OutOfContextView): __regid__ = 'outofcontext2' __select__ = baseviews.OutOfContextView.__select__ & is_instance('Change') def cell_call(self, row, col): entity = self.cw_rset.get_entity(row, col) desc = entity.dc_description() self.w(u'<a href="%s" title="%s">' % (xml_escape(entity.absolute_url()), xml_escape(desc))) self.w( xml_escape( self._cw.view('textoutofcontext2', self.cw_rset, row=row, col=col))) self.w(u'</a>')
class CWProcessingPrimaryView(PrimaryView): """ Class that define how to display a CWUpload entity. The table display may be tuned by specifing the 'upload-table' class in a css. """ __select__ = PrimaryView.__select__ & is_instance("CWUpload") def display_form(self, entity): """ Generate the html code. """ # Generate the html entity html table entity_html = "<table style='width:90%'>" for parameter_name in ["title", "form_name"]: entity_html += "<tr><td><b>{0}</b></td><td>{1}</td>".format( parameter_name, entity.__dict__["cw_attr_cache"][parameter_name]) entity_html += "<tr><td></td><td>{0}</td>".format( entity.related_processing[0].view("outofcontext")) entity_html += "</table>" # Generate the html result html result_form = entity.result_form[0] result_form_image = u"<img alt='' src='{0}'>".format( result_form.icon_url()) result_html = "<div class='primaryRight'><div class='contextFreeBox rsetbox'>" result_html += "<div class='boxTitle'><span>Submitted task</span></div>" result_html += ( "<div class='boxBody'>{0}<a href='{1}' title=''>parameters" "</a></div>".format(result_form_image, result_form.absolute_url())) # Generate the html form html table form_html = "<h1>Submitted task</h1>" form_html += ("<table><tr><td style='width: 100%'>{0}</td><td>{1}</td>" "</tr></table>".format(entity_html, result_html)) # Display a title self.w(unicode(form_html)) def call(self, rset=None): """ Create the form primary view. """ # Get the entity that contains the form entity = self.cw_rset.get_entity(0, 0) # Display the form self.display_form(entity)
class SaveTaskResultBox(component.CtxComponent): """ Display a box containing a download shortcut. """ __regid__ = "ctx-save-task-result" __select__ = (component.CtxComponent.__select__ & is_instance("CWUpload") & one_line_rset()) context = "left" title = _("Download result") order = 2 def render_body(self, w): """ Create a navigation box to dowload the results. """ w(u"<div class='btn-toolbar'>") w(u"<div class='btn-group-vertical btn-block'>") href = self._cw.build_url( "add/CWSearch", path=self.cw_rset.printable_rql()) w(u"<a class='btn btn-primary' href='{0}'>".format(href)) w(u"{0}</a>".format(self.title)) w(u"</div></div><br/>")
class TabChanges(EntityView): __regid__ = 'tab_changes' __select__ = one_line_rset & is_instance('Monnaie') def entity_call(self, entity): rql = ('Any C WHERE C is Change, ' 'EXISTS (C prix_depart P1, P1 monnaie M1, M1 eid %(eid)s) ' 'OR ' 'EXISTS (C prix_converti P2, P2 monnaie M2, M2 eid %(eid)s)') rset = self._cw.execute(rql, {'eid': entity.eid}) changed = {} for change in rset.entities(): m1 = change.prix_depart[0].monnaie[0] m2 = change.prix_converti[0].monnaie[0] if m2.eid == entity.eid: m1, m2 = m2, m1 changed.setdefault((m2.nom, m2.eid), []).append(change) import pprint #pprint.pprint(changed) all_values = [] for (name, other_monnaie_eid), changes in sorted(changed.items()): monnaie = self._cw.entity_from_eid(other_monnaie_eid) all_values.append( ("<h2>%s</h2>" % monnaie.view('incontext'), '', '')) values = [] for change in changes: try: val = u'%.4f' % (change.change(1, other_monnaie_eid)[0], ) except AssertionError: val = u'invalid' values.append((change.date, val, change.view('outofcontext2'))) values.sort() all_values += values if not all_values: all_values.append([_('no changes')]) self.wview('pyvaltable', None, 'null', pyvalue=all_values)
class MonnaieTab(tabs.PrimaryTab): __regid__ = 'tab_monnaie' __select__ = one_line_rset() & is_instance('Monnaie') title = None