Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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: UI/UX:

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 bjornkri 6 years ago.
Possible fix, based on malcolmt's suggestions

Download all attachments as: .zip

Change History (7)

comment:1 Changed 6 years ago by RaceCondition

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 6 years ago by RaceCondition

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 6 years ago by bjornkri

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 6 years ago by bjornkri

Possible fix, based on malcolmt's suggestions

comment:4 Changed 6 years ago by bjornkri

  • Has patch set
  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 6 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:6 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.