Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X
Post

Django Views As Classes with Python’s __call__ Magic Method

I have been using Django off-and-on for about 2 years now. I am really liking the direction, but what bugged me (for the longest time) is the re-usability of the view section.

For those unfamiliar with Django views, they are not strictly “MVC” views. If anything, they act more like controllers, and I treat them as such. It should be a piece of cake to reuse code between these, but usually what happened was that I would define a bunch of private view functions and have them referenced by various view functions. It wasn’t exactly the shining pinnacle of my development career.

While reading the code for django-jqchat while working on a project for my client, I rediscovered the python __call__ magic method. This basically permits you to call an instance of an object like a function. With a little effort, I managed to re-organize the code to make it a little more easy to parse. This is not complete and not debugged, but maybe you will find it useful.

Github Gist Link

Links

Interesting Comment on Islamic Banking

I previously considered Islamic banking a fraud, more or less at the same level as “halal pork”.  This comment has forced me to reconsider.

Images

Sony Vaio ad cracks me up

Sony Vaio ad cracks me up

Should I get the 13.3 or the 13.6?

Links

Django Deployment Guide

Found this while watching a class on Safaribooksonline.

Deploying Django is always a bit of a hassle; hopefully this will help someone.
Links

Get rid of unnecessary /chrootjail/lib files

I am not sure if I should actually publish this because it seems like hitting a fly with a nuke.

This is a python script that goes through a chroot jail’s directory (in my case, /chroot/lib) and removes one file at a time.  It then tries sftping into the server using a restricted user; if the user is able to connect and transfer the file, the file is removed.  Otherwise, it is kept.
This requires Paramiko to execute the sftp connection.  I am sure there are better ways to do it, but this works.  (For some reason, just calculating the requirements /didn’t/ work for me.)