Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Dateformat and escaped chars
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Waylan Limberg  
View profile  
 More options Mar 13 2006, 11:17 pm
From: "Waylan Limberg" <way...@gmail.com>
Date: Mon, 13 Mar 2006 23:17:53 -0500
Local: Mon, Mar 13 2006 11:17 pm
Subject: Dateformat and escaped chars
I'm trying to format my dates with escaped characters in the format.
However, I can only seem to get them to work with the 'now' template
tag, but not the 'date' filter. Some examples:

    {% now "jS o\f F" %}

will return '13th of March' as it should. But if I do this in the template:

    {{ post.pub_date|date:"jS o\f F" }}

I get '13th o9:54 March' instead.

from the shell:

>>> from django.utils.dateformat import *
>>> from datetime import datetime
>>> d = datetime.now()
>>> df = DateFormat(d)
>>> print df.format('jS o\f F')
13th o March
>>> df.format('jS o\f F')

'13th o\x0c March'

I just updated to lasted truck (revision 2521) with no change in
behavior. I'm running python 2.3 on Linux if that makes any
difference. I searched the tickets and didn't find any reference to my
problem. Am I missing something?
--
----
Waylan Limberg
way...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Malcolm Tredinnick  
View profile  
 More options Mar 13 2006, 11:39 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Tue, 14 Mar 2006 15:39:43 +1100
Local: Mon, Mar 13 2006 11:39 pm
Subject: Re: Dateformat and escaped chars

On Mon, 2006-03-13 at 23:17 -0500, Waylan Limberg wrote:
> I'm trying to format my dates with escaped characters in the format.
> However, I can only seem to get them to work with the 'now' template
> tag, but not the 'date' filter. Some examples:

>     {% now "jS o\f F" %}

> will return '13th of March' as it should. But if I do this in the template:

>     {{ post.pub_date|date:"jS o\f F" }}

> I get '13th o9:54 March' instead.

OK, that's a bug. The problem is that django,util,dateformat.format is
being passed the format string with the backslash already removed. Not
sure why that is happening yet, but it's a real bug.

I am not going to have time to look at it this afternoon, so you should
probably open a ticket for it so that we don't lose the problem report.

> from the shell:
> >>> from django.utils.dateformat import *
> >>> from datetime import datetime
> >>> d = datetime.now()
> >>> df = DateFormat(d)
> >>> print df.format('jS o\f F')
> 13th o March
> >>> df.format('jS o\f F')
> '13th o\x0c March'

This one is all your own doing. :-)

Remember that Python will do the first pass of backslash-removals first,
before it gets to your function call. And '\f' is the form-feed
character (ASCII code 12), just like \n is newline and \t is tab. If you
want to pass in the two character '\' and 'f', you either need to use
raw strings -- r'jS o\f F' -- or escape the backslash -- 'jS o\\f S' --
when trying to construct the string in Python.

Cheers,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Waylan Limberg  
View profile  
 More options Mar 14 2006, 12:36 am
From: "Waylan Limberg" <way...@gmail.com>
Date: Tue, 14 Mar 2006 00:36:16 -0500
Local: Tues, Mar 14 2006 12:36 am
Subject: Re: Dateformat and escaped chars
On 3/13/06, Malcolm Tredinnick <malc...@pointy-stick.com> wrote:

Wow! I found a "real bug". Anyway, submitted as Ticket #1498.

Doh! My bad.

--
----
Waylan Limberg
way...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Duncan Foster  
View profile  
 More options Mar 14 2006, 5:26 am
From: Duncan Foster <d...@europe.renre.com>
Date: Tue, 14 Mar 2006 10:26:09 +0000
Local: Tues, Mar 14 2006 5:26 am
Subject: Re: Dateformat and escaped chars

This is a duplicate of #1198. I took a look at this during the Django
sprint at PyCon. In django/template/__init__.py at line 524, the
contanst_arg is stripped of any backslashes. I'm not sure why this is
done; I'll leave the fix to those who understand the code a little
better than I do!

Duncan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »