Django

Code

Ticket #4094 (new)

Opened 2 years ago

Last modified 6 months ago

databrowse calendars do not translate the month back to english resulting in an error

Reported by: lawgon <lawgon@thenilgiris.com> Assigned to: nickefford
Milestone: Component: django.contrib.databrowse
Version: SVN Keywords: sprintsept14
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When using databrowse in english, on selection of a year, the months are given. The url for clicking on a month would be ~/1998/feb/. This works. In finnish, on clicking the equivalent of february, the url becomes ~/1998/hel/ where 'hel' are the first three letters of the finnish equivalent of february. This obviously doesnt work.

Attachments

databrowse.diff (2.8 kB) - added by nickefford on 07/19/08 08:06:28.
New, refreshed version of the patch

Change History

04/21/07 07:45:07 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

I assume this is a generic i18n issue with databrowse?

04/22/07 08:14:48 changed by lawgon <lawgon@thenilgiris.com>

same problem in polish - so it must be i18n generic issue

04/26/07 07:41:54 changed by michal@plovarna.cz

Same in Czech language.

I looked into Django code and found, that calendar generate URLs with month presented as 3-letters text. And that is propably the reason of 404 page -- in my language I get ugly URLs like:

http://127.0.0.1:8000/databrowse/news/new/calendars/created/2007/b%C5%99e/ http://127.0.0.1:8000/databrowse/news/new/calendars/created/2007/z%C3%A1%C5%99/

It is not so common approach to represent month as 3-letter shortcuts in my country. In this situation will be better to represent month as number, ie:

http://127.0.0.1:8000/databrowse/news/new/calendars/created/2007/03/ http://127.0.0.1:8000/databrowse/news/new/calendars/created/2007/09/

In django/views/generic/date_based.py I found, that archive_month function have parameter month_format, but calendar_view (in django/contrib/databrowse.plugins/calendar.py) leave it to default value (%b).

Is it possible change the code to generate months in URLs as numbers, instead of 3-letter texts please?

08/20/07 05:41:48 changed by Simon G. <dev@simon.net.nz>

  • summary changed from when using finnish, databrowse with calendars does not translate the month back to english resulting in an error to databrowse calendars do not translate the month back to english resulting in an error.

09/14/07 11:45:51 changed by msgre

I try to solve it, but I am stuck, sorry.

What I found: I think, that problem is in strptime function (for example in django/views/generic/date_based.py line 119).

First, it is necessary to set correct locale. Next, if strptime gets date string as unicode, it throw exception UnicodeDecodeError?. But, if I put there same string, but not as unicode it is successfull:

import locale
locale.setlocale(locale.LC_TIME, 'cs_CZ.UTF-8')
from time import strptime
strptime(u'2007kvě', '%Y%b') # this throw UnicodeDecodeError exception
strptime('2007kvě', '%Y%b') # this is OK (see, date string isn't unicode, but it contain unicode character)

09/15/07 05:28:03 changed by Fredrik Lundh <fredrik@pythonware.com>

Should the URI really used localized names? Wouldn't numbers or english names be more robust?

(the Unicode issues for CZ is different from the original case for FI, but a non-localized fix would solve both, I think).

09/15/07 18:34:54 changed by nickefford

  • owner changed from nobody to nickefford.

09/16/07 10:31:12 changed by nickefford

  • keywords set to sprintsept14.
  • has_patch set to 1.

I'm submitting a patch that fixes this by using numeric months in the URLs, as suggested by michal & fredrik. The patch also fixes a bug in the heading displayed by the calendar_month.html template.

07/19/08 08:06:28 changed by nickefford

  • attachment databrowse.diff added.

New, refreshed version of the patch

07/19/08 08:11:10 changed by nickefford

I've updated the patch to be against a more recent trunk (post-nfa merge).


Add/Change #4094 (databrowse calendars do not translate the month back to english resulting in an error)




Change Properties
Action