Best way to change Site.__str__ to return name not domain

2014-10-07 Thread Michael Jones
Hi, I am using the sites framework and finding it very useful but I would prefer the Site.__str__ method to return the site name instead of the domain. What is the best way of going about that? Is it reasonable to monkey patch it or do I need to make my own sites app with a copy of the code?

Re: Catching AttributeError exceptions in widget media

2014-09-05 Thread Michael Jones
try: >> getattr(obj, name) >> return True >> except: # yikes! naked except! >> return False >> >> https://docs.python.org/2/library/functions.html#hasattr >> So, excepting AttributeError will at least narrow down the error >> slightly

Re: Catching AttributeError exceptions in widget media

2014-09-04 Thread Michael Jones
Hi, Thanks for the reply, but I'm not sure I follow. I was hoping that the following might work: if hasattr(sup_cls, 'media'): base = sup_cls.media else: base = Media() Would that swallow additional exceptions? Cheers, Michael On Wednesday, September 3, 2014 10:45:22

Catching AttributeError exceptions in widget media

2014-09-03 Thread Michael Jones
Hi, I love Django, it has been enormously useful to a new comer to web dev like me. One minor issue I've just had is that I've struggled to figure out an issue with my code because an AttributeError I was generating in my media property on my custom widget was being silently swallowed by: