Opened 16 years ago

Closed 16 years ago

#7316 closed (fixed)

Use ugettext_lazy instead of ugettext in contrib.localflavor

Reported by: Manuel Saelices Owned by: Manuel Saelices
Component: contrib.localflavor Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are many files in localflavor that uses ugettext for defining fields and widgets, for example:

from django.utils.translation import ugettext

class NOSocialSecurityNumber(Field):
    """
    Algorithm is documented at http://no.wikipedia.org/wiki/Personnummer
    """
    default_error_messages = {
        'invalid': ugettext(u'Enter a valid Norwegian social security number.'),
    }
...

This can produce a serious problem (in production server), because two things:

  1. String translation is got in import time, for example when web server starts. This string will never change.
  2. This is the most important problem: You could have error with circulars import, because gettext call will try import all applications installed on Django, but this file haven't loaded yet. I had this problem with Apache for a import cycle, because a contrib.localflavor import. This is not acceptable.

I will attach a patch for fix this problem.

Attachments (1)

localflavor_r7554.diff (20.9 KB ) - added by Manuel Saelices 16 years ago.
Patch that fixes problem.

Download all attachments as: .zip

Change History (3)

by Manuel Saelices, 16 years ago

Attachment: localflavor_r7554.diff added

Patch that fixes problem.

comment:1 by Simon Greenhill, 16 years ago

Triage Stage: UnreviewedReady for checkin

comment:2 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(In [7689]) Fixed #7554 -- Modified contrib.localflavor to make use of ugettext, rather than ugettext. Thanks to msaelices for the report and patch.

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