minor fixes

This commit is contained in:
doubaniux 2022-11-26 20:36:44 +01:00
parent 2645bc05f0
commit 6924fdc092
6 changed files with 22 additions and 11 deletions

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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()

View file

@ -41,7 +41,7 @@ class ReviewFeed(Feed):
return f"{item.title} - 评论《{item.item.title}"
def item_description(self, item):
target_html = f'<p><a href="{item.item.url}">{item.item.title}</a></p>\n'
target_html = f'<p><a href="{item.item.absolute_url}">{item.item.title}</a></p>\n'
html = markdown(item.content)
return target_html + html

View file

@ -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)