Example #1
0
  def render(self, name, value, attrs=None):
    if not value: value = ""
    value = smart_unicode(value)

    values = simplejson.dumps(self.values,ensure_ascii=False)
    
    if not self.tokens: tokens = ""
    if self.tokens: tokens = ", tokens: '%s'" % self.tokens
    
    if not self.minChars: minChars = ""
    if self.minChars: minChars = ", minChars: '%s'" % self.minChars
    s = u''
    return u"""<input id="id_%s" name="%s" value="%s" type="text" autocomplete="off" %s>
    <div id="id_%supdate" class=autocomplete style="display:none;border:1px solid black;background-color:white;height:150px;overflow:auto;"></div>
           <script type="text/javascript" language="javascript" charset="utf-8">
           // <![CDATA[
             new Autocompleter.Local('id_%s','id_%supdate', %s, { fullSearch: true, partialSearch: true, frequency:0.001 %s %s });
           // ]]>
           </script>""" % (name, name, value, flatatt(self.attrs), name, name, name, values, minChars, tokens)
Example #2
0
 def render(self, name, value, attrs=None, choices=()):
     from django.utils.html import escape
     from django.newforms.util import flatatt, smart_unicode 
     if value is None: value = '' 
     final_attrs = self.build_attrs(attrs, name=name) 
     output = [u'<select%s>' % flatatt(final_attrs)] 
     str_value = smart_unicode(value)
     for group_label, group in self.choices: 
         if group_label: # should belong to an optgroup
             group_label = smart_unicode(group_label) 
             output.append(u'<optgroup label="%s">' % escape(group_label)) 
         for k, v in group:
             option_value = smart_unicode(k)
             option_label = smart_unicode(v) 
             selected_html = (option_value == str_value) and u' selected="selected"' or ''
             output.append(u'<option value="%s"%s>%s</option>' % (escape(option_value), selected_html, escape(option_label))) 
         if group_label:
             output.append(u'</optgroup>') 
     output.append(u'</select>') 
     return u'\n'.join(output)
Example #3
0
 def render(self):
     """Outputs a <ul> for this set of radio fields."""
     return mark_safe(u'<ul%s>\n%s\n</ul>' % (
         flatatt(self.attrs),
         u'\n'.join([u'<li>%s</li>' % force_unicode(w) for w in self]))
     )
Example #4
0
 def fields(self, name, value, count, attrs=None):
     """
     Renders the necessary number of file input boxes.
     """
     return u''.join([u'<input%s />\n' % flatatt(dict(attrs, id=attrs['id']+str(i))) for i in range(count)])