I’ve just bought a new Macbook and am busy setting up my dev environment on it. Things aren’t really as hard as I though they’d be. With macports, OSX doesn’t really feel much different superficially from any linux distro.
My dear brother Thilak met with a minor accident this afternoon, and in the confusion the ensued, he’s spilt the beans on Tagz. It must’ve been painful to singlehandedly type the 228 word post (He’s got a cast on his right hand, because of the accident). The UI is kinda crude, but functional. Actually a couple of friends are already using/testing it. Well, we plan to release it sometime soon, but I honestly wish he hadn’t made it public so soon.
We’d been discussing this “`better` delicious reddit chimera” idea for quite some time now. Due to difficult personal circumstances in the past couple of months, I’ve been suffering from a terrible bout of insomnia. When the usual remedies for this (reading Nietzsche, driving through the city all night long etc) didn’t work, I started working on it. Then, on one of my infrequent visits to Mangalore, I showed a very crude prototype to Thilak and he was pretty enthusiastic about it. We setup a redmine instance, moved the mercurial repository to my vps and we were up and running, with a couple of commits every night.
We’ve got a long way to go before I can call it release ready. Until then, all I can say is its written using django and python, with postgresql for the db. And the `undumb` or `not dumb` (or whatever) tags thing he’s hinting about isn’t really all that smart, its just plain old tagging with porter stemming to identify similar tags.
In one of my django projects, I use a lot of recursive template tags, which seem to cause quite a bit of slowdown while rendering them. I looked at the code in django.template.loaders.filesystem
def load_template_source(template_name, template_dirs=None):
tried = []
for filepath in get_template_sources(template_name, template_dirs):
try:
return (open(filepath).read().decode(settings.FILE_CHARSET), filepath)
except IOError:
tried.append(filepath)
if tried:
error_msg = "Tried %s" % tried
else:
error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
raise TemplateDoesNotExist, error_msg
load_template_source.is_usable = True
Looks like the template is reloaded from the filesystem every time the a template is loaded. This gets really bad with custom templatetags and inclusion tags. Well, can’t we just load the file into memory, and the next time its needed, call os.stat() on the file and check if the file has been modified, if not don’t reload the file from disk. Finally, I settled on a compromise, don’t reload templates in production mode, and disable the template cache in debug mode.
Here’s template_cache.py
# -*- coding: utf-8 -*-
from django.template import loader, TemplateDoesNotExist
from django.conf import settings
template_cache = {}
def cached_loader( template_name, template_dirs=None ) :
global template_cache
t = template_cache.get(template_name)
if not t :
old_loaders = settings.TEMPLATE_LOADERS[:]
settings.TEMPLATE_LOADERS = old_loaders[1:]
loader.template_source_loaders = None
try :
template_cache[template_name] = t = loader.find_template_source( template_name, template_dirs )
finally :
settings.TEMPLATE_LOADERS = old_loaders # To avoid recursively calling cached_loader
loader.template_source_loaders = None
return t
cached_loader.is_usable = not settings.DEBUG # Avoid caching in debug mode
