Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

name attribute for NoticeType #3

Open
zerok opened this Issue · 3 comments

1 participant

@zerok

http://code.google.com/p/django-notification/issues/detail?id=6

Reported by jjconti, May 22, 2008

I suggest a new attribute for NoticeType: name.

If label is "Información" name should be "informacion"
If label is "Birthday Greet" name should be "birthday_greet"

Django cames with a function to perform this stuff but I am not sure if the
name should be forced or defined by the user. In any case, I'll really
appreciate that attribute because it'll allow me to do this at Notice:

def __getattr__(self, attrname):
   if(attrname.startswith('is_')):
       label = attrname[len('is_'):]
       try:
           notice_type = NoticeType.objects.get(label=label)
           return (lambda: True)
       except NoticeType:
           return (lambda: False)
   else:
       super(Notice, self).__getattr__(attrname)

Playing in the shell:

>>> from notifications.models import *
>>> n = Notice.objects.get(id=1)
>>> n.is_foo()
False
>>> n.notice_type
<NoticeType: informacion>
>>> n.is_informacion()
True

These methods without arguments will be very useful at templates, where you
can ask if a Notice is_sometype and then render "class=sometype" for css stuff.

@zerok

jtauber:

This as already been solved with the 'display' field.

You should also look at Pinax -- site at http://pinax.hotcluboffrance.com and code
under django-hotclub -- for an example of how I'm using django-notification at the
moment.

@zerok

jtauber:

I am happy to change the names 'label' and 'display' to something that better shows
one is the unique key and one is the display name.

@zerok

jjconti:

auth.Permission use name and codename for that propose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.