def render_options(self, choices, selected_choices, disabled_choices): def render_option(option_value, option_label): option_value = force_unicode(option_value) ## This next line adds a mesasge after the label for the option. Modify as needed ## option_label = (option_value in disabled_choices) and (force_unicode(option_label) + ' - SOLD OUT') or force_unicode(option_label) selected_html = (option_value in selected_choices) and ' selected="selected"' or '' disabled_html = (option_value in disabled_choices) and ' disabled="disabled"' or '' return '<option value="%s"%s%s>%s</option>' % ( escape(option_value), selected_html, disabled_html, conditional_escape(option_label)) # Normalize to strings. selected_choices = set([force_unicode(v) for v in selected_choices]) disabled_choices = set([force_unicode(v) for v in disabled_choices]) output = [] for option_value, option_label in chain(self.choices, choices): if isinstance(option_label, (list, tuple)): output.append('<optgroup label="%s">' % escape(force_unicode(option_value))) for option in option_label: output.append(render_option(*option)) output.append('</optgroup>') else: output.append(render_option(option_value, option_label)) return '\n'.join(output) ##====================================================================================##
def render(self, name, value, attrs=None, choices=()): PERSON_COL = 3 tmpcol = 1 old_group = None if value is None: value = [] has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) output = [u'<table width="100%">'] # Normalize to strings str_values = set([force_unicode(v) for v in value]) for i, (option_value, user) in enumerate(chain(self.choices, choices)): # If an ID attribute was given, add a numeric index as a suffix, # so that the checkboxes don't all have the same ID attribute. if has_id: final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) label_for = u' for="%s"' % final_attrs['id'] else: label_for = '' cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) rendered_cb = cb.render(name, force_unicode(option_value)) #do group if old_group != user.get_profile().company: if tmpcol > 1: for i in range(tmpcol, PERSON_COL + 1): output.append('<td></td>') output.append(u'</tr>') output.append( u'<tr><td colspan="%(col)s"><p style="margin: 15px 0 10px 0;"><a class="smallcaps_title blue_bg white" href="">%(name)s</a></p></td></tr>' % { 'col': PERSON_COL, 'name': user.get_profile().company.short_name }) tmpcol = 1 old_group = user.get_profile().company #do user u = self.myrender(user, label_for, rendered_cb) if tmpcol == 1: u = '<tr>' + u tmpcol += 1 elif tmpcol == PERSON_COL: u += '</tr>' tmpcol = 1 else: tmpcol += 1 output.append(u) if tmpcol > 1: for i in range(tmpcol, PERSON_COL + 1): output.append('<td></td>') output.append(u'</tr>') output.append(u'</table>') return mark_safe(u'\n'.join(output))
def render_option(option_value, option_label): option_value = force_unicode(option_value) ## This next line adds a mesasge after the label for the option. Modify as needed ## option_label = (option_value in disabled_choices) and (force_unicode(option_label) + ' - SOLD OUT') or force_unicode(option_label) selected_html = (option_value in selected_choices) and ' selected="selected"' or '' disabled_html = (option_value in disabled_choices) and ' disabled="disabled"' or '' return '<option value="%s"%s%s>%s</option>' % ( escape(option_value), selected_html, disabled_html, conditional_escape(option_label))
def render(self, name, value, attrs=None, choices=()): PERSON_COL=3 tmpcol = 1 old_group = None if value is None: value = [] has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) output = [u'<table width="100%">'] # Normalize to strings str_values = set([force_unicode(v) for v in value]) for i, (option_value, user) in enumerate(chain(self.choices, choices)): # If an ID attribute was given, add a numeric index as a suffix, # so that the checkboxes don't all have the same ID attribute. if has_id: final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) label_for = u' for="%s"' % final_attrs['id'] else: label_for = '' cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) rendered_cb = cb.render(name, force_unicode(option_value)) #do group if old_group != user.get_profile().company: if tmpcol > 1 : for i in range(tmpcol, PERSON_COL+1 ): output.append( '<td></td>' ) output.append(u'</tr>') output.append( u'<tr><td colspan="%(col)s"><p style="margin: 15px 0 10px 0;"><a class="smallcaps_title blue_bg white" href="">%(name)s</a></p></td></tr>'%{'col': PERSON_COL, 'name': user.get_profile().company.short_name} ) tmpcol = 1 old_group = user.get_profile().company #do user u = self.myrender(user, label_for, rendered_cb) if tmpcol == 1: u = '<tr>' + u tmpcol += 1 elif tmpcol == PERSON_COL: u += '</tr>' tmpcol = 1 else: tmpcol += 1 output.append( u ) if tmpcol > 1 : for i in range(tmpcol, PERSON_COL+1 ): output.append( '<td></td>' ) output.append(u'</tr>') output.append(u'</table>') return mark_safe(u'\n'.join(output))
def render(self, name, value, attrs=None): if value is None: value = [] final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) if value != '': # Only add the 'value' attribute if a value is non-empty. final_attrs['value'] = force_unicode(self._format_value(value)) return mark_safe(u'<input%s />' % flatatt(final_attrs))
def render(self): """Outputs a <div> for this set of radio fields.""" if "id" in self.attrs: div_tag = ' id="%s"' % self.attrs["id"] else: div_tag = ' id="radio"' input_list = u"%s\n" % u"\n".join([u"%s\n" % force_unicode(w) for w in self]) return mark_safe(u"<div%s>%s</div>" % (div_tag, input_list))
def render(self, name, value, attrs=None, choices=()): if value is None: value = [] has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) output = [u'<ul class="inputs-list">'] # Normalize to strings str_values = set([widgets.force_unicode(v) for v in value]) for i, (option_value, option_label) in enumerate(widgets.chain(self.choices, choices)): # If an ID attribute was given, add a numeric index as a suffix, # so that the checkboxes don't all have the same ID attribute. if has_id: final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) cb = widgets.CheckboxInput(final_attrs, check_test=lambda value: value in str_values) option_value = widgets.force_unicode(option_value) rendered_cb = cb.render(name, option_value) option_label = widgets.force_unicode(option_label) # purposefully did not escape so I can get html in here output.append(u'<li><label>%s<span>%s</span></label></li>' % (rendered_cb, option_label)) output.append(u'</ul>') return widgets.mark_safe(u'\n'.join(output))
def render(self, name=None, value=None, attrs=None, choices=()): name = name or self.name value = value or self.value attrs = attrs or self.attrs if "id" in self.attrs: label_for = ' for="%s_%s"' % (self.attrs["id"], self.index) else: label_for = "" choice_label = conditional_escape(force_unicode(self.choice_label)) return mark_safe(u"%s<label%s>%s</label>" % (self.tag(), label_for, choice_label))
def render(self, name, value, attrs=None, choices=()): if value is None: value = [] has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) output = [u'<div class="landmarks-listing"><ul class="unstyled">'] # Normalize to strings str_values = set([force_unicode(v) for v in value]) for i, (option_value, option_label, option_detail) in enumerate(chain(self.choices, choices)): # If an ID attribute was given, add a numeric index as a suffix, # so that the checkboxes don't all have the same ID attribute. if has_id: final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) label_for = u' for="%s"' % final_attrs['id'] else: label_for = '' cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) option_value = force_unicode(option_value) option_detail = force_unicode(option_detail) rendered_cb = cb.render(name, option_value) option_label = conditional_escape(force_unicode(option_label)) output.append(u'<li><label%s>%s %s</label><div>%s</div></li>' % (label_for, rendered_cb, option_label, option_detail)) output.append(u'</ul></div><div id="landmark-details"></div><div class="clear"></div>') return mark_safe(u'\n'.join(output))
def render(self): return mark_safe(u'\n%s\n' % u'\n'.join([u'%s' % force_unicode(w) for w in self]))