Thursday, February 2, 2012

Django Snippet imports?

What would I have to import to use the following snippet (source:
http://djangosnippets.org/snippets/847/)?

@register.filter
def in_group(user, groups):
"""Returns a boolean if the user is in the given group, or comma-
separated
list of groups.

Usage::

{% if user|in_group:"Friends" %}
...
{% endif %}

or::

{% if user|in_group:"Friends,Enemies" %}
...
{% endif %}

"""
group_list = force_unicode(groups).split(',')
return
bool(user.groups.filter(name__in=group_list).values('name'))

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

No comments:

Post a Comment