I've been using Django for three days now. I'm getting more and more nervous about the black-magic model code. Today I ran into this ... strangeness. In my model code, I have:
class UTC(datetime.tzinfo):
def utcoffset(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return datetime.timedelta(0)
UTC = UTC()
class Challenge(meta.Model):
.
.
.
def start_utc(self):
return datetime.datetime(self.start.year, self.start.month,
self.start.day, 0, 0, 0, 0, UTC)
Looks reasonable enough, but it breaks. Says the global "UTC" isn't defined, inside start_utc(). I have to hard-code UTC=UTC in the method signature to make that code work. Update: this is fixed in 0.92, the next major release.
The hiding of exceptions in template rendering is really starting to annoy. That is, if there's an issue rendering {{ some_callable }} in a template, then I see nothing. I've even got DEBUG on. Nothing appears in the browser, the page source or the server log. It could be that I mis-typed "some_callabl" or perhaps "some_callable" is a call and that raised an exception. I won't know unless I manually wrap "some_callable" in a try/except/import traceback to find out!