I have a variety of places in my code where I add a class to a
widget.  For example, I have a render() function for a DateWidget that
contains this code, which adds a special class if the date is in the
past.

                if date < datetime.datetime.now():
                    if self.attrs.get("class"):
                        self.attrs["class"] += " " + self.pastClass
                    else:
                        self.attrs["class"] = self.pastClass

This checks if there's already a class attribute and if there is,
appends a space and then the string in self.pastClass, and if tehre is
not, just creates the class attribute containing self.pastClass.

This seems like a lot of code to do something really simple and I feel
like I'm repeating it in various places.  I'm wondering if there is
some better way that folks deal with this little nit?

Margie

--

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


Reply via email to