def metadata(book): try: xml = etree.parse(book.xml_file) finally: book.xml_file.close() md = wl_dc_reader(xml) m = md.getMap() if book.parent: m['isPartOf'] = [str(WLURI.from_slug(book.parent.slug))] return m
def metadata(self, book): try: xml = etree.parse(book.xml_file) finally: book.xml_file.close() md = wl_dc_reader(xml) m = md.getMap() if book.parent: m['isPartOf'] = [str(WLURI.from_slug(book.parent.slug))] return m
def info_args(title, language=None): """ generate some keywords for comfortable BookInfoCreation """ slug = unicode(slughifi(title)) if language is None: language = u'pol' return { 'title': unicode(title), 'url': WLURI.from_slug(slug), 'about': u"http://wolnelektury.pl/example/URI/%s" % slug, 'language': language, }
def setUp(self): WLTestCase.setUp(self) common_uri = WLURI.from_slug('common-slug') self.pol_info = BookInfoStub(genre='X-Genre', epoch='X-Epoch', kind='X-Kind', author=PersonStub(("Joe", ), "Doe"), variant_of=common_uri, **info_args(u"Książka")) self.eng_info = BookInfoStub(genre='X-Genre', epoch='X-Epoch', kind='X-Kind', author=PersonStub(("Joe", ), "Doe"), variant_of=common_uri, **info_args("A book", "eng"))
def fix_wluri(elem, change, verbose): try: WLURI.strict(elem.text) except ValidationError: correct_field = unicode(WLURI.from_slug( WLURI(elem.text.strip()).slug)) try: WLURI.strict(correct_field) except ValidationError: # Can't make a valid WLURI out of it, leave as is. return False if verbose: print "Changing %s from %s to %s" % ( elem.tag, elem.text, correct_field ) elem.text = correct_field return True
def setUp(self): WLTestCase.setUp(self) self.book_info = BookInfoStub( url=WLURI.from_slug(u"default-book"), about=u"http://wolnelektury.pl/example/URI/default_book", title=u"Default Book", author=PersonStub(("Jim",), "Lazy"), kind="X-Kind", genre="X-Genre", epoch="X-Epoch", language=u"pol", ) self.expected_tags = [ ('author', 'jim-lazy'), ('genre', 'x-genre'), ('epoch', 'x-epoch'), ('kind', 'x-kind'), ] self.expected_tags.sort()
def setUp(self): WLTestCase.setUp(self) self.book_info = BookInfoStub( url=WLURI.from_slug(u"default-book"), about=u"http://wolnelektury.pl/example/URI/default_book", title=u"Default Book", author=PersonStub(("Jim", ), "Lazy"), kind="X-Kind", genre="X-Genre", epoch="X-Epoch", language=u"pol", ) self.expected_tags = [ ('author', 'jim-lazy'), ('genre', 'x-genre'), ('epoch', 'x-epoch'), ('kind', 'x-kind'), ] self.expected_tags.sort()
def setUp(self): WLTestCase.setUp(self) common_uri = WLURI.from_slug('common-slug') self.pol_info = BookInfoStub( genre='X-Genre', epoch='X-Epoch', kind='X-Kind', author=PersonStub(("Joe",), "Doe"), variant_of=common_uri, **info_args(u"Książka") ) self.eng_info = BookInfoStub( genre='X-Genre', epoch='X-Epoch', kind='X-Kind', author=PersonStub(("Joe",), "Doe"), variant_of=common_uri, **info_args("A book", "eng") )
def test_book_with_invalid_slug(self): """ Book with invalid characters in slug shouldn't be imported """ self.book_info.url = WLURI.from_slug(u"default_book") book_text = "<utwor />" models.Book.from_text_and_meta(ContentFile(book_text), self.book_info)