def getView(self): elem=ecs.Form() if self.method: elem.setAttribute('method', self.method) if self.enctype: elem.setAttribute('enctype', self.enctype) if self.action: elem.setAttribute('action', self.action) elem.attributes.update(self.view_attrs) if self.name: elem.setAttribute('name', self.name) table=ecs.Table() table.addElement('\n') top_level_errors=self.errors.get(self) if top_level_errors: top_level_error='<br />'.join([x.errormsg for x \ in top_level_errors]) em=ecs.Em(top_level_error).setAttribute('class', 'form_error') tr=ecs.Tr().addElement(ecs.Td(em)\ .setAttribute('colspan', str(2 * self.maxDepth))) table.addElement(tr) table.addElement('\n') self.layout.layoutFields(self, table) elem.addElement('\n') elem.addElement(table) elem.addElement('\n') return elem
def getView(self): tr=ecs.Tr() for val, label in self.options: b=ecs.Button(label, attributes={'name' : self.name, 'value': htmlquote(str(val))}) tr.addElement(ecs.Td(b)) return ecs.Table(tr)
def getView(self): table=ecs.Table() tr=ecs.Tr() for o in self.options: tr.addElement(ecs.Td(o.getView())) table.addElement(tr) table.attributes.update(self.view_attrs) return table
def layoutFields(self, form, table=None): """\ Arranges the given form's ViewableField list into a flow layout, disregarding any nesting within the field list... all items are arranged in a single row following the order of the field list from the first index of the list [and the first index of any nested list] to the last index: [1, [2,3], 4, [5,6,7]] produces <table> <tr> <td>1.description</td><td>1.getView()</td> <td>2.description</td><td>2.getView()</td> <td>3.description</td><td>3.getView()</td> <td>4.description</td><td>4.getView()</td> <td>5.description</td><td>5.getView()</td> <td>6.description</td><td>6.getView()</td> <td>7.description</td><td>7.getView()</td> </tr> </table> """ if table is None: table=ecs.Table() errTr = ecs.Tr() numErr = 0 for fld in form.fields: numErr = numErr + self.handleError(form, errTr, fld) if numErr: table.addElement(errTr) tr = ecs.Tr() for fld in form.fields: if not hasattr(fld, "getView"): continue if fld.description: desTd = ecs.Td().addElement(fld.description) vwTd = ecs.Td().addElement(fld.getView()) desTd.setAttribute('valign', 'top') vwTd.setAttribute('valign', 'top') tr.addElement(desTd) tr.addElement(vwTd) else: td=ecs.Td().addElement(fld.getView()) td.setAttribute('valign', 'top') td.setAttribute('colspan', '2') tr.addElement(td) tr.addElement('\n') table.addElement(tr) return table
def getView(self): # this is a little more speculative than for a select, # since it consists of multiple elements. Override this # at will; it is meant to be visually adequate but no more. table=ecs.Table() for o in self.options: self._update_checked_state(o) tr=ecs.Tr().addElement(ecs.Td(o.description)) tr.addElement(ecs.Td().addElement(o.getView())) table.addElement(tr) table.attributes.update(self.view_attrs) return table
def layoutFields(self, form, table=None): """\ Arranges the given form's ViewableField list into a tabular display based upon the nesting of the given field list... column spanning is based upon the maximum depth of the largest nested list: [1, [2,3], 4, [5,6,7]] produces <table> <tr> <td>1.description</td><td colspan="5">1.getView()</td> </tr> <tr> <td>2.description</td><td>2.getView()</td> <td>3.description</td><td colspan="3">3.getView()</td> </tr> <tr> <td>4.description</td><td colspan="5">4.getViews()</td> </tr> <tr> <td>5.description</td><td>5.getView()</td> <td>6.description</td><td>6.getView()</td> <td>7.description</td><td>7.getView()</td> </tr> </table> where ecs.Table is returned by the method: 1) if a table was passed to the method, the same table is returned with the fields laid out inside it 2) if a table was not passed, the default table is generated and returned with the fields laid out """ if table is None: table=ecs.Table() for tstFnm in form.fieldLayout: tr=ecs.Tr() if isinstance(tstFnm, list) or isinstance(tstFnm, tuple): self.handleList(form, tstFnm, tr, table) else: self.handleField(form, form.fields[tstFnm], tr, table) table.addElement(tr) table.addElement('\n') return table