Brad's Blog

web dev, django, running, food, or whatever

SiteSprint III - An update 2011-01-24

This post, a followup to my previous post, is now about 2 months overdue. I have to admit, I'm glad I participated in SiteSprint, but I'm fairly disappointed in the amount of work that I accomplished. So, without further ado, here's the update on what happened.Success!Set up a Django stack running nginx, gunicorn, postgresqlSet up MezzanineMigrated my blog posts and comments from BloggerFor a weekend of work, this really wasn't too bad. I like ...

Fix: Leopard libedit detected. 2011-01-05

If you use iPython on OS X, you've probably seen this: Leopard libedit detected., and then noticed some very quirky behavior related to spacing, and command history. In short, that behavior is related to default version of the readline library bundled in OS X (It's not GNU readline). If you use pip and virtualenv, just instalilng readline doesn't help. So, how do you fix this? Well, the quick and dirty way to fix this is with:easy_install ...

SiteSprint III - The Reclaimation 2010-11-02

My personal website is a disgrace. As a web developer, I find it embarrassing that my own site is a cobbled-together mess of PHP and static html. Only slightly less embarrassing is my blog, which is obviously hosted on Blogger. Even though Blogger has recently added a few new themes, I'm still unhappy with the look-and-feel of my blog. So, since SiteSprint III has officially started, I'm taking this opportunity to Reclaimâ„¢ my personal website.Tech Specs - the ...

Python: stray commas cause tuples? 2010-10-15

As I try to debug a strange problem in a Django view, I notice a stray comma after a dictionary definition. So I jump over to a python shell, and guess what? Ending a literal dict with a comma creates a tuple. >>> d = {1:'foo'},>>> type(d)<type 'tuple'>>>> d({1: 'foo'},)>>>

A case for values_list 2010-07-19

Here's the Scenario: I have a model (lets call it Contact) with two Foreign Keys, one of which is related to User in Django's contrib.auth app. I need to build a form that lets me select an existing object, and a new user. class ContactType(Model): name = CharField(max_length=128)class Contact(Model): user = ForeignKey(User) contact_type = ForeignKey(ContactType) # possibly more fields...I need to select from existing models, so my first thought might be to build ...

PyGraphviz on OS X (SL) with virtualenv 2010-07-14

There's this cool project called django-extensions that (among other things) adds a lot of commands to django's manage.py offerings. One of which is ./manage.py graph_models [appname] which will generate a nice graph displaying the relationships among all of your Models. This comand needs pyGraphViz, though, and I was a little disappointed when i discovered I couldn't install pyGraphViz with pip install pygraphviz. (ok, a lot disappointed). I eventually got this working, and here's how ...

Vim Syntax highlighting for Apache Config Files 2010-06-09

I use Django with Apache and mod_wsgi. Each project that I work on has different apache config files, so I like to keep those in the same mercurial repo that contains my django project's code.For some time now, it's been bugging me that vim doesn't do syntax highlighting for those apache configs (nor the wsgi files). I finally decided to do something about it, and I'm glad I did, because it's a fairly simple ...

Convert Tables to Unordered Lists 2010-05-28

If you've ever had the pleasure of working with old HTML content, you've surely seen some <table>'s where they don't belong. Lately, that's the sort of thing I've been dealing with on a regular basis, and for some reason, I often see a list of information in a table.Wouldn't it be nice if there were an easy way to turn these tables into unordered lists? Thanks to BeautifulSoup, this is really not ...

Pretty options for Django's auth.User 2010-04-22

Several of my Django Apps have Foreign Key relationships to django.contrib.auth.model.User. In Django's admin app, these show up a select elements displaying the username attribute. For some people, that may be OK, but for most of the people with which I work, it's not. We want to see prettier options, i.e. each User's full name as the options in that select element.So, here's how it works. We override the ModelChoiceField ...

Dealing with Unicode and ASCII using Python 2010-03-25

Dealing with Character Encodings is (sometimes) hard. It's especially confusing for those who've never done it before. Converting text from unicode to ascii can be tricky. A lot of times, I'll import some data from a text file, and I just want to convert everything to ASCII and ignore anything that's not ascii (like MS Word's smart quotes). Luckily, this is fairly easy:mystring = mystring.decode('ascii', 'ignore')There's tons of great Python resources ...