tech notes
These posts are strictly for programmers to find on google when trying to solve the same problems. Otherwise dull as dirt.
django has two classes called ValidationError
2010 February 04
There is one in django.core.exceptions and one in django.forms.util
Using that space age IDE Eclipse I have to say I’m enjoying how much time I’ve saved just going shift-command-O to organize and resolve all of my imports. But today I’ve just lost a few hours due to my ok-ing the wrong class.
Quite mysterious it was, I raised a ValidationError (core exceptions one) in my form’s clean() and watched as the try: except ValidationError: in django’s full_clean() completely ignored my error and propagated it up.
But what is the django crüe doing naming two classes that ? django.core.exceptions is quite vague, it just says “An error while validating data.” Its used for db Field validation errors.
I guess its as confusing as naming two entire class heirarchies 'Field’ : one for db fields and one for html form fields. As though the two always went hand in hand, which they don’t.
Another large problem I have recently is that a form field and its form widget are never allowed to talk to the object model, only to a single db field. I often have built fields that need to save to several fields on the model, and the clearest place to do this is by concentrating most of the power into the Form class.
An example is an address input that I use that has a display address, postal address and map address. The interface is complex, uses google maps and in the end also saves longitude,latitude, geo_accuracy, address, street, zip, city,state, and country objects. As a field or widget its not allowed to do all that. It has to be tied to a form or the form has to call a function on the field to offer it access to the Model.
Another pet peeve (while we’ve got me in a tizzy still):
# Give this new form class a reasonable name.
if form ModelForm:
class_name = model.name + 'Form’
else:
# CX: leave a clue that the form IS the form that you passed in
# otherwise you have no clue what happened to your form class
class_name = form.name + “FromFactory”
GDAL fails to build: `.rodata' can not be used when making a shared object; recompile with -fPIC
2010 January 23
Compiling GDAL, I had a failure with the following splurge:
libtool: link: g++ -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.1/crtbeginS.o .libs/libgdal.la.lnkscript -L/usr/local/lib /usr/local/lib/libgeos_c.so /usr/local/lib/libgeos.so /usr/local/lib/libexpat.so -L/usr/lib -lpq -lrt -ldl /usr/lib/libcurl.so -lssl -lcrypto -lz -L/usr/lib/gcc/x86_64-linux-gnu/4.4.1 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.4.1/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crtn.o -Wl,-soname -Wl,libgdal.so.1 -o .libs/libgdal.so.1.13.2
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `.rodata’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make1: *** [libgdal.la] Error 1
make1: Leaving directory `/home/crucial/tmp/gdal-1.6.2’
make: *** [check-lib] Error 2
installing MySQLdb on Ubuntu (mysql-python)
2010 January 23
MySQLdb is the python support bindings for MySQL. Not that the name would lead you to beleive that.
Its sourceforge page calls it http://sourceforge.net/projects/mysql-python/ which makes more sense.
you need setuptools, which you usually already have:
sudo aptitude install python-setuptools
You need MySQL-devel to compile, but its not called that, its called: libmysql++-dev on Ubuntu
sudo apt-get install libmysql++-dev
download MySQLdb itself from:
http://sourceforge.net/projects/mysql-python/
# the version you download will be more recent
tar xfz MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py build
# the following might fail if it can’t find mysql_config on your path
sudo python setup.py install
if it did try locating the mysql_config that was installed with MySQL-devel
and editing site.cfg which is in the MySQL-python folder
uncomment and point to it here:
mysql_config = /usr/bin/mysql_config
and try to build again
if it worked then test:
open a python shell (also change directories out of the compile dir you were just in to avoid confusing yourself with the just compiled version sitting in your path)
import MySQLdb
postgres login as admin user postgres
2010 January 18
When installing postgres a user will be created named 'postgres’ with a password of '!!’ which means “cannot login”. But yet you need to login as that in order to run psql (the postgres db shell) to create other users and to create database templates.
The solution is to first log yourself in as root (in your normal shell):
su root
(enter password…)
then you will no longer be subject to password checks and you can login in as user 'postgres’
su postgres
(you will automatically allowed to do this)
then you can
psql
note: on OS X you cannot login as root. use a binary install. the King Khaos package was fairly painless for me.
How to uninstall PyDev Extensions from Eclipse
2010 January 12
I’m enjoying Eclipse for Python Django development. The integrated lint check is great and has saved me much time already. Nearly automatic handling of imports is simply a life saver. Imports are the most time consuming and frustrating aspect of python development and I always wished they would just resolve themselves. With Eclipse and PyDev they do !
I dream of one day getting the debugger and integrated unit tests to work properly.
It takes a while to get used to Eclipse. It always makes me feel like I am being fondled by a great tentacle monster, if you know what I mean.
PyDev is THE python development plugin for Eclipse.
PyDev Extensions was the debugger add-on plugin, which cost $40 or so. Its been open sourced and is now part of PyDev.
Splendid. A quick rant and then I’ll tell you the solution.
Let’s upgrade. Menu: Preferences > Install/Update. It checks for new updates on start up. No complaints, no updates. Hmm. Eventually I notice a very small icon on the bottom toolbar. It looks like a computer (ok, but everything involves computers. how is this relevant ?) Near the computer it has a donut and an angry X in a red circle. eventually I notice it, give it a click and it tells me there’s an upgrade conflict. Understandable, I need to uninstall PyDev Extensions since its now part of the new PyDev.
How to uninstall PyDev Extensions: Help (of course ! I have a problem and therefore I need help ! so go to the Help menu) > Install new software … (trick question, I’m uninstalling actually). Click on the chatty “What is already installed ?” hyperlink. Yes, its a hyperlink. As though we were going to read something on the internet. Now you may select the obsolete PyDev extensions and click Uninstall. Restart, the updater runs and now offers to upgrade PyDev to the newest (1.5.3 as of this writing).
more in tech notes
- django has two classes called ValidationError
- GDAL fails to build: `.rodata' can not be used when making a shared object; recompile with -fPIC
- installing MySQLdb on Ubuntu (mysql-python)
- postgres login as admin user postgres
- How to uninstall PyDev Extensions from Eclipse
- django: post_syncdb signal
- com_digidesign_FWMbox2ProDevice kernel panic
- Capistrano sudo shows password, doesn't work
- Quicksilver action: quickly write a file from text
- Clearsilver not installed - Trac doesn't work on Hardy
- Qt PyQt4 license incompatible
- django ajax select for ManyToMany
- django cron jobs with envir variables
- MySQL case insensitive LIKE
- global .gitignore
- django circular imports due to new admin
- that &*^%ing UTF-8 MySQL *&^@ing truncate bug again
- firefox firebug vs gmail = application not responding
- copy and paste from password protected PDF files OS X
- django and TextMate : open Exception location file
- django: those pesky silent template variable failures
- django / MySQL 4.1 : bogus "Data truncated for column" error
- tip: don't name django apps common names like "collections"
- django reverse() url lookups
- django development server vs example.com
- django debugging : forcing files to recompile
- apple goofs up airport update
- php or || : more reasons to dislike php
- how to set up a local svn repository (for SC)
- how not to get your myspaced hacked
- myspace breaks when using safari : aug 22 2007
- logic pro audio cut out
- MacBook pro wireless problem Airport
- set CSS class by javascript
- svnX and switching an SVN working copy to a different user
- Cocoa MySQL can't connect
- the real reason apple can't let third party applications on the iPhone
- Mac automatic transfer from old machine to new machine
- Logic Audio hangs while validating Native Instruments AU
- reaktor, logic and freezing tracks
- logic channel strips and reaktor patches
- SDII format specification