Problem: JSON doesn’t specify a date format. Dojo wants json dates in the form {_type:’Date’,_value:’2007-12-31T12:34:56.789′}. Using jsonlib.write’s on_unknown handler, we can test for the datetime type and format it in this way. On the way back, when items are changed in the browser, we did Date.prototype.json = function() {return dateFormat(this)}, so that dojo.toJson would know how to format dates. This means that “json” is using two different formats for the two directions (an object on the way to browser and a string on the way back to server.) The string format for the date itself is the same in the two directions (which took some work since dojo appends the time zone offset but Python’s datetime’s .isoformat function does not, and there are some milliseconds/microseconds issues.)
Next problem: Dojo grid (ItemFileReadStore, actually) likes to have an ‘identifier’ column, which is used to quickly find a row (’item’). We have some tables that have multi-column primary keys (PKs). I had first just been lazy and used the 1st column of the PK, but Dojo was smart enough to see that wasn’t unique when I used real data. I looked at perhaps a hundred dojo grid data examples, and EVERY ONE had a single-column primary key. However, you can use an OBJECT for identifier, and if it has a .toString() method then you might be able to have it combine the primary key columns on-the-fly {x:10,y:20,toString:function(){return this.x+’|'+this.y}}. I’m thinking this will be messy because 1) jsonlib won’t know how to emit a javascript function; 2) didn’t figure out how the object’s toString function references the item’s data columns (does this.pk0 work?); 3) what if we change a PK’s value? “ItemFileWriteStore does not have support for changing the value of an item’s identifier“.
The plan at the moment is one of: 1) construct our own new one-column primary key that is a concatenation of the actual primary key columns, such as NJ|Trenton. This won’t be shown on the grid, and for now, there is no editing of PK values anyway. 2) just use a sequence number and fix when we finally have some use for the identifier; 3) switch to the ‘table’ format where we don’t need an identifier.
Tags: dojo, identifier, json