From af43a678694121f8b7c81a52a64d02c1b024fc57 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 10 Jan 2023 15:40:13 +0100 Subject: [PATCH] Updated and fixes. --- requirements/requirements.txt | 2 +- .../templates/catalogue/book_text.html | 3 ++- src/catalogue/templatetags/catalogue_tags.py | 2 +- src/education/models.py | 17 +++++++++++------ src/search/index.py | 14 ++++++++------ src/wolnelektury/settings/apps.py | 1 + 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2dec1cc9b..c78c3f5c1 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -40,7 +40,7 @@ mutagen==1.45.1 sorl-thumbnail==12.8.0 # home-brewed & dependencies -librarian==2.4.1 +librarian==2.4.9 # celery tasks celery[redis]==5.2.7 diff --git a/src/catalogue/templates/catalogue/book_text.html b/src/catalogue/templates/catalogue/book_text.html index 9d28bd7bc..78067d747 100644 --- a/src/catalogue/templates/catalogue/book_text.html +++ b/src/catalogue/templates/catalogue/book_text.html @@ -198,9 +198,10 @@ "label": "{{ ref.entity.label }}", "description": "{{ ref.entity.description }}", "wikipedia_link": "{{ ref.entity.wikipedia_link }}" - }{% if not forloop.last %},{% endif %} + }, {% endif %} {% endfor %} + "": null } {% endlocalize %} diff --git a/src/catalogue/templatetags/catalogue_tags.py b/src/catalogue/templatetags/catalogue_tags.py index 6ee177713..1d5cee0db 100644 --- a/src/catalogue/templatetags/catalogue_tags.py +++ b/src/catalogue/templatetags/catalogue_tags.py @@ -106,7 +106,7 @@ def nice_title_from_tags(tags, related_tags): # No info on genre, but there's only one kind related. subpieces = [] pieces.append([ - t.collective_noun or t.name for t in self['kind'] + t.collective_noun or t.name for t in related_tags['kind'] ]) plural = False else: diff --git a/src/education/models.py b/src/education/models.py index 5d11004b8..33064a113 100644 --- a/src/education/models.py +++ b/src/education/models.py @@ -49,15 +49,18 @@ class YPlaylist(models.Model): super().save() self.download() - def download(self): - response = YouTubeToken.objects.first().call( - "GET", - "https://www.googleapis.com/youtube/v3/playlistItems", - params={ + def download(self, page_token=None): + params = { 'part': 'snippet', 'playlistId': self.youtube_id, 'maxResults': 50, - }, + } + if page_token: + params['pageToken'] = page_token + response = YouTubeToken.objects.first().call( + "GET", + "https://www.googleapis.com/youtube/v3/playlistItems", + params=params ) data = response.json() for item in data['items']: @@ -68,6 +71,8 @@ class YPlaylist(models.Model): 'order': item['snippet']['position'], } ) + if data.get('nextPageToken'): + self.download(page_token=data['nextPageToken']) diff --git a/src/search/index.py b/src/search/index.py index 2be60fdf7..68a2b3b18 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -9,6 +9,9 @@ import os import re from django.conf import settings from librarian import dcparser +import librarian.meta.types.date +import librarian.meta.types.person +import librarian.meta.types.text from librarian.parser import WLDocument from lxml import etree import scorched @@ -318,21 +321,20 @@ class Index(SolrIndex): if hasattr(book_info, field.name): if not getattr(book_info, field.name): continue - # since no type information is available, we use validator - type_indicator = field.validator - if type_indicator == dcparser.as_unicode: + type_indicator = field.value_type + if issubclass(type_indicator, librarian.meta.types.text.TextValue): s = getattr(book_info, field.name) if field.multiple: s = ', '.join(s) fields[field.name] = s - elif type_indicator == dcparser.as_person: + elif issubclass(type_indicator, librarian.meta.types.person.Person): p = getattr(book_info, field.name) - if isinstance(p, dcparser.Person): + if isinstance(p, librarian.meta.types.person.Person): persons = str(p) else: persons = ', '.join(map(str, p)) fields[field.name] = persons - elif type_indicator == dcparser.as_date: + elif issubclass(type_indicator, librarian.meta.types.date.DateValue): dt = getattr(book_info, field.name) fields[field.name] = dt diff --git a/src/wolnelektury/settings/apps.py b/src/wolnelektury/settings/apps.py index ad0ff1592..fe42e04c1 100644 --- a/src/wolnelektury/settings/apps.py +++ b/src/wolnelektury/settings/apps.py @@ -11,6 +11,7 @@ INSTALLED_APPS_OUR = [ 'catalogue', 'chunks', 'dictionary', + 'education', 'experiments', 'infopages', 'lesmianator', -- 2.20.1