Simple_tag revamp: now takes context and inner block #1105

1 view
Skip to first unread message

Julien Phalip

unread,
Jun 18, 2008, 3:24:22 AM6/18/08
to Django developers
Hi,

I have just posted a patch that improves the simple_tag by allowing it
to take the context and/or the inner block. See the patch in ticket
#1105 [1].

It is backward compatible, and while the patch is quite simple it
would make the creation of template tag even more super easy. For
example:

@register.simple_tag(takes_block=True, takes_context=True)
def customspaceless(context, block_nodelist):
from django.utils.html import strip_spaces_between_tags
return
strip_spaces_between_tags(block_nodelist.render(context).strip())

It is nearly completed. There is just a small glitch with block
support, and I haven't been able to figure it out yet. So your
feedback would be very welcome!

I'd be keen to have it checked in as it makes life much easier ;)
I also believe that many default tags could be revamped using that new
simple_tag, and that way we could shrink the code quite a lot in
django.templates.

Cheers,

Julien

[1] http://code.djangoproject.com/ticket/1105

Julien Phalip

unread,
Jun 21, 2008, 8:02:21 PM6/21/08
to Django developers
Hello all,

I hope I didn't scare anyone away with the word "revamp". The patch is
in fact pretty simple and backward compatible.

I don't mean to be pushy and I totally understand that some issues
might have higher priority on the road to 1.0, but I think this is
something that might be of interest for quite a few people as in [1]
[2] [3] [4]. It has been somewhat validated by Malcom [1] [4] and
Simon [5].

I believe that small change would make the creation of template tags
even more trivial and save a lot of boiler plate code.

If you're interested, let me know what you think of the code, it's all
in the super_simple_tag.diff patch on ticket #1105 [6].

Thanks! ;)

[1] http://groups.google.com/group/django-users/browse_thread/thread/b3b3d7894f48b609
[2] http://groups.google.com/group/django-users/browse_thread/thread/ee830466be465704
[3]
http://groups.google.com/group/django-users/browse_thread/thread/36ef798d6f6e46c8/19146dc1f092a59f?lnk=gst&q=simple_tag#19146dc1f092a59f
[4]
http://groups.google.com/group/django-users/browse_thread/thread/179b206a75fbb456/89eb87ca142a724e?lnk=gst&q=simple_tag+context#89eb87ca142a724e
[5] http://groups.google.com/group/django-developers/browse_thread/thread/62d0cefde54a50a3#
[6] http://code.djangoproject.com/ticket/1105

Tai Lee

unread,
Jun 22, 2008, 6:15:47 AM6/22/08
to Django developers
I like it. I've run into a few cases recently where I just needed a
simple_tag with access to the context.

Julien Phalip

unread,
Jun 25, 2008, 1:23:39 AM6/25/08
to Django developers
Hi all,

If you're interested and would like to see this checked in, you can
have a look at ticket #1105 [1]. There is now fully functional code +
documentation + tests.

I personally think it's a good enhancement for simple_tag as it'd make
creation of most template tags (in particular tags with context and
block tags) even more trivial and really fast.

Let me know what you think.

Cheers!

Julien

[1] http://code.djangoproject.com/ticket/1105

Jacob Kaplan-Moss

unread,
Jun 25, 2008, 12:24:44 PM6/25/08
to django-d...@googlegroups.com
Hey Julien --

#1105 looks quite nice (though it looks like your patch was generated
weirdly... at least, the paths are strange -- no real problem,
though).

I don't know that it'll make it in before 1.0 since we're focusing on
stuff on the roadmap, but if you're willing to be patient this'll
almost certainly go in after. And possibly before if I find the time,
but don't count on it.

Jacob

Jeremy Dunck

unread,
Jun 25, 2008, 12:30:35 PM6/25/08
to django-d...@googlegroups.com
On Wed, Jun 25, 2008 at 11:24 AM, Jacob Kaplan-Moss
<jacob.ka...@gmail.com> wrote:
...

> I don't know that it'll make it in before 1.0 since we're focusing on
> stuff on the roadmap, but if you're willing to be patient this'll
> almost certainly go in after. And possibly before if I find the time,
> but don't count on it.
>

Julien,
With that in mind, it'd be good to note, in the ticket, which rev of
Django the patch applies to.

Julien Phalip

unread,
Jun 25, 2008, 7:12:19 PM6/25/08
to Django developers
Thanks Jacob and Jeremy for these suggestions ;)

On Jun 26, 2:30 am, "Jeremy Dunck" <jdu...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages