Opened 16 years ago

Closed 16 years ago

Last modified 13 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: dev
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

Description

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

class Page(models.Model):
    """A simple hierarchical page model"""
    
    STATUS_DRAFT = 0
    STATUS_PUBLISHED = 1
    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, default=datetime.now)
    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>
<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>
</div>

Attachments (1)

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

Download all attachments as: .zip

Change History (7)

comment:1 by Erik Allik, 16 years ago

The admin.py 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 by Erik Allik, 16 years ago

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 by Bjorn Kristinsson, 16 years ago

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

by Bjorn Kristinsson, 16 years ago

Attachment: boolean.diff added

Possible fix, based on malcolmt's suggestions

comment:4 by Bjorn Kristinsson, 16 years ago

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

comment:5 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

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

comment:6 by Jacob, 13 years ago

milestone: 1.0 beta

Milestone 1.0 beta deleted

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