X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/44974eca5cd6e3fdb299d815f7a1a512cefd6196..ac5de8695878cb6aabf9161930af189cf5d15316:/src/documents/models/book.py?ds=sidebyside diff --git a/src/documents/models/book.py b/src/documents/models/book.py index ca1f4f8c..1245ceab 100644 --- a/src/documents/models/book.py +++ b/src/documents/models/book.py @@ -307,6 +307,26 @@ class Book(models.Model): valid_about = self.correct_about() assert bi.about == valid_about, _("rdf:about is not") + " " + valid_about + srcs = self.relative_ilustr_srcs(changes=changes) + assert not srcs, 'Ilustracje bez pełnego adresu: ' + ', '.join( + src or '(pusty)' for src in srcs) + + def relative_ilustr_srcs(self, changes=None): + """Returns `src` of illustrations which aren't absolute URLs. + + Those only work relative to the gallery, so they break + outside of it. Checks the current text, unless `changes` are given. + """ + from lxml import etree + try: + tree = etree.fromstring(self.materialize(changes=changes).encode('utf-8')) + except (self.NoTextError, etree.XMLSyntaxError): + return [] + return [ + elem.get('src', '') for elem in tree.iter('ilustr') + if not elem.get('src', '').startswith(('http://', 'https://')) + ] + def publishable_error(self): try: return self.assert_publishable() @@ -477,7 +497,7 @@ class Book(models.Model): cb = self.catalogue_book isbn = cb.isbn_set.filter(form='mp3').first() if isbn is not None: - data['isbn_mp3'] = isbn.get_code() + data['isbn_mp3'] = isbn.get_code() if self.project is not None: if self.project.logo: data['logo'] = urljoin(