示例#1
0
文件: form.py 项目: emragins/tribal
    def input_group(self,
                    request,
                    content,
                    model,
                    groupValues,
                    inputType,
                    templateAttributes={}):
        """
        Base code for a group of objects.  Checkgroup will use this, as
        well as radiogroup.  In the attributes, rows means how many rows
        the group should be arranged into, cols means how many cols the
        group should be arranged into.  Columns take precedence over
        rows: if both are specified, the output will always generate the
        correct number of columns.  However, if the number of elements
        in the group exceed (or is smaller than) rows*cols, then the
        number of rows will be off.  A cols attribute of 1 will mean that
        all the elements will be listed one underneath another.  The
        default is a rows attribute of 1:  everything listed next to each
        other.
        """
        rows = model.getHint('rows', templateAttributes.get('rows', None))
        cols = model.getHint('cols', templateAttributes.get('cols', None))
        if rows:
            rows = int(rows)
        if cols:
            cols = int(cols)

        defaults = self.getValues(request, model)
        if (rows and rows > 1) or (cols and cols > 1):  #build a table
            s = content.table(border="0")
            if cols:
                breakat = cols
            else:
                breakat = math.ceil(float(len(groupValues)) / rows)
            for i in range(0, len(groupValues), breakat):
                tr = s.tr()
                for j in range(0, breakat):
                    if i + j >= len(groupValues):
                        break
                    tag, value, desc = groupValues[i + j]
                    kw = {}
                    if value in defaults:
                        kw = {'checked': '1'}
                    tr.td().input(type=inputType,
                                  name=model.name,
                                  value=tag,
                                  **kw).text(desc)

        else:
            s = content.div()
            for tag, value, desc in groupValues:
                kw = {}
                if value in defaults:
                    kw = {'checked': '1'}
                s.input(type=inputType, name=model.name, value=tag,
                        **kw).text(desc)
                if cols:
                    s.br()

        return s
示例#2
0
 def input_text(self, request, content, model, templateAttributes={}):
     r = content.textarea(
         cols=str(model.getHint('cols',
                                templateAttributes.get('cols', '60'))),
         rows=str(model.getHint('rows',
                                templateAttributes.get('rows', '10'))),
         name=model.name,
         wrap=str(model.getHint('wrap',
                                templateAttributes.get('wrap', "virtual"))))
     r.text(str(self.getValue(request, model)))
     return r
示例#3
0
文件: form.py 项目: emragins/tribal
 def input_text(self, request, content, model, templateAttributes={}):
     r = content.textarea(
         cols=str(
             model.getHint('cols', templateAttributes.get('cols', '60'))),
         rows=str(
             model.getHint('rows', templateAttributes.get('rows', '10'))),
         name=model.name,
         wrap=str(
             model.getHint('wrap',
                           templateAttributes.get('wrap', "virtual"))))
     r.text(str(self.getValue(request, model)))
     return r
示例#4
0
    def input_group(self, request, content, model, groupValues, inputType,
                    templateAttributes={}):
        """
        Base code for a group of objects.  Checkgroup will use this, as
        well as radiogroup.  In the attributes, rows means how many rows
        the group should be arranged into, cols means how many cols the
        group should be arranged into.  Columns take precedence over
        rows: if both are specified, the output will always generate the
        correct number of columns.  However, if the number of elements
        in the group exceed (or is smaller than) rows*cols, then the
        number of rows will be off.  A cols attribute of 1 will mean that
        all the elements will be listed one underneath another.  The
        default is a rows attribute of 1:  everything listed next to each
        other.
        """
        rows = model.getHint('rows', templateAttributes.get('rows', None))
        cols = model.getHint('cols', templateAttributes.get('cols', None))
        if rows:
            rows = int(rows)
        if cols:
            cols = int(cols)
            
        defaults = self.getValues(request, model)
        if (rows and rows>1) or (cols and cols>1):  #build a table
            s = content.table(border="0")
            if cols:
                breakat = cols
            else:
                breakat = math.ceil(float(len(groupValues))/rows)
            for i in range(0, len(groupValues), breakat):
                tr = s.tr()
                for j in range(0, breakat):
                    if i+j >= len(groupValues):
                        break
                    tag, value, desc = groupValues[i+j]
                    kw = {}
                    if value in defaults:
                        kw = {'checked' : '1'}
                    tr.td().input(type=inputType, name=model.name,
                        value=tag, **kw).text(desc)
                        
        else:
            s = content.div()
            for tag, value, desc in groupValues:
                kw = {}
                if value in defaults:
                    kw = {'checked' : '1'}
                s.input(type=inputType, name=model.name,
                        value=tag, **kw).text(desc)
                if cols:
                    s.br()

        return s
示例#5
0
 def input_file(self, request, content, model, templateAttributes={}):
     kw = {}
     for attrib in ['size', 'accept']:
         val = model.getHint(attrib, templateAttributes.get(attrib, None))
         if val:
             kw[attrib] = str(val)
     return content.input(type="file", name=model.name, **kw)
示例#6
0
文件: form.py 项目: emragins/tribal
    def input_single(self, request, content, model, templateAttributes={}):
        """
        Returns a text input node built based upon the node model.
        Optionally takes an already-coded DOM node merges that
        information with the model's information.  Returns a new (??)
        lmx node.
        """
        #in a text field, only the following options are allowed (well, more
        #are, but they're not supported yet - can add them in later)
        attribs = ['type', 'name', 'value', 'size', 'maxlength',
                   'readonly']  #only MSIE recognizes readonly and disabled

        arguments = {}
        for attrib in attribs:
            #model hints and values override anything in the template
            val = model.getHint(attrib, templateAttributes.get(attrib, None))
            if val:
                arguments[attrib] = str(val)

        value = self.getValue(request, model)
        if value:
            arguments["value"] = str(value)

        arguments["type"] = "text"  #these are default
        arguments["name"] = model.name

        return content.input(**arguments)
示例#7
0
文件: form.py 项目: emragins/tribal
 def input_verifiedpassword(self,
                            request,
                            content,
                            model,
                            templateAttributes={}):
     breakLines = model.getHint('breaklines', 1)
     values = self.getValues(request, model)
     if isinstance(values, (str, unicode)):
         values = (values, values)
     if not values:
         p1, p2 = "", ""
     elif len(values) == 1:
         p1, p2 = values, ""
     elif len(values) == 2:
         p1, p2 = values
     else:
         p1, p2 = "", ""
     div = content.div()
     div.text("Password: "******"password", size="20", name=model.name, value=str(p1))
     if breakLines:
         div.br()
     div.text("Verify: ")
     div.input(type="password", size="20", name=model.name, value=str(p2))
     return div
示例#8
0
文件: form.py 项目: emragins/tribal
 def input_file(self, request, content, model, templateAttributes={}):
     kw = {}
     for attrib in ['size', 'accept']:
         val = model.getHint(attrib, templateAttributes.get(attrib, None))
         if val:
             kw[attrib] = str(val)
     return content.input(type="file", name=model.name, **kw)
示例#9
0
文件: form.py 项目: emragins/tribal
 def input_date(self, request, content, model, templateAttributes={}):
     breakLines = model.getHint('breaklines', 1)
     date = self.getValues(request, model)
     if date == None:
         year, month, day = "", "", ""
     else:
         year, month, day = date
     div = content.div()
     div.text("Year: ")
     div.input(type="text",
               size="4",
               maxlength="4",
               name=model.name,
               value=str(year))
     if breakLines:
         div.br()
     div.text("Month: ")
     div.input(type="text",
               size="2",
               maxlength="2",
               name=model.name,
               value=str(month))
     if breakLines:
         div.br()
     div.text("Day: ")
     div.input(type="text",
               size="2",
               maxlength="2",
               name=model.name,
               value=str(day))
     return div
示例#10
0
    def input_single(self, request, content, model, templateAttributes={}):
        """
        Returns a text input node built based upon the node model.
        Optionally takes an already-coded DOM node merges that
        information with the model's information.  Returns a new (??)
        lmx node.
        """
        #in a text field, only the following options are allowed (well, more
        #are, but they're not supported yet - can add them in later)
        attribs = ['type', 'name', 'value', 'size', 'maxlength',
                   'readonly'] #only MSIE recognizes readonly and disabled

        arguments = {}
        for attrib in attribs:
            #model hints and values override anything in the template
            val = model.getHint(attrib, templateAttributes.get(attrib, None))
            if val:
                arguments[attrib] = str(val)
            
        value = self.getValue(request, model)
        if value:
            arguments["value"] = str(value)

        arguments["type"] = "text"  #these are default
        arguments["name"] = model.name

        return content.input(**arguments)
示例#11
0
 def input_choice(self, request, content, model, templateAttributes={}):
     arguments = {}
     val = model.getHint("onChange", templateAttributes.get("onChange", None))
     if val:
         arguments["onChange"] = val
     arguments["name"] = model.name
     s = content.select(**arguments)
     default = self.getValues(request, model)
     for tag, value, desc in model.choices:
         kw = {}
         if value in default:
             kw = {'selected' : '1'}
         s.option(value=tag, **kw).text(desc)
     return s
示例#12
0
 def input_submit(self, request, content, model, templateAttributes={}):
     arguments = {}
     val = model.getHint("onClick", templateAttributes.get("onClick", None))
     if val:
         arguments["onClick"] = val
     arguments["type"] = "submit"
     arguments["name"] = model.name
     div = content.div()
     for tag, value, desc in model.choices:
         args = arguments.copy()
         args["value"] = tag
         div.input(**args)
         div.text(" ")
     if model.reset:
         div.input(type="reset")
     return div
示例#13
0
文件: form.py 项目: emragins/tribal
 def input_choice(self, request, content, model, templateAttributes={}):
     # am I not evil? allow onChange js events
     arguments = {}
     val = model.getHint("onChange",
                         templateAttributes.get("onChange", None))
     if val:
         arguments["onChange"] = val
     arguments["name"] = model.name
     s = content.select(**arguments)
     default = self.getValues(request, model)
     for tag, value, desc in model.choices:
         kw = {}
         if value in default:
             kw = {'selected': '1'}
         s.option(value=tag, **kw).text(desc)
     return s
示例#14
0
文件: form.py 项目: emragins/tribal
 def input_submit(self, request, content, model, templateAttributes={}):
     arguments = {}
     val = model.getHint("onClick", templateAttributes.get("onClick", None))
     if val:
         arguments["onClick"] = val
     arguments["type"] = "submit"
     arguments["name"] = model.name
     div = content.div()
     for tag, value, desc in model.choices:
         args = arguments.copy()
         args["value"] = tag
         div.input(**args)
         div.text(" ")
     if model.reset:
         div.input(type="reset")
     return div
示例#15
0
 def input_date(self, request, content, model, templateAttributes={}):
     breakLines = model.getHint('breaklines', 1)
     date = self.getValues(request, model)
     if date == None:
         year, month, day = "", "", ""
     else:
         year, month, day = date
     div = content.div()
     div.text("Year: ")
     div.input(type="text", size="4", maxlength="4", name=model.name, value=str(year))
     if breakLines:
         div.br()
     div.text("Month: ")
     div.input(type="text", size="2", maxlength="2", name=model.name, value=str(month))
     if breakLines:
         div.br()
     div.text("Day: ")
     div.input(type="text", size="2", maxlength="2", name=model.name, value=str(day))
     return div
示例#16
0
 def input_single(self, request, content, model, templateAttributes={}):
     """
     Returns a text input node built based upon the node model.
     Optionally takes an already-coded DOM node merges that
     information with the model's information.  Returns a new (??)
     lmx node.
     """
     attribs = ['type', 'name', 'value', 'size', 'maxlength',
                'readonly'] #only MSIE recognizes readonly and disabled
     arguments = {}
     for attrib in attribs:
         val = model.getHint(attrib, templateAttributes.get(attrib, None))
         if val:
             arguments[attrib] = str(val)
     value = self.getValue(request, model)
     if value:
         arguments["value"] = str(value)
     arguments["type"] = "text"  #these are default
     arguments["name"] = model.name
     return content.input(**arguments)
示例#17
0
 def input_verifiedpassword(self, request, content, model, templateAttributes={}):
     breakLines = model.getHint('breaklines', 1)
     values = self.getValues(request, model)
     if isinstance(values, (str, unicode)):
         values = (values, values)
     if not values:
         p1, p2 = "", ""
     elif len(values) == 1:
         p1, p2 = values, ""
     elif len(values) == 2:
         p1, p2 = values
     else:
         p1, p2 = "", ""
     div = content.div()
     div.text("Password: "******"password", size="20", name=model.name, value=str(p1))
     if breakLines:
         div.br()
     div.text("Verify: ")
     div.input(type="password", size="20", name=model.name, value=str(p2))
     return div