Esempio n. 1
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))
Esempio n. 2
0
 def to_python(self, value):
     for key2, value2 in self.choices:
         if key2 == value or force_text(key2) == value:
             if isinstance(key2, int):
                 return int(value)
             elif isinstance(key2, float):
                 return float(value)
     return value
Esempio n. 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)
Esempio n. 4
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))
Esempio n. 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))
Esempio n. 6
0
 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))