Hi there,

I encountered what seems to be a bug in newforms-admin. Before I open
a ticket, I want to be sure it is indeed a bug. (I'm new to Django, so
thanks for being patient.)

When using RadioSelect as the custom widget for a DB field in newforms-
admin, I get the following error:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
TypeError at /admin/****/****/add/
sequence item 0: expected string or Unicode, RadioFieldRenderer found

Request Method: GET
Request URL:    http://127.0.0.1:8000/admin/****/****/add/
Exception Type: TypeError
Exception Value:        sequence item 0: expected string or Unicode,
RadioFieldRenderer found
Exception Location:     /Library/Frameworks/Python.framework/Versions/2.4/
lib/python2.4/site-packages/django/contrib/admin/widgets.py in
__call__, line 91
Python Executable:      /Library/Frameworks/Python.framework/Versions/2.4/
Resources/Python.app/Contents/MacOS/Python
Python Version: 2.4.4
Template error

In template /Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/site-packages/django/contrib/admin/templates/admin/
change_form.html, error at line 55
Caught an exception while rendering: sequence item 0: expected string
or Unicode, RadioFieldRenderer found
45          <fieldset class="module aligned {{ bfset.fieldset.classes }}">
46          {% if bfset.fieldset.name %}<h2>{{ bfset.fieldset.name }}</
h2>{% endif %}
47          {% if bfset.fieldset.description %}<div
class="description">{{ bfset.fieldset.description }}</div>{% endif %}
48          {% for line in bfset %}
49              <div class="form-row{% if line.errors %} errors{% endif
%}">
50              {{ line.errors }}
51              {% for field in line %}
52                  {% if field.is_checkbox %}
53                      {{ field.field }}{{ field.label_tag }}
54                  {% else %}
55                      {{ field.label_tag }}{{ field.field }}
56                  {% endif %}
57                  {% if field.field.field.help_text %}<p
class="help">{{ field.field.field.help_text }}</p>{% endif %}
58              {% endfor %}
59              </div>
60          {% endfor %}
61          </fieldset>
62      {% endfor %}
63
64      {% block after_field_sets %}{% endblock %}
65
Traceback (innermost last)

Switch to copy-and-paste view

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/template/__init__.py in render_node
            result = node.render(context) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/template/__init__.py in render
        return self.encode_output(output) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/template/__init__.py in encode_output
                return str(output) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/utils/encoding.py in __str__
        return self.__unicode__().encode(settings.DEFAULT_CHARSET) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/newforms/forms.py in __unicode__
        value = self.as_widget(self.field.widget) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/newforms/forms.py in as_widget
        return widget.render(self.html_name, data, attrs=attrs) ...
▶ Local vars
/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-
packages/django/contrib/admin/widgets.py in __call__
        return u''.join(output) ...
▶ Local vars
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


As you can see, the template is expecting a unicode object, but the
RadioSelect widget returns a RadioFieldRenderer object.

I was able to get around this problem by subclassing RadioSelect and
adding to its render method:


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
class AdminRadioSelect(forms.widgets.RadioSelect):
        def render(self, name, value, attrs=None, choices=()):
                renderer =
super(AdminRadioSelect,self).render(name,value,attrs,choices)
                return renderer.__unicode__()
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Is this indeed a bug, or am I missing something?

Cheers,
Leif


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to