View Single Post
Old 03-11-2011, 02:31 PM   #1
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
New Metadata class (empty books) and custom columns

In my plugin I have a class called "SeriesBook", which wraps access to an instance of a Metadata object, like below. The SeriesBook class has various functions I require which include getting and setting values in particular custom columns that Metadata object has.
Code:
class SeriesBook(object):
  def __init__(self, mi):
    self.mi = mi
Now as part of the functionality I have, I want to be able to create new SeriesBook instances for "empty books". So I do something like this:
Code:
mi = Metadata(title, authors)
book = SeriesBook(mi)
However the problem I have is that a new Metadata object instantiated in this way does not have any of the custom column data in place. So if on my SeriesBook class I have functions that use mi.get_user_metadata() and mi.set_user_metadata(), they will work fine on mi objects that have been read from the database using db.get_metadata(), but not on my unsaved mi instances.

Any suggestions on how to solve this? I don't want to persist the mi to the database at this point and re-read it. What I want to do is somehow create the custom column infrastructure on the mi instance when I create the empty book, so my SeriesBook class will not care. This has to be done in such a way that when I call db.set_metadata() way later in the code (the user clicking ok on the dialog), it will be quite happy with the way that custom column data has been set on the mi instance.

I hope that makes sense.
kiwidude is offline   Reply With Quote