Skip to main content

Posts

Django: How to hook in after multiple M2M have been processed

This situation comes up, from time to time, when we need to get something to happen after a many-to-many field is changed. The novice will connect a post_save signal and scratch his head when it doesn't fire on the addition or removal of items in the ManyToManyField. We all learn that it takes a slightly more complicated signal, the m2m_changed signal, and its many actions , which tell us exactly what has changed in the particular field sending it (the signal comes from the field's through table, to be exact). Well, a slightly more complicated case arose in a design today and I was scratching my head and feeling like a novice all over again. You see, I needed to know when new things had been adding to such a field, but I had more than one. In fact, I had four of them. I needed a specific function called on the instance when all of these fields were finished being cleared or added to or subtracted from. This was in a form in the Django admin. Thankfully I had an assumpti...

How To Speed Up Django Tests on Postgresql

I had a problem with a Django project that took forever to run its unit tests. The test database took an enormous amount of time to run, upwards of ten to fifteen minutes each. I didn't have a lot of ways around this, because I had to use a base Model that pulled in lots of cascading requirements and I couldn't avoid the dozens of applications it needed to build tables for. This was really hindering my ability to develop, as I rely heavily on constantly running tests in my own pathetic attempt at Continuous Integration. After some poking around the PG forums, I eventually worked out this script, which I now run on startup. #!/usr/bin/env bash service postgresql stop mount -t tmpfs -o size=500m tmpfs /mnt/pg_data_mem/ cp -R /var/lib/postgresql/8.4/main/ /mnt/pg_data_mem/ mount --bind /var/lib/postgresql/8.4/main/pg_xlog /mnt/pg_data_mem/main/pg_xlog chown -R postgres:postgres /mnt/pg_data_mem/ sudo -u postgres /usr/lib/postgresql/8.4/bin/pg_resetxlog -f /mnt/pg_data_mem/main/ser...

Soft Announcement: Trapdoor Prototype

Previously I made a little preview of something I'm announcing today, but it is a soft announcement as I've had it on github for some time, but I haven't done anything with the project. This is just a prototype, an experiment, and it is called Trapdoor. I don't remember why I named it Trapdoor. Trapdoor has a simple concept, along the lines of Mozilla Prism. I wanted to take things I use to build web applications and test how they could be applied to building desktop applications. This meant two things: 1) I need to wrap up a web application in something that can be run locally. 2) I need some way to extend a web application in ways that normally only desktop applications can provide. This has been done in the simplest way I could find, at the time, and is available on github . extensions :   - calculator.Calculator js :   - calculator.js plugins :   - trapdoor.contrib.windowmanager Applications are configured through this si...

How To Give Twisted a Friendly Zero-Step: Part 1

Zero-Step: n. The first impression and actions of a user's exposure to a new tool, before actual research and use of the details. I'm not as involved with or using Twisted as much I'd like, but I still pay attention and I care about the project. I understand its strengths and its weaknesses and I want to see it used in more cases where it is the best tool for the job. There is a obvious and recently publicized problem with Twisted and the Zero-Step. Why do people go to twistedmatrix.com for the first time? Usually, it probably isn't to read the documentation or start investigating open bug reports. First time visitors are looking to solve a problem and the first thing that has to be impressed on them is if Twisted actually solves that problem. This is actually a really big problem in this case, because there are so many problems it can solve. How do you present that image without boring lists of functionality and supported protocols? The most obvious use-case for...

How To Limit Application Trust

Why is it when I see an application in the Chome Web Store I see a little notice about what permissions the app will have, and I'll see a similar list of permissions before installing an Android application? Why is it that I don't see something more like this?

How To Push Your Habit Building Onto Technology

I use desktop alerts to keep myself organized through the day, in various ways. There are things i want to do repeatedly and I don't have a good track record with keeping good habits, so I have found some ways to make tools fill in the gaps for me. There are some specific examples i can give. I have been using the great site 750words.com for almost a year, and I love it. I write nearly every day, and I'm getting better at that habit all nthe time. usaully I only miss it when something interrupts me. I remember with something better than an email reminder or a note on my calendar each day, which both i can build a habit to ignore. I use an alert program, which is KAlert in my case, but any alert program should work the same. Every morning at 5AM, it spawns a google chrome window opening the 750words.com write page, and so I wake up and sit down to my computer every morning to find the page already open with a blank page and a blinking cursor, and I start writing. I don't hav...