Exemple #1
0
 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))
Exemple #2
0
    def render(self, name, value, attrs=None):

        # ng-model='checkin' is-open="opened" ng-focus="opened=true" datepicker-popup

        # or

        # <p class="input-group">
        #   <input type="text" class="form-control" ng-model='checkin' is-open="opened" ng-focus="opened=true" datepicker-popup  />
        #   <span class="input-group-btn">
        #     <button type="button" class="btn btn-default" ng-click="opened=true;$event.stopPropagation()"><i class="glyphicon glyphicon-calendar"></i></button>
        #   </span>
        # </p>

        attrs['ng-model'] = attrs['id']
        attrs['is-open'] = "%s_opened" % attrs['id']
        attrs['ng-focus'] = "%s_opened=true" % attrs['id']

        if value is None:
            value = ''

        attrs['ng-init'] = "%s='%s'" % (attrs['ng-model'],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_text(self._format_value(value))

        # print final_attrs
        # print flatatt(final_attrs)
        # print format_html('<input{0} datepicker-popup/>', flatatt(final_attrs))


        return format_html('<input{0} datepicker-popup/>', flatatt(final_attrs))
Exemple #3
0
 def render(self, name, value, attrs=None):
     if value is None:
         value = ''
     final_attrs = self.build_attrs(attrs, type='hidden', name=name)
     if value != '':
         final_attrs['value'] = widgets.force_text(value)
     return widgets.format_html('<input{0} />{1}',
                                widgets.flatatt(final_attrs),
                                value)
 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))
Exemple #5
0
    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'] = widgets.force_text(self._format_value(value))

        classes = 'autocomplete'
        if 'class' in final_attrs:
            classes += ' ' + final_attrs['class']

        return widgets.format_html('<input class="' + classes + '"{} />', widgets.flatatt(final_attrs))
Exemple #6
0
 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))
Exemple #7
0
    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'] = widgets.force_text(self._format_value(value))

        classes = 'autocomplete'
        if 'class' in final_attrs:
            classes += ' ' + final_attrs['class']

        return widgets.format_html('<input class="' + classes + '"{} />', widgets.flatatt(final_attrs))
Exemple #8
0
 def render_options(self, choices, selected_choices):
     # Normalize to strings.
     selected_choices = set(force_text(v) for v in selected_choices)
     output = []
     for option_value, option_label in chain(choices, self.choices):
         if isinstance(option_label, (list, tuple)):
             output.append(
                 format_html('<optgroup label="{}">',
                             force_text(option_value)))
             for option in option_label:
                 output.append(self.render_option(selected_choices,
                                                  *option))
             output.append('</optgroup>')
         else:
             output.append(
                 self.render_option(selected_choices, option_value,
                                    option_label))
     return '\n'.join(output)