Add from __future__ import unicode_literals, issue #37
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from itertools import chain
|
||||
import os
|
||||
|
||||
@@ -15,7 +17,7 @@ class PlainWidget(forms.widgets.Widget):
|
||||
widget and reduces the output to only it's value
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
return mark_safe(u'%s' % value)
|
||||
return mark_safe('%s' % value)
|
||||
|
||||
|
||||
class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
@@ -28,7 +30,7 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
value = ''
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
css_class = final_attrs.get('class', 'list')
|
||||
output = u'<ul class="%s">' % css_class
|
||||
output = '<ul class="%s">' % css_class
|
||||
options = None
|
||||
if value:
|
||||
if getattr(value, '__iter__', None):
|
||||
@@ -39,7 +41,7 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
self.choices if index == value]
|
||||
else:
|
||||
if self.choices:
|
||||
if self.choices[0] != (u'', u'---------') and value != []:
|
||||
if self.choices[0] != ('', '---------') and value != []:
|
||||
options = [(index, string) for index, string in
|
||||
self.choices]
|
||||
|
||||
@@ -47,16 +49,16 @@ class DetailSelectMultiple(forms.widgets.SelectMultiple):
|
||||
for index, string in options:
|
||||
if self.queryset:
|
||||
try:
|
||||
output += u'<li><a href="%s">%s</a></li>' % (
|
||||
output += '<li><a href="%s">%s</a></li>' % (
|
||||
self.queryset.get(pk=index).get_absolute_url(),
|
||||
string)
|
||||
except AttributeError:
|
||||
output += u'<li>%s</li>' % (string)
|
||||
output += '<li>%s</li>' % (string)
|
||||
else:
|
||||
output += u'<li>%s</li>' % string
|
||||
output += '<li>%s</li>' % string
|
||||
else:
|
||||
output += u'<li>%s</li>' % _(u'None')
|
||||
return mark_safe(output + u'</ul>\n')
|
||||
output += '<li>%s</li>' % _('None')
|
||||
return mark_safe(output + '</ul>\n')
|
||||
|
||||
|
||||
def exists_with_famfam(path):
|
||||
@@ -66,11 +68,11 @@ def exists_with_famfam(path):
|
||||
return exception
|
||||
|
||||
|
||||
def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross'):
|
||||
def two_state_template(state, famfam_ok_icon='tick', famfam_fail_icon='cross'):
|
||||
if state:
|
||||
return mark_safe(u'<span class="famfam active famfam-%s"></span>' % famfam_ok_icon)
|
||||
return mark_safe('<span class="famfam active famfam-%s"></span>' % famfam_ok_icon)
|
||||
else:
|
||||
return mark_safe(u'<span class="famfam active famfam-%s"></span>' % famfam_fail_icon)
|
||||
return mark_safe('<span class="famfam active famfam-%s"></span>' % famfam_fail_icon)
|
||||
|
||||
|
||||
class TextAreaDiv(forms.widgets.Widget):
|
||||
@@ -88,11 +90,11 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
if value is None:
|
||||
value = u''
|
||||
value = ''
|
||||
|
||||
flat_attrs = flatatt(self.build_attrs(attrs, name=name))
|
||||
content = conditional_escape(force_unicode(value))
|
||||
result = u'<pre%s>%s</pre>' % (flat_attrs, content)
|
||||
result = '<pre%s>%s</pre>' % (flat_attrs, content)
|
||||
return mark_safe(result)
|
||||
|
||||
|
||||
@@ -124,7 +126,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
value = []
|
||||
has_id = attrs and 'id' in attrs
|
||||
final_attrs = self.build_attrs(attrs, name=name)
|
||||
output = [u'<ul class="undecorated_list" style="margin-left: 5px; margin-top: 3px; margin-bottom: 3px;">']
|
||||
output = ['<ul class="undecorated_list" style="margin-left: 5px; margin-top: 3px; margin-bottom: 3px;">']
|
||||
# Normalize to strings
|
||||
str_values = set([force_unicode(v) for v in value])
|
||||
for i, (option_value, option_label) in enumerate(chain(self.choices, choices)):
|
||||
@@ -132,7 +134,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
# 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']
|
||||
label_for = ' for="%s"' % final_attrs['id']
|
||||
else:
|
||||
label_for = ''
|
||||
|
||||
@@ -140,7 +142,7 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
option_value = force_unicode(option_value)
|
||||
rendered_cb = cb.render(name, option_value)
|
||||
option_label = conditional_escape(force_unicode(option_label))
|
||||
output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
|
||||
output.append(u'</ul>')
|
||||
output.append('<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
|
||||
output.append('</ul>')
|
||||
|
||||
return mark_safe(u'<div class="text_area_div">%s</div>' % u'\n'.join(output))
|
||||
return mark_safe('<div class="text_area_div">%s</div>' % '\n'.join(output))
|
||||
|
||||
Reference in New Issue
Block a user