Archive for January, 2010

  1. Django settings in template

    So what do you do if you require a django setting in your templates, much like we have MEDIA_URL today?

    Well there are use cases for this, (if you are in doubt have a look at the original ticket for adding MEDIA_URL to django ).

    The easiest way that I have found so far is to write a context processor. For example in my settings I might have JAVASCRIPT_URL (which in my real life code changes depending on whether I am running in debug, test or from a CDN):

    JAVASCRIPT_URL = 'http://myjshost.com'

    Now from here I would like to make this available in my templates. Create a new python file that is somewhere on your python path (Under my project, I create a utils directory and then put a file context_processors.py in there. Don’t forget __init__.py should live in that directory as well).

    In the context_processors.py file simply put

    def javascript_url(request):
        from django.conf import settings
        return {'JAVASCRIPT_URL': settings.JAVASCRIPT_URL}

    In your settings.py file you might already have a reference to TEMPLATE_CONTEXT_PROCESSORS if not then add it like so:

    from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
    TEMPLATE_CONTEXT_PROCESSORS += (
         'django.core.context_processors.request',
         'django.core.context_processors.i18n',
         'appname.utils.context_processors.javascript_url',
    )

    And thats about it. From there on in you will be able to use JAVASCRIPT_URL like MEDIA_URL:

    {{ JAVASCRIPT_URL }}
    By timc3 on the
    January 22nd, 2010
  2. The White Balance Lens Cap

    Oh this is clever:

    The White Balance Lens Cap: “

    You may think automatic white balance is good enough. But if you’ve ever had to fix dozens (or even 100s) of photos with just slightly different colors, one-by-one, you know the true meaning of pain. The White Balance Lens Cap leaves you no excuse for not properly white-balancing every situation you encounter. Simply flip your camera into custom White Balance mode, snap a photo with your White Balance Lens Cap on, and your camera creates a perfect profile of the actual lighting in front of you. Best of all, unlike a gray card, the White Balance Cap takes no extra room in your gear bag. Just replace your existing lens cap with this one and you’ll always be able to white balance with no additional equipment.

    (Via swissmiss.)

    By timc3 on the
    January 22nd, 2010
  3. Sugru

    Awesome silicon based material for hacking anything – http://sugru.com/

    By timc3 on the
    January 20th, 2010
  4. Updating contact details

    I have just spent the past 90 minutes updating contact details – much longer than it should take. Would be nice if I could just update say on Plaxo, and linkedin, Facebook etc would receive the updates but I guess we haven’t got to that stage yet. Have also sent out emails to lots of people, so apologies if you haven’t received one.

    The main change is my mobile number – it belonged to vizrt, with whom my last day was officially the 31st of December. So please remove that from your records, I am waiting for company registration details to go through before I get a proper new mobile number but in the meantime reach me at tim@ the usual places or skype me on timchild.

    Just to reiterate – my mobile number is no more.

    By timc3 on the
    January 1st, 2010