Exemple #1
0
    def handleField(self, form, f, tr, table, colspan=0, fromList=0):
        if not fromList:
            # if we are not coming from a list [aka handleList()],
            # then this method must check for errors itself
            errTr = ecs.Tr()
            numErr = self.handleError(form, errTr, f)
            if numErr:
                table.addElement(errTr)

        if not hasattr(f, "getView"):
            return 
            
        if f.description:
            desTd = ecs.Td().addElement(f.description)
            vwTd = ecs.Td().addElement(f.getView())
            desTd.setAttribute('valign', 'top')
            vwTd.setAttribute('valign', 'top')
            if colspan:
                vwTd.setAttribute('colspan', colspan)
            tr.addElement(desTd)
            tr.addElement(vwTd)
        else:
            td=ecs.Td().addElement(f.getView())
            td.setAttribute('valign', 'top')
            if colspan:
                td.setAttribute('colspan', colspan)
            else:
                td.setAttribute('colspan', '2')
            tr.addElement(td)
        tr.addElement('\n')
        return 
Exemple #2
0
    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
Exemple #3
0
 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
Exemple #4
0
    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
Exemple #5
0
 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)
Exemple #6
0
 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
Exemple #7
0
 def handleError(self, form, tr, fld):
     numErrs = 0
     if form.errors:
         msgs=form.errors.get(fld)
         if msgs:
             msg='\n'.join([x.errormsg for x in msgs])
             numErrs = numErrs + 1
             em=ecs.Em(msg).setAttribute('class', 'form_error')
             pr = ecs.Pre(em)
             td=ecs.Td(pr).setAttribute('colspan', '2')
             tr.addElement(td)
     return numErrs    
Exemple #8
0
    def handleList(self, form, list, tr, table):
        errTr = ecs.Tr()
        ttlErr = 0
        for fnm in list:
            fld = form.fields[fnm]
            # handle the errors display...these will always span two columns
            numErrs = self.handleError(form, errTr, fld)
            if not numErrs:
                # if there were no errors, we need to add an empty TD for
                #this field's error
                errTr.addElement(ecs.Td().setAttribute('colspan', '2')\
                                 .addElement("&nbsp;"))
            else:
                # increment the total number of errors
                ttlErr = ttlErr + numErrs
                                 
        if ttlErr:
            table.addElement(errTr)
        
        # some rows may have less items than the max depth, in which case we should
        # not span the remaining columns or a very ugly GUI is created
        colspan = 0
        lstLen = len(list)
        if lstLen < form.maxDepth:
            # note that there are 2 <td> cells for each item in any row
            colspan = 2 * (form.maxDepth - lstLen)
        
        for idx in range(0, lstLen):
            fnm = list[idx]
            fld = form.fields[fnm]

            if not hasattr(fld, "getView"):
                return
            
            if idx == lstLen - 1:
                # if we are on the last column, add the colspan, else add no
                #colspan
                self.handleField(form, fld, tr, table, colspan, fromList=1)
            else:
                self.handleField(form, fld, tr, table, 0, fromList=1)