diff --git a/collection/models.py b/collection/models.py index dda20130..ad149f5c 100644 --- a/collection/models.py +++ b/collection/models.py @@ -1,4 +1,5 @@ from django.db import models +from markdown import markdown from common.models import UserOwnedEntity from movies.models import Movie from books.models import Book @@ -8,6 +9,7 @@ from markdownx.models import MarkdownxField from django.utils.translation import gettext_lazy as _ from django.conf import settings from common.utils import ChoicesDictGenerator, GenerateDateUUIDMediaFilePath +from common.models import RE_HTML_TAG from django.shortcuts import reverse diff --git a/common/models.py b/common/models.py index e897b18b..d7589627 100644 --- a/common/models.py +++ b/common/models.py @@ -64,6 +64,11 @@ class Entity(models.Model): def url(self): return self.get_absolute_url() + @property + def absolute_url(self): + """URL with host and protocol""" + return settings.APP_WEBSITE + self.url + def get_json(self): return { 'title': self.title, diff --git a/common/search/typesense.py b/common/search/typesense.py index 29123de4..e03610cc 100644 --- a/common/search/typesense.py +++ b/common/search/typesense.py @@ -1,5 +1,7 @@ +import types import logging import typesense +from typesense.exceptions import ObjectNotFound from django.conf import settings from django.db.models.signals import post_save, post_delete @@ -194,14 +196,16 @@ class Indexer: # 'facetsDistribution': ['_class'], # 'sort_by': None, } - # print(q) - r = self.instance().collections[INDEX_NAME].documents.search(options) - # print(r) - import types results = types.SimpleNamespace() - results.items = list([x for x in map(lambda i: self.item_to_obj(i['document']), r['hits']) if x is not None]) - results.num_pages = (r['found'] + SEARCH_PAGE_SIZE - 1) // SEARCH_PAGE_SIZE - # print(results) + + try: + r = self.instance().collections[INDEX_NAME].documents.search(options) + results.items = list([x for x in map(lambda i: self.item_to_obj(i['document']), r['hits']) if x is not None]) + results.num_pages = (r['found'] + SEARCH_PAGE_SIZE - 1) // SEARCH_PAGE_SIZE + except ObjectNotFound: + results.items = [] + results.num_pages = 1 + return results @classmethod diff --git a/mastodon/api.py b/mastodon/api.py index 63a6990e..66546f5c 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -410,7 +410,7 @@ def share_mark(mark): visibility = TootVisibilityEnum.UNLISTED tags = '\n' + user.get_preference().mastodon_append_tag.replace('[category]', str(mark.item.verbose_category_name)) if user.get_preference().mastodon_append_tag else '' stars = rating_to_emoji(mark.rating, MastodonApplication.objects.get(domain_name=user.mastodon_site).star_mode) - content = f"{mark.translated_status}《{mark.item.title}》{stars}\n{mark.item.url}\n{mark.text}{tags}" + content = f"{mark.translated_status}《{mark.item.title}》{stars}\n{mark.item.absolute_url}\n{mark.text}{tags}" update_id = None if mark.shared_link: # "https://mastodon.social/@username/1234567890" r = re.match(r'.+/(\w+)$', mark.shared_link) # might be re.match(r'.+/([^/]+)$', u) if Pleroma supports edit @@ -469,7 +469,7 @@ def share_collection(collection, comment, user, visibility_no): else: visibility = TootVisibilityEnum.UNLISTED tags = '\n' + user.get_preference().mastodon_append_tag.replace('[category]', '收藏单') if user.get_preference().mastodon_append_tag else '' - content = f"分享收藏单《{collection.title}》\n{collection.url}\n{comment}{tags}" + content = f"分享收藏单《{collection.title}》\n{collection.absolute_url}\n{comment}{tags}" response = post_toot(user.mastodon_site, content, visibility, user.mastodon_token) if response and response.status_code in [200, 201]: j = response.json() diff --git a/users/feeds.py b/users/feeds.py index 16bd045d..ec325249 100644 --- a/users/feeds.py +++ b/users/feeds.py @@ -41,7 +41,7 @@ class ReviewFeed(Feed): return f"{item.title} - 评论《{item.item.title}》" def item_description(self, item): - target_html = f'

{item.item.title}

\n' + target_html = f'

{item.item.title}

\n' html = markdown(item.content) return target_html + html diff --git a/users/tasks.py b/users/tasks.py index a7c17f82..25766c2e 100644 --- a/users/tasks.py +++ b/users/tasks.py @@ -135,7 +135,7 @@ def export_marks_task(user): my_rating = None # (mark.rating / 2) if mark.rating else None content = review.content target_source_url = review.item.source_url - target_url = review.item.url + target_url = review.item.absolute_url line = [title, target, url, timestamp, my_rating, label, content, target_source_url, target_url] ws.append(line)