+ def book_info(self, publishable=True):
+ try:
+ book_xml = self.materialize(publishable=publishable)
+ except self.NoTextError:
+ pass
+ else:
+ from librarian.dcparser import BookInfo
+ from librarian import NoDublinCore, ParseError, ValidationError
+ try:
+ return BookInfo.from_string(book_xml.encode('utf-8'))
+ except (self.NoTextError, ParseError, NoDublinCore, ValidationError):
+ return None
+
+ def refresh_dc_cache(self):
+ update = {
+ 'dc_slug': None,
+ }
+
+ info = self.book_info()
+ if info is not None:
+ update['dc_slug'] = info.slug
+ Book.objects.filter(pk=self.pk).update(**update)
+