From b15e203d42d3fd0880ca21d6251dca6fa46405c9 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 22 Aug 2023 16:13:41 +0200 Subject: [PATCH 1/1] woblink last steps --- src/depot/publishers/base.py | 21 ++++++++-------- src/depot/publishers/legimi.py | 7 +++--- src/depot/publishers/woblink.py | 25 ++++++++++++++++--- .../templates/documents/book_detail.html | 6 ++--- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/depot/publishers/base.py b/src/depot/publishers/base.py index b728cf24..dbf14ab7 100644 --- a/src/depot/publishers/base.py +++ b/src/depot/publishers/base.py @@ -22,9 +22,19 @@ class BasePublisher: def get_description(self, wlbook, description_add=''): description = '' + + if wlbook.meta.audience in ('L', 'SP1', 'SP2', 'SP3', 'SP4'): + description += '

{} to lektura szkolna.'.format(wlbook.meta.title) + if wlbook.tree.find('//pe') is not None: + description += '
Ebook {title} zawiera przypisy opracowane specjalnie dla uczennic i uczniów {school}.'.format( + title=wlbook.meta.title, + school='szkoły podstawowej' if wlbook.meta.audience.startswith('SP') else 'liceum i technikum' + ) + description += '

\n' + abstract = wlbook.tree.find('.//abstrakt') if abstract is not None: - description = transform_abstrakt(abstract) + description += transform_abstrakt(abstract) description += description_add description += '

' description += ', '.join( @@ -62,14 +72,5 @@ class BasePublisher: for p in wlbook.meta.genres ) + '

' - # TODO: Move away from using audiences for this. - if wlbook.meta.audience in ('L', 'SP1', 'SP2', 'SP3', 'SP4'): - description += '

{} to lektura szkolna.'.format(wlbook.meta.title) - if wlbook.tree.find('//pe') is not None: - description += '
Ebook {title} zawiera przypisy opracowane specjalnie dla uczennic i uczniów {school}.'.format( - title=wlbook.meta.title, - school='szkoły podstawowej' if wlbook.meta.audience.startswith('SP') else 'liceum i technikum' - ) - description += '

' return description diff --git a/src/depot/publishers/legimi.py b/src/depot/publishers/legimi.py index c7fa26df..a85b46bc 100644 --- a/src/depot/publishers/legimi.py +++ b/src/depot/publishers/legimi.py @@ -133,6 +133,7 @@ class Legimi(BasePublisher): d = { 'errors': [], 'warnings': [], + 'info': [] } if meta.thema_main or meta.thema: if meta.thema_main: @@ -144,14 +145,14 @@ class Legimi(BasePublisher): "{code}".format(code=escape(t)) for t in meta.thema ) - d['comment'] = mark_safe(comment) + d['info'].append(mark_safe(comment)) elif meta.thema: - d['comment'] = mark_safe( + d['info'].append(mark_safe( "w kategorii " + ", ".join( "{code}".format(code=escape(t)) for t in meta.thema ) - ) + )) d['warnings'].append('Brak głównej kategorii Thema') else: d['errors'].append('Brak kategorii Thema.') diff --git a/src/depot/publishers/woblink.py b/src/depot/publishers/woblink.py index 8472a180..d7d55ea7 100644 --- a/src/depot/publishers/woblink.py +++ b/src/depot/publishers/woblink.py @@ -124,6 +124,8 @@ class Woblink(BasePublisher): STEP1_URL = BASE_URL + 'catalog/edit/%s' STEP2_URL = BASE_URL + 'catalog/edit/%s/2' STEP3_URL = BASE_URL + 'catalog/edit/%s/3' + STEP4_URL = BASE_URL + 'catalog/edit/%s/4' + STEP5_URL = BASE_URL + 'catalog/edit/%s/5' UPLOAD_URL = BASE_URL + 'file/upload-%s' JOB_STATUS_URL = BASE_URL + 'task/status' GENERATE_DEMO_URL = BASE_URL + 'task/run/generate-%s-demo/%s/%d' @@ -309,6 +311,7 @@ class Woblink(BasePublisher): d = { 'warnings': [], 'errors': [], + 'info': [], } errors = [] book_data = self.get_book_data(shop, wldoc, errors) @@ -320,11 +323,15 @@ class Woblink(BasePublisher): errlist.append(error.as_html()) if book_data.get('genres'): - d['comment'] = format_html( + d['info'].append(format_html( 'W kategoriach: {cat} ({price} zł)', cat=', '.join(self.describe_category(g) for g in book_data['genres']), - price=book_data['price'] - ) + price=book_data['price'], + )) + d['info'].append(mark_safe( + '' + book_data['abstract']['header'] + + '
' + book_data['abstract']['rest'] + )) return d @@ -378,6 +385,8 @@ class Woblink(BasePublisher): book.woblink_id, wldoc, book.gallery_path(), fundraising=texts ) + self.edit_step4(book.woblink_id, book_data) + self.edit_step5(book.woblink_id, book_data) def get_book_data(self, shop, wldoc, errors=None): return { @@ -479,6 +488,16 @@ class Woblink(BasePublisher): d = self.with_form_name(d, 'EditPublicationStep3') return self.session.post(self.STEP3_URL % woblink_id, data=d) + def edit_step4(self, woblink_id, book_data): + d = {} + d = self.with_form_name(d, 'EditPublicationStep4') + return self.session.post(self.STEP4_URL % woblink_id, data=d) + + def edit_step5(self, woblink_id, book_data): + d = {} + d = self.with_form_name(d, 'EditPublicationStep5') + return self.session.post(self.STEP5_URL % woblink_id, data=d) + def wait_for_job(self, job_id): while True: response = self.session.post( diff --git a/src/documents/templates/documents/book_detail.html b/src/documents/templates/documents/book_detail.html index 08d8c36f..273b3a74 100644 --- a/src/documents/templates/documents/book_detail.html +++ b/src/documents/templates/documents/book_detail.html @@ -153,11 +153,11 @@ Opublikuj na {{ shop.name }} - {% if shop.comment %} + {% for info in shop.info %}
- {{ shop.comment }} + {{ info }}
- {% endif %} + {% endfor %} {% else %} {% for error in shop.errors %}
-- 2.20.1