Thursday, September 1, 2011

AW: custom templatetag that checks groups

Okay i got it:

 

from django import template

register = template.Library()

 

@register.filter(name ="check")

def check(user, arg):

    if str(user.groups.all()[0]) == "Timesheet-Boss":

        return True

    else:

        return False

 

 

thanks anyways !

 

. . . . . . . . . . . . . . . . . . . . . . . . . .

Ing. Patrick Szabo
XSLT Developer

LexisNexis
Marxergasse 25, 1030 Wien

patrick.szabo@lexisnexis.at

Tel.: 00431 534521573

Fax: +43 (1) 534 52 - 146


Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im Auftrag von Szabo, Patrick (LNG-VIE)
Gesendet: Donnerstag, 01. September 2011 11:39
An: django-users@googlegroups.com
Betreff: custom templatetag that checks groups

 

Hi,

 

I want to create my own templatetag that returns true if a user is member of a certain group.

I did the following:

 

Created a package „templatetags“ in my app.

Wrote a module:

 

from django import template

register = template.Library()

 

def check(user):

    if str(user.groups.all()[0]) == "Timesheet-Boss":

        return True

    else:

        return False

 

Put this in my html:

 

{% load checkers %}

 

{{ check:user  }}

 

I get the following error:

 

Invalid filter: 'check'

Request Method:

GET

Request URL:

http://localhost:8000/

Django Version:

1.2.4

Exception Type:

TemplateSyntaxError

Exception Value:

Invalid filter: 'check'

 

 

What am i doing wrong ?!

 

Best regards


No comments:

Post a Comment