View Single Post
Old 09-21-2010, 11:27 AM   #8
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
For developers

Notes for those of you who do development from time to time:

The new metadata interface is much easier and more convenient to use than the older interfaces. Given a book, you can get values and column metadata. There is a method that formats the value for you, and another method that accepts an arbitrary template, returning the resulting string.

If you are working in database-land, then use db.get_metadata to get a book structure. Get_metadata is now cached, so the performance is acceptable. The book is a Metadata instance (ebooks/metadata/book/base.py), so all the methods in that class will be available to you. You can also use a new set of field-oriented interface methods to get metatada, to get lists of field keys (sort/search names), and to get field values by name.

If you are working in device-driver land, then the book you are used to is now a Metadata instance. The JSON cache now contains all the attributes, so you can trust the book to have whatever standard or custom attributes were there when the book was last written to the cache.

My experience is that Metadata (book) instances are much easier to use than what we had before. Getting a field is as easy as book.get('field'). Getting a field's type is book.metadata_for_field('field')['datatype']. Getting a formatted value is book.format_field('field').

Don't hesitate to ask questions. Even some suggestions will be entertained.
chaley is offline   Reply With Quote