woblink last steps
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 22 Aug 2023 14:13:41 +0000 (16:13 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 22 Aug 2023 14:13:41 +0000 (16:13 +0200)
src/depot/publishers/base.py
src/depot/publishers/legimi.py
src/depot/publishers/woblink.py
src/documents/templates/documents/book_detail.html

index b728cf2..dbf14ab 100644 (file)
@@ -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 += '<p><em>{}</em> to lektura szkolna.'.format(wlbook.meta.title)
+            if wlbook.tree.find('//pe') is not None:
+                description += '<br>Ebook <em>{title}</em> 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 += '</p>\n'
+
         abstract = wlbook.tree.find('.//abstrakt')
         if abstract is not None:
-            description = transform_abstrakt(abstract)
+            description += transform_abstrakt(abstract)
         description += description_add
         description += '<p>'
         description += ', '.join(
@@ -62,14 +72,5 @@ class BasePublisher:
             for p in wlbook.meta.genres
         ) + '</p>'
 
-        # TODO: Move away from using audiences for this.
-        if wlbook.meta.audience in ('L', 'SP1', 'SP2', 'SP3', 'SP4'):
-            description += '<p><em>{}</em> to lektura szkolna.'.format(wlbook.meta.title)
-            if wlbook.tree.find('//pe') is not None:
-                description += '<br>Ebook <em>{title}</em> 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 += '</p>'
         return description
 
index c7fa26d..a85b46b 100644 (file)
@@ -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):
                         "<b><tt>{code}</tt></b>".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(
                         "<b><tt>{code}</tt></b>".format(code=escape(t))
                         for t in meta.thema
                     )
-                )
+                ))
                 d['warnings'].append('Brak głównej kategorii Thema')
         else:
             d['errors'].append('Brak kategorii Thema.')
index 8472a18..d7d55ea 100644 (file)
@@ -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(
+            '<strong>' + book_data['abstract']['header'] +
+            '</strong><br/>' + 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(
index 08d8c36..273b3a7 100644 (file)
                         Opublikuj na {{ shop.name }}
                       </button>
                     </form>
-                    {% if shop.comment %}
+                    {% for info in shop.info %}
                       <div class="alert alert-info">
-                        {{ shop.comment }}
+                        {{ info }}
                       </div>
-                    {% endif %}
+                    {% endfor %}
                   {% else %}
                     {% for error in shop.errors %}
                       <div class="alert alert-danger">