The joy of legacy Zope/ZODB systems

I have a large number of legacy systems that – when all other avenues fail – become my responsibility to sort out. Some of those are very old Zope systems written by others and which never fail to reduce me to tears. This morning I came across some particularly good design decisions which I thought I’d share. Yes, that ‘good’ is sarcasm. First of all let’s remember that Zope, by default, uses the ZODB. In…

Continue reading

Python – comparing floats and decimals

No matter how old I get, I keep being bitten by the joys of having some data as floats and some as decimals. [cc lang=”python”] ipdb> value Decimal(‘1.473’) ipdb> from_value 1.473 ipdb> value < from_value True [/cc] because ... [cc lang="python"] ipdb> from decimal import * ipdb> Decimal(from_value) Decimal(‘1.4730000000000000870414851306122727692127227783203125’) [/cc] So work out what accuracy you need and do something like [cc lang=”python”] from_value = Decimal(from_value).quantize(Decimal(‘0.0001’)) [/cc]

Continue reading

Django/Postgresql – inserting new record doesn’t return id.

You have an old database and you find the following happens. [cc lang=”python”] >>> ap = ValidAirPressureCode(code=’9′, description=’9′, barcode=’9′, comments=’ 9′) >>> ap.save() >>> ap.id >>> ap = ValidAirPressureCode.objects.get(code=’9′) >>> ap.id 11 [/cc] In short Django doesn’t return the id of a newly inserted record. If you insert records in admin and choose to continue editing, you’ll get an error saying it can’t find a record with a null id. The problem (in my case)…

Continue reading

Converting Legacy Databases to Django 1.3 – Day 0.5

I have done this quite a few times in the past, but not recently. I was given three days to convert an existing postgres database (front ended with Zope) to Django 1.3. I thought it would be useful to document what I did here for my own future reference and to record any gotchas for posterity. The database I am converting is nine years old, so plenty of cruft through the years, although the basic…

Continue reading

Python development with virtualenvwrapper, django, buildout and mercurial – a basic example

I have been trying to streamline my python development processes over the years. Earlier this year @rossjones introduced me to virtualenvwrapper which made things even simpler. I’m about to go into quite a concentrated period of development so I thought I’d take the opportunity to document what I do to make an easily reproduceable python environment. Please let me know of any errors or suggestions for better ways of doing this as I go along.…

Continue reading