diff --git a/journal/models.py b/journal/models.py index 3178f4b2..33fa23ce 100644 --- a/journal/models.py +++ b/journal/models.py @@ -934,7 +934,7 @@ class Mark: if self.shelfmember.metadata else None ) - self.translated_status = self.shelf_label + self.translated_status = self.action_label self.save = lambda **args: None if not share_mark(self): raise ValueError("sharing failed") diff --git a/journal/views.py b/journal/views.py index ff72acb6..131b5335 100644 --- a/journal/views.py +++ b/journal/views.py @@ -152,7 +152,8 @@ def mark(request, item_uuid): visibility, share_to_mastodon=share_to_mastodon, ) - except Exception: + except Exception as e: + _logger.warn(f"post to mastodon error {e}") return render_relogin(request) return HttpResponseRedirect(request.META.get("HTTP_REFERER")) return HttpResponseBadRequest() diff --git a/mastodon/api.py b/mastodon/api.py index 1269076e..381001b6 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -11,7 +11,6 @@ from .models import CrossSiteUserInfo, MastodonApplication from mastodon.utils import rating_to_emoji import re - logger = logging.getLogger(__name__) # See https://docs.joinmastodon.org/methods/accounts/ @@ -446,6 +445,8 @@ def revoke_token(site, token): def share_mark(mark): + from catalog.common import ItemCategory + user = mark.owner if mark.visibility == 2: visibility = TootVisibilityEnum.DIRECT @@ -458,7 +459,7 @@ def share_mark(mark): tags = ( "\n" + user.get_preference().mastodon_append_tag.replace( - "[category]", str(mark.item.verbose_category_name) + "[category]", str(ItemCategory(mark.item.category).label) ) if user.get_preference().mastodon_append_tag else "" @@ -467,7 +468,7 @@ def share_mark(mark): mark.rating, MastodonApplication.objects.get(domain_name=user.mastodon_site).star_mode, ) - content = f"{mark.translated_status}《{mark.item.title}》{stars}\n{mark.item.absolute_url}\n{mark.text}{tags}" + content = f"{mark.translated_status}《{mark.item.title}》{stars}\n{mark.item.absolute_url}\n{mark.text or ''}{tags}" update_id = None if mark.shared_link: # "https://mastodon.social/@username/1234567890" r = re.match( @@ -489,6 +490,7 @@ def share_mark(mark): mark.save(update_fields=["shared_link"]) return True else: + print(response) return False