Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#8107 closed (fixed)

Invalid HTML output generated for BooleanFields using Python 2.3

Reported by: RaceCondition <eallik@…> Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


Using ugettext_lazy, the following model results in invalid HTML generated in the admin area.

class Page(models.Model):
    """A simple hierarchical page model"""
    STATUSES = (
        (STATUS_DRAFT, _('Draft')),
        (STATUS_PUBLISHED, _('Published')),
    title = models.CharField(_('title'), max_length=100)
    body = models.TextField(_('body'), blank=True, help_text=_('Only use the enter/return key for creating new paragraphs, try not to use any line breaks.'))
    slug = models.SlugField(_('slug'), blank=True)
    parent = models.ForeignKey('self', verbose_name=_('parent'), related_name="children", blank=True, null=True)
    order = models.PositiveSmallIntegerField(_('order'))
    creation_date = models.DateTimeField(_('creation date'), editable=False,
    publication_date = models.DateTimeField(_('publication date'), editable=False, null=True)
    published = models.BooleanField(_('is published'), default=False)
    is_folder = models.BooleanField(_('is folder'), default=False)

Generated HTML for the two BooleanFields:

<div class="form-row published">
	<input type="checkbox" name="published" id="id_published" /><label for="id_published" class="vCheckboxLabel"><django.utils.functional.__proxy__ object at 0x2aa3374990></label>
<div class="form-row is_folder">
	<input type="checkbox" name="is_folder" id="id_is_folder" /><label for="id_is_folder" class="vCheckboxLabel"><django.utils.functional.__proxy__ object at 0x2aa3374950></label>

Attachments (1)

boolean.diff (567 bytes) - added by Bjorn Kristinsson 10 years ago.
Possible fix, based on malcolmt's suggestions

Download all attachments as: .zip

Change History (7)

comment:1 Changed 10 years ago by Erik Allik

The file for this app contains:

from django.contrib import admin
from pages.models import Page

class PageAdmin(admin.ModelAdmin):
    list_display = ('title', 'parent', 'order', 'get_absolute_url', 'published', )

def register_models(site):
    site.register(Page, PageAdmin)

comment:2 Changed 10 years ago by Erik Allik

Forgot to mention that it only happens when using "from django.utils.translation import ugettext_lazy" as opposed to "from django.utils.translation import ugettext".

comment:3 Changed 10 years ago by Bjorn Kristinsson

At least I can confirm this is not a problem in Python 2.5... Had been trying to reproduce it without success before noticing it affects 2.3 :P

Changed 10 years ago by Bjorn Kristinsson

Attachment: boolean.diff added

Possible fix, based on malcolmt's suggestions

comment:4 Changed 10 years ago by Bjorn Kristinsson

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

comment:5 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [8245]) Fixed #8107 -- Fixed a missing forced_unicode() call in admin. Patch from

comment:6 Changed 7 years ago by Jacob

milestone: 1.0 beta

Milestone 1.0 beta deleted

Note: See TracTickets for help on using tickets.
Back to Top