fix post toot w tag error
This commit is contained in:
parent
0d5b9e5b80
commit
3752b724a0
3 changed files with 8 additions and 5 deletions
|
@ -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")
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue