Feature query rewrite datatable

Use a more explicit representation of data tables, separating creating the table and outputting the json structure 

advantages:
- make it easier for different scripts to output data tables
- make it easier to change the output json format if desired

points of discussion:
- datatable now inherits from dict. Hack or elegant solution?
- I've removed make_relative because I think that it should actually happen client side: on querying you don't know which values are allowed, and it should be fairly easy to offer js-based 'relativization'. 

todo:
- handle media properly, change output json so it outputs {"id": 1, "label": "vk"} structure. 
- add sorting routines and test case