from scaffold.core.widget import base_widget class control(base_widget): method = 'post' action = '/' template = { 'text':'''
%s
'''} def create(self, action, method='post', title=None): self.inputs = [] self.action = action self.method = method return self @staticmethod def set_template(template): if template: control.template = template def append(self, input_type, input_name, label,values="", input_id=None, classes='validate', placeholder='', disabled='', selected=None): if input_type == 'select' and values: if type(values) is not list or tuple: form_control = """""" % ( input_name, input_name, "\n".join(["""""" % (value, value) for value in values])) self.apply_template(input_type, form_control) return self if len(values[0]) == 2: form_control = """ """ % ( input_name, input_name, "\n".join(["""""" % (value, item) for value, item in values])) else: form_control = """ """ % ( input_name, input_name, "\n".join(["""""" % (item, item) for item in values])) self.apply_template(input_type, form_control) return self form_control = """ """ % ( input_type, input_name, input_id if input_id else '', label, 'disabled="disabled" ' if disabled else '', classes, values, 'checked="checked"' if selected else '', input_id if input_id else '', label) self.apply_template(input_type, form_control) return self def apply_template(self, input_type, form_control): return self.inputs.append( control.template.get(input_type, "%s
") % form_control) def render(self): super(control, self).render() # send return """