Example #1
0
 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
Example #2
0
 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
Example #3
0
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,
    }
Example #4
0
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,
    }
Example #5
0
    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"))
Example #6
0
 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
Example #7
0
    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()
Example #8
0
    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()
Example #9
0
    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")
        )
Example #10
0
 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)
Example #11
0
 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)