def render_option(self, selected_choices, option_value, option_label): if option_value is None: option_value = '' option_value = force_text(option_value) if option_value in selected_choices: selected_html = mark_safe(' selected="selected"') if not self.allow_multiple_selected: # Only allow for a single selection. selected_choices.remove(option_value) else: selected_html = '' # Pass the default location capacity as an option if option_value: this_location = Location.objects.filter( id=int(option_value)).first() defaultCapacity = this_location.defaultCapacity room_options = [{ 'id': x.id, 'name': x.name, 'defaultCapacity': x.defaultCapacity } for x in this_location.room_set.all()] extra_value_data = format_html( ' data-defaultCapacity="{}" data-roomOptions="{}"', defaultCapacity, json.dumps(room_options)) else: extra_value_data = '' return format_html('<option value="{}"{}{}>{}</option>', option_value, mark_safe(selected_html), extra_value_data, force_text(option_label))
def render(self, name, value, attrs=None): textinput = super(TextInput, self).render(name, value, attrs) if self.available_tags: showmorestr = _('Show Tags') showlessstr = _('Hide Tags') tags = "" for tag in self.available_tags: if tags: tags += '<span class="gray">|</span> <a href="" class="addtag_%(name)s" title="%(tag)s">%(tag)s</a> '%{'tag': tag,'name':name} else: tags += '<a href="" class="addtag_%(name)s" title="%(tag)s">%(tag)s</a> '%{'tag': tag,'name':name} js=''' <script type="text/javascript"> $(document).ready(function() { $("#extrainfo_%(name)s").hide(); $("a.addtag_tags").click(function() { val = $("#id_%(name)s").val(); newval = $(this).attr('title'); if (val.indexOf(' '+newval+ ',') == -1 && val.indexOf(','+newval+ ',') == -1 && val.indexOf(newval+ ',') == -1){ if (val == '') val = newval+ ', '; else val = val + newval+ ', '; $("#id_%(name)s").val(val) $(this).toggleClass('gray') } return false; }); $("a#click_extrainfo_%(name)s").toggle( function() { $("#extrainfo_%(name)s").slideDown('fast'); $("a#click_extrainfo_%(name)s").text("%(showlessstr)s"); }, function() { $("#extrainfo_%(name)s").slideUp('fast'); $("a#click_extrainfo_%(name)s").text("%(showmorestr)s"); } ); }); </script>'''%{'name':name, 'showlessstr': showlessstr, 'showmorestr': showmorestr } div=''' <a href="" id="click_extrainfo_%(name)s">%(showmorestr)s</a> <div id="extrainfo_%(name)s"> <br/> %(tags)s </div> '''%{'name': name, 'tags': tags, 'showmorestr': showmorestr} return mark_safe(u'%s %s %s' % (textinput,js, div)) else: return mark_safe(u'%s' % (textinput))
def render(self, name, value, attrs=None, renderer=None, choices=(('', '---------'), )): if value is None: value = '' final_attrs = self.build_attrs(attrs, {'name': name}) output = [] if len(value) == 0: output.append(format_html('<select{}>', flatatt(final_attrs))) options = self.render_options(choices, [value]) if options: output.append(options) output.append('</select>') else: for val in value: output.append(format_html('<select{}>', flatatt(final_attrs))) options = self.render_options(choices, [val]) if options: output.append(options) output.append('</select>') output.append('<p><a href="#" class="addNewItem">Add Another</a></p>') return mark_safe('\n'.join(output))
def clean(self): super(RegistrationContactForm,self).clean() first = self.cleaned_data.get('firstName') last = self.cleaned_data.get('lastName') email = self.cleaned_data.get('email') # Check that this customer is not already registered for any of the Events in the list customer = Customer.objects.filter( first_name=first, last_name=last, email=email).first() if customer: eventids = [x.event.id for x in self._registration.temporaryeventregistration_set.all()] already_registered_list = customer.getSeriesRegistered().filter(id__in=eventids) else: already_registered_list = [] if already_registered_list: error_list = '\n'.join(['<li>%s</li>' % (x.name,) for x in already_registered_list]) raise ValidationError(ugettext(mark_safe('You are already registered for:\n<ul>\n%s\n</ul>\nIf you are registering another person, please enter their name.' % error_list))) # Allow other handlers to add validation errors to the form. Also, by passing the request, we allow # those handlers to add messages to the request, which (for this form) are treated like errors in that # they prevent the form from being considered valid. check_student_info.send(sender=RegistrationContactForm,instance=self,formData=self.cleaned_data,request=self._request,registration=self._registration) return self.cleaned_data
def render(self, name, value, attrs=None): html = '<div class="input-group colorpicker-addon"><span class="input-group-addon"><i></i></span>%s</div>' html += ('<script type="application/javascript" defer>' '$(document).ready(' 'function () { $(".colorpicker-addon").colorpicker({align: "left", format: "hex"}); ' '});</script>') return mark_safe(html % super(ColorPickerWidget, self).render(name, value, attrs))
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, name, value, attrs=None): output = super(AutosizedTextarea, self).render(name, value, attrs) output += mark_safe( '<script type="text/javascript">' '$(document).ready(function () { $("#id_%s").attr("rows", 1).autosize().css("resize", "vertical"); });' '</script>' % name) return output
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=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=()): 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(self, selected_choices, option_value, option_label): if option_value is None: option_value = '' option_value = force_text(option_value) if option_value in selected_choices: selected_html = mark_safe(' selected="selected"') if not self.allow_multiple_selected: # Only allow for a single selection. selected_choices.remove(option_value) else: selected_html = '' return format_html('<option value="{}"{}>{}</option>', option_value, selected_html, force_text(option_label))
def render(self, name, value, attrs=None): output = [] output.append('<table>') for (id,app) in permissions.apps: tid = "%s_%s"%(name,id) if value: tval = value.get(tid) else: tval = None output.append('<tr><td>%s: </td><td>%s</td></tr>'%(app, Select(choices=self.ch).render(tid, tval, {'id': tid})) ) output.append('</table>') return mark_safe(u'\n'.join(output))
def render(self, name, value, attrs=None): output = [] output.append('<table>') for (id, app) in permissions.apps: tid = "%s_%s" % (name, id) if value: tval = value.get(tid) else: tval = None output.append( '<tr><td>%s: </td><td>%s</td></tr>' % (app, Select(choices=self.ch).render(tid, tval, {'id': tid}))) output.append('</table>') return mark_safe(u'\n'.join(output))
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): id_ = self.attrs.get('id', None) start_tag = format_html(u'<ul class="category_ul" id="{0}">', id_) if id_ else u'<ul>' output = [start_tag] old_level = 0 for i, choice in enumerate(self.choices): level_dashes = gre_get_level.findall(choice[1])[0] choice = (choice[0], choice[1].replace(level_dashes, "")) level = level_dashes.count(u"-") if level != old_level: if level > old_level: for j in range(0, level-old_level): output.append(u'<ul>') else: for j in range(0, old_level-level): output.append(u'</ul>') old_level = level w = self.choice_input_class(self.name, self.value, self.attrs.copy(), choice, i) output.append(format_html(u'<li>{0}</li>', force_text(w))) output.append(u'</ul>') return mark_safe('\n'.join(output))
def render_option(self, selected_choices, option_value, option_label): if option_value is None: option_value = '' option_value = force_text(option_value) if option_value in selected_choices: selected_html = mark_safe(' selected="selected"') if not self.allow_multiple_selected: # Only allow for a single selection. selected_choices.remove(option_value) else: selected_html = '' # Pass the default wage rate as an option if option_value: defaultCapacity = Location.objects.filter( id=int(option_value)).first().defaultCapacity extra_value_data = ' data-defaultCapacity=' + str(defaultCapacity) else: extra_value_data = '' return format_html('<option value="{}"{}{}>{}</option>', option_value, selected_html, extra_value_data, force_text(option_label))
def render(self): return mark_safe(u'\n%s\n' % u'\n'.join([u'%s' % force_unicode(w) for w in self]))
def render(self, name, value, attrs=None): textinput = super(TextInput, self).render(name, value, attrs) if self.available_tags: showmorestr = _('Show Tags') showlessstr = _('Hide Tags') tags = "" for tag in self.available_tags: if tags: tags += '<span class="gray">|</span> <a href="" class="addtag_%(name)s" title="%(tag)s">%(tag)s</a> ' % { 'tag': tag, 'name': name } else: tags += '<a href="" class="addtag_%(name)s" title="%(tag)s">%(tag)s</a> ' % { 'tag': tag, 'name': name } js = ''' <script type="text/javascript"> $(document).ready(function() { $("#extrainfo_%(name)s").hide(); $("a.addtag_tags").click(function() { val = $("#id_%(name)s").val(); newval = $(this).attr('title'); if (val.indexOf(' '+newval+ ',') == -1 && val.indexOf(','+newval+ ',') == -1 && val.indexOf(newval+ ',') == -1){ if (val == '') val = newval+ ', '; else val = val + newval+ ', '; $("#id_%(name)s").val(val) $(this).toggleClass('gray') } return false; }); $("a#click_extrainfo_%(name)s").toggle( function() { $("#extrainfo_%(name)s").slideDown('fast'); $("a#click_extrainfo_%(name)s").text("%(showlessstr)s"); }, function() { $("#extrainfo_%(name)s").slideUp('fast'); $("a#click_extrainfo_%(name)s").text("%(showmorestr)s"); } ); }); </script>''' % { 'name': name, 'showlessstr': showlessstr, 'showmorestr': showmorestr } div = ''' <a href="" id="click_extrainfo_%(name)s">%(showmorestr)s</a> <div id="extrainfo_%(name)s"> <br/> %(tags)s </div> ''' % { 'name': name, 'tags': tags, 'showmorestr': showmorestr } return mark_safe(u'%s %s %s' % (textinput, js, div)) else: return mark_safe(u'%s' % (textinput))
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, extra_attrs={'name': name}) output = [ u'', ] # Separate out regular choices and override-only choices all_choices = list(chain(self.choices, choices)) override_choices = [ x for x in all_choices if isinstance(x[1], dict) and 'override' in x[1].keys() and x[1]['override'] ] regular_choices = [x for x in all_choices if x not in override_choices] # Normalize to strings str_values = set([force_text(v, encoding='utf-8') for v in value]) if regular_choices: output.append(u'<ul class="list-unstyled">') for i, (option_value, option_label) in enumerate(regular_choices): if 'disabled' in final_attrs: del final_attrs['disabled'] if isinstance(option_label, dict): if dict.get(option_label, 'disabled'): final_attrs = dict(final_attrs, disabled='disabled') option_label = option_label['label'] # 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_text(option_value, encoding='utf-8') rendered_cb = cb.render(name, option_value) option_label = conditional_escape( force_text(option_label, encoding='utf=8')) output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label)) output.append(u'</ul>') if override_choices: # Determine whether or not to add a Submit button submit_button_flag = False # Create an ID for the collapse if has_id: collapse_id = 'override_' + str(attrs['id']) else: collapse_id = 'override_' + str(int(random() * 10.0**12)) output.append( u'<button class="btn btn-outline-secondary btn-sm mb-4" type="button" data-toggle="collapse" data-target="#%(id)s">%(string)s</button><div class="collapse" id="%(id)s"><ul class="list-unstyled">' % { 'id': collapse_id, 'string': _('Additional Choices') }) for i, (option_value, option_label) in enumerate(override_choices): if 'disabled' in final_attrs: del final_attrs['disabled'] if isinstance(option_label, dict): if dict.get(option_label, 'disabled'): final_attrs = dict(final_attrs, disabled='disabled') if dict.get(option_label, 'closed'): submit_button_flag = True option_label = option_label['label'] # 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_text(option_value, encoding='utf=8') rendered_cb = cb.render(name, option_value) option_label = conditional_escape( force_text(option_label, encoding='utf=8')) output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label)) if submit_button_flag: output.append( u'<input class="btn btn-outline-primary btn-sm" type="submit" value="%s »" />' % _('Register now')) output.append(u'</ul></div>') return mark_safe(u'\n'.join(output))
def render(self, name, value, attrs=None): html = '<p class="form-control-static">%s</p>' % value return mark_safe(html)
def render(self, name, value, attrs, choices=()): html = u'<br><div class="topicSelection">' for i in range(1, self.topic_count+1): html += (u'<input type="checkbox" id="' + self.content_type + '_' + str(i) + u'" value="' + str(i) + u'"name="topics"/>') html += u'</div>' return widgets.mark_safe(html)
def render(self, name, value, attrs=None): return mark_safe('<input name="%s" />' % LOGIN_USER_NAME)
def render(self, name, value, attrs=None): html = super(WYSIHTML5Widget, self).render(name, value, attrs) html += ('<script type="application/javascript" defer>' '$(document).ready(function () {{$("#id_{0}").wysihtml5()}});' '</script>'.format(name)) return mark_safe(html)
def __unicode__(self): choice_label = conditional_escape(force_text(self.choice_label)) return mark_safe(u'%s %s' % (self.tag(), choice_label))
def render(self): """ Outputs radio fields wrapped in p-tags. """ return mark_safe(u'\n'.join([ u'<p>%s</p>' % force_text(w) for w in self]))