View Single Post
Old 04-29-2011, 03:21 PM   #217
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,501
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
I see Kovid has merged the changes now so I shall have an experiment later.
Note the slight API change that the code I posted didn't use, but should. I changed the add_multiple method to have a parameter that tells it to delete all existing data for that name before adding the new data.
Code:
add_multiple_custom_book_data(self, name, vals, delete_first=False):
Also note that 'vals' must be an iterable that has a book_id as a key/index and the object to be serialized as the data. Either a list or a dict will work. In my test I used a dict.

The get_all_custom_book_data method does what you would expect.

For completeness I also added delete_all_custom_book_data(self, name). It removes all records with 'name', regardless of book_id.
chaley is offline   Reply With Quote