field.label in template converts to lower case in 1.2.1

22 views
Skip to first unread message

Jeff Green

unread,
Jul 29, 2010, 5:42:30 PM7/29/10
to Django users
With Django 1.2.1 it seems that my html template causes the
field.label to display
in lower case except for the first character. Has anyone experienced
this before and how do you
get it display without lower case conversion


My html template snippet is:

{% for field in form %}

{{ field.label_tag}}

Thanks,
Jeff

Jason

unread,
Jul 29, 2010, 6:02:45 PM7/29/10
to Django users
I think Django's been doing that for a long time (not just 1.2.1).

Probably the quick and easy way to change case would be to use just
field.label and pump it into whatever format you want:

{{ field.label|upper }}

You'll have to manually create the rest of the html for the label
using field.html_name

I've run into some slight problems figuring out the proper id's for
the corresponding labels... Normally it's just
id_{{ field.html_name }} but if you get into auto_id's as well as
labels for more complex things (radio button lists, etc) it can get a
little bit funky.

Jeff Green

unread,
Jul 29, 2010, 6:17:31 PM7/29/10
to django...@googlegroups.com
For example, the field name is Programmer Serial Number but it is being displayed
as Programmer serial number
 
I have not had this issue in 1.1.1. I was wondering if there was a way to ignore the conversion.

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


Jason

unread,
Jul 29, 2010, 6:31:13 PM7/29/10
to Django users
Post the form class (or model if you are generating it from a model).

On Jul 29, 3:17 pm, Jeff Green <jeffhg2...@gmail.com> wrote:
> For example, the field name is Programmer Serial Number but it is being
> displayed
> as Programmer serial number
>
> I have not had this issue in 1.1.1. I was wondering if there was a way to
> ignore the conversion.
>
> > django-users...@googlegroups.com<django-users%2Bunsu...@googlegroups.com>
> > .

Jeff Green

unread,
Jul 30, 2010, 8:26:31 AM7/30/10
to django...@googlegroups.com
Here is my form class
 
class StationInfo( forms.Form):
 
    def __init__( self, *args, **kwargs):
        super( StationInfo, self).__init__( *args, **kwargs)

        request = args[1]
        selecttuple = "choice0", "--Select One--"

        userid = threadlocals.get_current_user()
        user = '%s' % userid
        userrec = User.objects.get(username=user)
        projrecs = UserProj.objects.filter( User=userrec)
        self.projlist = []
        phaselist = []
        for proj in projrecs:
            self.projlist.append( proj.ProjectId)

        # Get all the configurations for a station
        stationrec = request.session['stationrec']
        configlist1 = Configuration.objects.filter( ConfigurationType='Station', AdditionalEquipFlag=False)
        configlist2 = Configuration.objects.filter( ConfigurationType='Station',
                    AdditionalEquipFlag=True).order_by('ConfigurationName')
        configlist = list(chain(configlist1, configlist2))

        for config in configlist:
            config_str = '%s' % config
            foundconfig = True
            # Get station configuration record for given station
            configstr_list = []
            try:
                stationconfiglist = StationConfig.objects.filter(
                    ConfigValueId__ConfigurationId__ConfigurationName=config.ConfigurationName,
                    EndDate__isnull=True,
                    StationId=stationrec
                    )
                if len(stationconfiglist) == 0:
                    foundconfig = False
                else:
                    for stationconfigrec in stationconfiglist:
                        configstr = '%s' % stationconfigrec.ConfigValueId
                        configstr_list.append( configstr)

            except:
                foundconfig = False

            # Get choice list
            choicelist = []
            if config_str == 'Phase' or config_str == 'Project':
                configvalues = ConfigValues.objects.filter(
                    ConfigurationId__ConfigurationName=config.ConfigurationName
                    ).order_by( 'ConfigValue')
            else:
                configvalues = ConfigValues.objects.filter(
                    ConfigurationId__ConfigurationName=config.ConfigurationName,
                    ProjectId__in = self.projlist).order_by( 'ConfigValue')
            if not foundconfig:
                if config.MultiSelectFlag:
                    choicelist.append( selectmoretuple)
                else:
                    choicelist.append( selecttuple)
            select_fieldlist = []
            allchoiceslist = []
            for configrec in configvalues:
                configvalstr = '%s' % configrec
                allchoiceslist.append( configvalstr)
                choicestr = "choice%s" % str( configrec.id)
                choicetuple = choicestr, configrec.ConfigValue
                if configrec.ConfigValue in configstr_list:
                    choicelist.insert( 0, choicetuple)
                    select_fieldlist.append( choicestr)
                else:
                    choicelist.append( choicetuple)

            for stationconfigrec in stationconfiglist:
                configstr = str( stationconfigrec.ConfigValueId)
                # Tried if not in list but it gave incorrect result
                found = False
                for choice in allchoiceslist:
                    if configstr == choice:
                        found = True
                        break
                if not found:
                    choicestr = "choice%s" % str( stationconfigrec.ConfigValueId.id)
                    choicetuple = choicestr, configstr
                    choicelist.insert( 0, choicetuple)
                    select_fieldlist.append( choicestr)

            if config.MultiSelectFlag:

                self.fields[config.ConfigurationName] = forms.MultipleChoiceField(
                        choices=choicelist,
                        required=False,
                        widget = MyMultiSelectWidget(initial=select_fieldlist ))
 

            else:
                print 'config name is ', config.ConfigurationName
                self.fields[config.ConfigurationName] = forms.ChoiceField(
                                        choices=choicelist,
                                        required=False)
            if config.ExpireFlag:
                for stationconfigrec in stationconfiglist:
                    config_valuestr = '%s' % stationconfigrec.ConfigValueId
                    print 'config value string is ', config_valuestr
                    fieldname = ( config_valuestr + ' ' +
                                config.ConfigurationName +
                                ' CalibrationDueDate (US/Central Time)')
                    print 'field name is ', fieldname
                    if stationconfigrec.ExpireDate == None:
                        self.fields[fieldname] = forms.SplitDateTimeField(
                        required=False,
                        widget = MySplitDateTimeWidget())
                    else:
                        startdatetime = '%s' % stationconfigrec.ExpireDate
                        datelist = startdatetime.split(' ')
                        self.fields[fieldname] = forms.SplitDateTimeField(
                        required=False,
                        widget = MySplitDateTimeWidget(datevalue=datelist[0],
                        timevalue=datelist[1]))
            if config.ConfigurationName != 'Phase':
                delete_field = config.ConfigurationName + 'DeleteFlag'
                self.fields[delete_field] = forms.BooleanField(
                                        required=False)


 
To unsubscribe from this group, send email to django-users...@googlegroups.com.

Jason

unread,
Jul 30, 2010, 11:16:45 AM7/30/10
to Django users
Looks like you are generating the fields in two different cases.
Here's the second one:

self.fields[config.ConfigurationName] =
forms.ChoiceField(
choices=choicelist,
required=False)

Change that to:

self.fields[config.ConfigurationName] =
forms.ChoiceField(
label =
config.ConfigurationName,
choices=choicelist,
required=False)


(and make the same change to the multiple select as well)

Assuming the ConfigurationName has proper capitalization it should
work.
> > <django-users%2Bunsu...@googlegroups.com<django-users%252Buns...@googlegroups.com>

Jason

unread,
Jul 30, 2010, 11:23:09 AM7/30/10
to Django users
Actually - make that change to the rest of the field options too. The
word wrap threw me off there at the end.
> ...
>
> read more »

Jeff Green

unread,
Jul 30, 2010, 12:03:46 PM7/30/10
to django...@googlegroups.com
Thanks Jason! That fixed the issue.

To unsubscribe from this group, send email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages