From: Radek Czajka Date: Tue, 19 May 2026 15:30:00 +0000 (+0200) Subject: fix tests and importers X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/HEAD?ds=inline;hp=482a9275485e8326dd056e03679968c1270367c1 fix tests and importers --- diff --git a/src/catalogue/models.py b/src/catalogue/models.py index bd959134..8c3d4cdf 100644 --- a/src/catalogue/models.py +++ b/src/catalogue/models.py @@ -666,6 +666,9 @@ class Thema(models.Model): ordering = ('code',) verbose_name_plural = 'Thema' + @staticmethod + def standardize(code): + return code.split('.')[0] class Audience(models.Model): code = models.CharField( diff --git a/src/cover/tests.py b/src/cover/tests.py index 4755991e..5436100a 100644 --- a/src/cover/tests.py +++ b/src/cover/tests.py @@ -41,7 +41,7 @@ class FlickrTests(TestCase): 'author': "Radek Czajka@Flickr", 'title': "Pirate Stańczyk", 'license_name': "CC BY 2.0", - 'license_url': "https://creativecommons.org/licenses/by/2.0/", + 'license_url': "https://creativecommons.org/licenses/by/2.0/deed.en", 'download_url': re.compile(r'\.staticflickr\.com'), } ) @@ -72,7 +72,7 @@ class FlickrTests(TestCase): form.cleaned_data, { 'title': 'Chłopiec w słomkowym kapeluszu', - 'author': 'Mykola Pymonenko', + 'author': 'Mykoła Pymonenko', 'source_url': 'https://commons.wikimedia.org/wiki/File:Pymonenko_A_boy_in_a_straw_hat.jpg', 'download_url': 'https://upload.wikimedia.org/wikipedia/commons/9/9b/Pymonenko_A_boy_in_a_straw_hat.jpg', 'license_url': 'https://pl.wikipedia.org/wiki/Domena_publiczna', @@ -82,7 +82,7 @@ class FlickrTests(TestCase): def test_mnw(self): form = ImportForm({ - "source_url": 'https://cyfrowe.mnw.art.pl/pl/katalog/511078' + "source_url": 'https://cyfrowe.mnw.art.pl/pl/zbiory/447973' }) self.assertTrue(form.is_valid()) self.assertEqualWithRe( @@ -90,7 +90,7 @@ class FlickrTests(TestCase): { 'title': 'Chłopka (Baba ukraińska)', 'author': 'Krzyżanowski, Konrad (1872-1922)', - 'source_url': 'https://cyfrowe.mnw.art.pl/pl/katalog/511078', + 'source_url': 'https://cyfrowe.mnw.art.pl/pl/zbiory/447973', 'download_url': re.compile(r'https://cyfrowe-cdn\.mnw\.art\.pl/.*\.jpg'), 'license_url': 'https://pl.wikipedia.org/wiki/Domena_publiczna', 'license_name': 'domena publiczna' @@ -106,7 +106,7 @@ class FlickrTests(TestCase): self.client.post( '/cover/quick-import/1/', { - 'url': 'https://cyfrowe.mnw.art.pl/pl/katalog/511078' + 'url': 'https://cyfrowe.mnw.art.pl/pl/zbiory/447973' } ) diff --git a/src/cover/utils.py b/src/cover/utils.py index baf3e88e..59e194ff 100644 --- a/src/cover/utils.py +++ b/src/cover/utils.py @@ -62,7 +62,7 @@ def get_flickr_data(url): m = re.search(r'modelExport: (\{.*\})', html) try: assert m - download_url = 'https:' + json.loads(m.group(1))['main']['photo-models'][0]['sizes']['o']['url'] + download_url = 'https:' + json.loads(m.group(1))['main']['photo-models'][0]['data']['sizes']['data']['o']['data']['url'] except (AssertionError, ValueError, IndexError, KeyError): raise FlickrError('Error reading image URL.') return { diff --git a/src/depot/models.py b/src/depot/models.py index 41a6bdfa..62a360aa 100644 --- a/src/depot/models.py +++ b/src/depot/models.py @@ -174,9 +174,9 @@ class SiteBookPublish(models.Model): self.site_book.site.publish(self, changes=changes) - except Exception: + except Exception as e: self.status = 110 - self.error = traceback.format_exc() + self.error = str(e) + '\n\n' + traceback.format_exc() else: self.status = 100 self.error = '' diff --git a/src/depot/publishers/legimi.py b/src/depot/publishers/legimi.py index da222456..11a1c038 100644 --- a/src/depot/publishers/legimi.py +++ b/src/depot/publishers/legimi.py @@ -1,19 +1,20 @@ from datetime import date import re +from urllib.parse import urljoin from django.conf import settings from django.utils.html import escape from django.utils.safestring import mark_safe from librarian.functions import lang_code_3to2 from librarian.builders import EpubBuilder, MobiBuilder from librarian.covers.marquise import MarquiseCover, LabelMarquiseCover -from catalogue.models import Audience +from lxml import html +from catalogue.models import Audience, Thema from .base import BasePublisher class Legimi(BasePublisher): - BASE_URL = 'https://panel.legimi.pl' - LOGIN_URL = BASE_URL + '/publishers/membership' - UPLOAD_URL = BASE_URL + '/administration/upload/start' + BASE_URL = 'https://wydawca.legimi.pl' + UPLOAD_URL = BASE_URL + '/upload/start' CREATE_URL = BASE_URL + '/publishers/publications/create' EDIT_URL = BASE_URL + '/publishers/publications/edit/%s' EDIT_FILES_URL = BASE_URL + '/publishers/publications/editfiles/%s' @@ -121,13 +122,14 @@ class Legimi(BasePublisher): } def login(self): - self._session.post( - self.LOGIN_URL, - data={ - 'ValidationTrue': 'true', - 'UserName': self.username, - 'Password': self.password, - }) + r = self._session.get(self.BASE_URL) + h = html.fromstring(r.text) + form = h.findall('.//form')[0] + login_url = urljoin(r.url, form.action) + data = {e.name: e.value for e in form.findall('.//input')} + data['Login'] = self.username + data['Password'] = self.password + self._session.post(login_url, data=data) def can_publish(self, site, book): d = { @@ -180,6 +182,7 @@ class Legimi(BasePublisher): Audience.objects.filter(code__in=meta.audiences).exclude( thema=None).values_list('thema', flat=True) ) + thema = [Thema.standardize(t) for t in thema] return thema def send_book(self, site_book_publish, changes=None): @@ -315,8 +318,8 @@ class Legimi(BasePublisher): response = self.session.post(self.CREATE_URL, data=data) m = re.search(r'/(\d+)$', response.url) - if m is not None: - return m.group(1) + assert m is not None, 'Legimi.create_book: ' + response.text + return m.group(1) def edit(self, legimi_id, data): current = { diff --git a/src/documents/tests/files/expected.xml b/src/documents/tests/files/expected.xml index ff225a03..9ea5b5b8 100644 --- a/src/documents/tests/files/expected.xml +++ b/src/documents/tests/files/expected.xml @@ -37,7 +37,7 @@ Precz z mego serca!... i serce posłucha,/ Precz z méj pamięci!... Nie! tego rozkazu/ Moja i twoja pamięć nie posłucha. - + Jak cień tém dłuższy, gdy padnie z daleka,/ Tém szerzéj koło żałobne roztoczy,/