def render(self, name, value, attrs=None): new_attrs = create_attributes(self, UNIVERSAL) # build a list of possible elements elements = single_attributes(self) substitutions = { "initial_text": self.initial_text, "input_text": self.input_text, "clear_template": "", "clear_checkbox_label": self.clear_checkbox_label, } template = u"%(input)s" substitutions["input"] = super(ClearableFileInput, self).render(name, value, attrs, new_attrs, elements) if value and hasattr(value, "url"): template = self.template_with_initial substitutions["initial"] = u'<a href="%s">%s</a>' % (escape(value.url), escape(force_unicode(value))) if not self.is_required: checkbox_name = self.clear_checkbox_name(name) checkbox_id = self.clear_checkbox_id(checkbox_name) substitutions["clear_checkbox_name"] = conditional_escape(checkbox_name) substitutions["clear_checkbox_id"] = conditional_escape(checkbox_id) substitutions["clear"] = CheckboxInput().render(checkbox_name, False, attrs={"id": checkbox_id}) substitutions["clear_template"] = self.template_with_clear % substitutions return mark_safe(template % substitutions)
def render(self, name, value, attrs=None): new_attrs = create_attributes(self, UNIVERSAL, TEXT_SEARCH) attrs.update(**new_attrs) elements = single_attributes(self) if value is None: value = "" final_attrs = self.build_attrs(attrs, name=name) return mark_safe( u"<textarea%s %s>%s</textarea>" % (flatatt(final_attrs), elements, conditional_escape(force_unicode(value))) )
def render(self, name, value, attrs=None, choices=()): new_attrs = create_attributes(self, UNIVERSAL) # build a list of possible elements elements = single_attributes(self) attrs.update(**new_attrs) output = list() for i, choice in enumerate(self.choices): output.append(RadioInput(name, value, attrs.copy(), choice, i, elements)) return mark_safe(u"<ul>\n%s\n</ul>" % u"\n".join([u"<li>%s</li>" % force_unicode(w) for w in output]))
def render(self, name, value, attrs=None, choices=()): if value is None: value = [] new_attrs = create_attributes(self, UNIVERSAL, TEXT_SEARCH) final_attrs = self.build_attrs(attrs, type=self.input_type, name=name, list=name, **new_attrs) output = list() output.append(u"<input%s />" % flatatt(final_attrs)) output.append(u'<datalist id="%(name)s">' % final_attrs) options = self.render_options(choices, value) if options: output.append(options) output.append(u"</datalist>") return mark_safe(u"\n".join(output))
def render(self, name, value, attrs=None, choices=()): new_attrs = create_attributes(self, UNIVERSAL, SELECT) # build a list of possible elements elements = single_attributes(self) if value is None: value = "" final_attrs = self.build_attrs(attrs, name=name, **new_attrs) output = [u'<select multiple="multiple"%s %s>' % (flatatt(final_attrs), elements)] options = self.render_options(choices, value) if options: output.append(options) output.append(u"</select>") return mark_safe(u"\n".join(output))
def tag(self): new_attrs = create_attributes(self, UNIVERSAL) # attrs.update(**new_attrs) self.attrs.update(**new_attrs) if self.elements: elements = self.elements else: elements = single_attributes(self) if "id" in self.attrs: self.attrs["id"] = "%s_%s" % (self.attrs["id"], self.index) final_attrs = dict(self.attrs, type="radio", name=self.name, value=self.choice_value) if self.is_checked(): final_attrs["checked"] = "checked" return mark_safe(u"<input%s %s>" % (flatatt(final_attrs), elements))
def render(self, name, value, attrs=None, elements=None, choices=()): new_attrs = create_attributes(self, UNIVERSAL, CHOICE) elements = single_attributes(self) final_attrs = self.build_attrs(attrs, name=name, type="checkbox", **new_attrs) try: result = self.check_test(value) except: # Silently catch exceptions result = False if result: final_attrs["checked"] = "checked" if value not in ("", True, False, None): # Only add the 'value' attribute if a value is non-empty. final_attrs["value"] = force_unicode(value) return mark_safe(u"<input%s %s>" % (flatatt(final_attrs), elements))
def render(self, name, value, attrs=None, choices=()): if value is None: value = [] new_attrs = create_attributes(self, UNIVERSAL, TEXT_SEARCH) final_attrs = self.build_attrs(attrs, type=self.input_type, name=name, **new_attrs) id_ = final_attrs.get("id", None) inputs = [] for i, v in enumerate(value): input_attrs = dict(value=force_unicode(v), **final_attrs) if id_: input_attrs["id"] = "%s_%s" % (id_, i) del input_attrs["type"] del input_attrs["value"] input_ = HiddenInput() input_.is_required = self.is_required inputs.append(input_.render(name, force_unicode(v), input_attrs)) return "\n".join(inputs)
def render(self, name, value, attrs=None, new_attrs=None, elements=None): # build a list of possible elements if not elements: elements = single_attributes(self) if not new_attrs: # below removes empty attributes and also removes dictionary of attributes that are not longer necessary new_attrs = create_attributes(self, UNIVERSAL, TEXT_SEARCH) if value is None: value = "" # set default final_attrs = self.build_attrs(attrs, type=self.input_type, name=name, **new_attrs) if value != "": # Only add the 'value' attribute if a value is non-empty. # This adds non-dictionary items to the input field such as required final_attrs["value"] = force_unicode(value) return mark_safe(u"<input%s %s>" % (flatatt(final_attrs), elements))
def render(self, name, value, attrs=None): new_attrs = create_attributes(self, UNIVERSAL, PASSWORD, RANGE) if value is None: value = "" return HTML5Input.render(self, name, value, attrs, new_attrs)
def render(self, name, value, attrs): new_attrs = create_attributes(self, UNIVERSAL, TIME_NUMERIC) return HTML5Input.render(self, name, value, attrs, new_attrs)
def render(self, name, value, attrs): new_attrs = create_attributes(self, UNIVERSAL, TEXT_SEARCH) return HTML5Input.render(self, name, value, attrs, new_attrs)
def render(self, name, value, attrs=None): new_attrs = create_attributes(self, UNIVERSAL, PASSWORD) if not self.render_value: value = None return HTML5Input.render(self, name, value, attrs, new_attrs)