Brad's Blog

web dev, django, running, food, or whatever

Published: 2009-12-13

Ubuntu Audio, YES! Windows XP, NO.

Hardware Linux Ubuntu audio

I run a dual-boot Ubuntu64[1] and Windows XP system. The windows partition really exists for a single purpose, and I occasionally just reboot the machine, choose the XP partition from the Grub menu, and all is well.However, a few weeks ago, I upgraded Ubuntu, but when I rebooted the machine and chose the XP partition, I noticed the sound[2] stopped working. What!? The audio worked fine in ubuntu!The Secret: I had to completely power down the ...


Published: 2009-11-24

Gahhh!! Django, virtualenv, and cx_Oracle

apache cx_oracle django virtualenv

UPDATE: Thanks in advance to the comments from Graham Dumpleton whose comments below pointed me in the right direction!This wasis a plea for help.I've got django installed and configured with apache and virtualenv. I also have one particular app (named myapp) that queries an Oracle database directly (django is configured to use MySQL). All of the apps work, except for anything thatbrequires the myapp app... which includes the admin!Requesting any view that uses cx_Oracle results in ...


Published: 2009-11-24

Sticky Groups

Linux web

I often deploy web projects in a directory that's not owned by the user under which my webserver runs. Therefor, I often have to change permissions so the webserver can read from or write to certain files. So, for this example, let's assume I'm logged in to my linux box as brad, and I'm using apache which runs under the user www-data. To give apache access to my public_html directory, I'd change ownership for the ...


Published: 2009-09-30

Mercurial installation woes on Mac OS X

Mac OS Python X hg mercurial

I started using mercurial around version 1.2, and I'm pretty sure I used the Mac OS X installer (from http://mercurial.berkwood.com/) to install 1.2.1. This placed hg in /Library/Frameworks/Python.framework/Versions/Current/bin/.Now, I've decided to upgrade to 1.3.1, and I again grab the Mac OS X installer (again from http://mercurial.berkwood.com/), which installs hg in /usr/local/bin/.Ok, but my path is set up ...


Published: 2009-07-14

A for AJAX - OR - Dynamically generating options for a select element.

Javascript Prototype ajax web

I don't do a lot of AJAXy web development, but when I do, I usually make use of Prototype. I've recently created a form containing a <select> element whose <option>s are dynamically generated via an AJAX request. The problem however, is that a selected option was already in the form. So before the AJAX request, my HTML looked something like this:<select name="s" id="s"><option value="val1">Value 1</option><option value="val2" selected="selected">Value 2</option><option value="val3">Value ...


Published: 2009-06-30

My PYTHONPATH bit me.

Python django web

I'd just finished the first version of a new django app (myapp), and so I pushed it out to my development server. All the new code was in place, so I ran python manage.py syncdb. The result?Traceback (most recent call last): File "manage.py", line 11, in <module> execute_manager(settings) File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 340, in execute_manager File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__ ...


Published: 2009-06-26

"Adding" Q objects in Django

Python django web

I've got a Django app with the following Model:class Story(models.Model): title = models.CharField(max_length=255) content = models.TextField()The Problem: I wanted to build a simple search feature that OR'ed all the search terms. Essentially, I wanted SQL resembling the following:SELECT * from myapp_stories where title LIKE '%term1%' OR content LIKE '%term1%' OR title LIKE '%term2%' OR content LIKE '%term2%'; The Solution: You can add django's ...


Published: 2009-05-06

Data Truncated Errors

Python django mysql web

I recently ran into some of the Data truncated for column ... errors in my django apps. After a little digging, I've discovered that my particular problem lie in the structure of the underlying MySQL tables. Particularly with varchar columns. I have a model that contains a FileField:class MyModel(models.Model): file = models.FileField(upload_to="files/%Y/%m/%d")Note that the MySQL table generated by this model will look something like the following:+-------------+--------------+------+-----+---------------------+----------------+| Field | Type | Null | Key | Default ...


Published: 2009-05-01

Have Apache Force File Downloads

apache django web

I have a Django app that lets users upload files. Any kind of file. It's nice that Apache will let me force file downloads based on the files extension. <LocationMatch "\.(gz|tar|pdf|docx|doc|xls|xlsx|bz2|zip)$"> SetHandler None Header set Content-Disposition attachment</LocationMatch>So, in my HTML/templates: all I have to do is this:<a href="SomFile.docx">Some File</a>


Published: 2009-04-30

Push Your SSH Public keys using Fabric

Python fabric

This came across my twitter radar today from @bitprophet (aka: Jeff Forcier), who just happens to be the new maintainer for Fabric:def push_key(): keyfile = '/tmp/%s.pub' % env.user run('mkdir -p ~/.ssh && chmod 700 ~/.ssh') put('~/.ssh/id_rsa.pub', keyfile) run('cat %s >> ~/.ssh/authorized_keys' % keyfile) run('rm %s' % keyfile)Everything you need to push your public key to an external server using Fabric.