Django

Code

Ticket #7239 (closed: wontfix)

Opened 1 year ago

Last modified 10 months ago

Using the url tag with the blocktrans one

Reported by: david Assigned to: david
Milestone: Component: Template system
Version: SVN Keywords:
Cc: viktor.nagy@gmail.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

For the moment, you can't use blocktrans with the url tag:

{% blocktrans %}
foo {% url bar %} baz.
{% endblocktrans %}

It seems that it had already been discussed: http://groups.google.fr/group/django-developers/browse_thread/thread/e8b6b99973b10a17 but I can't find a ticket about that. If someone can post the final syntax (We're pretty close to having a good syntax), I can write the patch.

Attachments

patch_django_7239.20080530.diff (1.9 kB) - added by david on 05/29/08 18:43:16.
First naive implementation
patch_django_7239_documentation.20080617.diff (0.9 kB) - added by david on 06/16/08 18:37:56.
Documentation of the patch
patch_django_7239.20080617.diff (7.5 kB) - added by david on 06/16/08 19:21:53.
All in one with regression tests
patch_django_7239.20080722.diff (10.9 kB) - added by david on 07/22/08 09:33:24.
New patch against r8053 with additional tests for combined arguments in url tag
patch_django_7239.20080809.diff (11.4 kB) - added by david on 08/09/08 02:58:46.
New patch against r8255 which handle decision in r8211 and add tests for this situation

Change History

05/26/08 06:58:15 changed by jezdez

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Hi David, the thread is here: http://groups.google.fr/group/django-developers/browse_thread/thread/4c7b2ce86bcd990e and has a fairly good syntax at the end, I think.

05/26/08 07:09:42 changed by david

  • status changed from new to assigned.

Thanks jezdez for the link, for the record, here is a quote from the final example:

So this would make the syntax like this :

{% blocktrans with message.created|date as date and user.married|year as married_since and user.name as username %} 
    Received on {{ date }} 
    from 
    {% as link_open %}<a href="{% url userlink user.id %}">{% endas %} 
         {{ username }} (married since {{ married_since }}) 
    {% as link_close %}<a/>{% endas %} 
{% endblocktrans %}

Then the string to translated would be :

"Received on %(date)s from %(link_open)s %(username)s (married since %(married_since)s) %(link_close)%" 

I'm not fond of all those tags but I'll try to write a patch.

05/26/08 07:33:58 changed by jezdez

Yay!

As for the "as" subtag you may want to have a look at http://www.djangosnippets.org/snippets/545/.

05/29/08 18:43:16 changed by david

  • attachment patch_django_7239.20080530.diff added.

First naive implementation

05/29/08 18:50:34 changed by david

Eventually I implemented:

{% blocktrans with message.created|date as date and user.married|year as married_since and user.name as username url userlink user.id as user_url %} 
    Received on {{ date }} 
    from 
    <a href="{{ user_url }}">{{ username }} (married since {{ married_since }})<a/>
{% endblocktrans %}

It seems a lot more readable to me and it's consistent with the existing "count" alternative. I reuse URLNode from the url tag.

The translated result is:

"Received on %(date)s from <a href=\"%(user_url)s\">%(username)s (married since %(married_since)s)</a>"

Any thoughts? (I'll add tests too but I need to be sure that this syntax is accepted first).

06/12/08 15:37:51 changed by david

  • cc deleted.
  • needs_docs set to 1.
  • has_patch set to 1.
  • needs_tests set to 1.

06/12/08 15:45:54 changed by edgarsj

  • stage changed from Unreviewed to Accepted.

06/16/08 18:37:56 changed by david

  • attachment patch_django_7239_documentation.20080617.diff added.

Documentation of the patch

06/16/08 18:39:15 changed by david

  • needs_docs deleted.

Added documentation, review welcome given my poor english.

06/16/08 19:21:53 changed by david

  • attachment patch_django_7239.20080617.diff added.

All in one with regression tests

06/16/08 19:28:07 changed by david

  • needs_tests deleted.

Added tests.

BTW, I found a bug in tests.regressiontests.templates.tests with url02, there is a space between client.id, and action="update" and this option is not mentioned in documentation (it breaks my code if it's intentional):

'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),

I suggest to remove it.

07/22/08 09:33:24 changed by david

  • attachment patch_django_7239.20080722.diff added.

New patch against r8053 with additional tests for combined arguments in url tag

07/22/08 10:04:13 changed by shanx

  • stage changed from Accepted to Ready for checkin.

Excellent, unittest in the new patch handles all the other cases of using url in blocktrans. I've tested it here against revision 8053 of trunk with Django's unittest framework and functionally using a local testproject.

Marking ready for checkin so a core dev can have a look at it.

08/09/08 02:58:46 changed by david

  • attachment patch_django_7239.20080809.diff added.

New patch against r8255 which handle decision in r8211 and add tests for this situation

08/10/08 10:16:35 changed by mtredinnick

  • stage changed from Ready for checkin to Accepted.

"ready for checkin" means just that, not "needs a higher-level review", so moving back to the right state.

08/25/08 03:52:01 changed by david

08/28/08 04:00:31 changed by Viktor <viktor.nagy@gmail.com>

  • cc set to viktor.nagy@gmail.com.

09/19/08 04:36:34 changed by david

  • status changed from assigned to closed.
  • resolution set to wontfix.

Close as wontfix given the new "as" keyword in url tag. See this thread for details: http://groups.google.com/group/django-developers/browse_thread/thread/5e9d28a878091346/454017eb2277b59f


Add/Change #7239 (Using the url tag with the blocktrans one)




Change Properties
Action