fly me to the moon, let me rate among the stars
This commit is contained in:
parent
b246bd7dd1
commit
8fdb119d21
6 changed files with 16 additions and 7 deletions
|
@ -9,6 +9,7 @@ from django.db.models import Count
|
|||
from django.utils import timezone
|
||||
from django.core.paginator import Paginator
|
||||
from mastodon import mastodon_request_included
|
||||
from mastodon.models import MastodonApplication
|
||||
from mastodon.api import check_visibility, post_toot, TootVisibilityEnum
|
||||
from mastodon.utils import rating_to_emoji
|
||||
from common.utils import PageLinksGenerator
|
||||
|
@ -312,7 +313,7 @@ def create_update_mark(request):
|
|||
args=[book.id])
|
||||
words = BookMarkStatusTranslator(form.cleaned_data['status']) +\
|
||||
f"《{book.title}》" + \
|
||||
rating_to_emoji(form.cleaned_data['rating'])
|
||||
rating_to_emoji(form.cleaned_data['rating'], MastodonApplication.objects.get(domain_name=request.user.mastodon_site).star_mode)
|
||||
|
||||
# tags = settings.MASTODON_TAGS % {'category': '书', 'type': '标记'}
|
||||
tags = ''
|
||||
|
|
|
@ -9,6 +9,7 @@ from django.db.models import Count
|
|||
from django.utils import timezone
|
||||
from django.core.paginator import Paginator
|
||||
from mastodon import mastodon_request_included
|
||||
from mastodon.models import MastodonApplication
|
||||
from mastodon.api import check_visibility, post_toot, TootVisibilityEnum
|
||||
from mastodon.utils import rating_to_emoji
|
||||
from common.utils import PageLinksGenerator
|
||||
|
@ -314,7 +315,7 @@ def create_update_mark(request):
|
|||
args=[game.id])
|
||||
words = GameMarkStatusTranslator(form.cleaned_data['status']) +\
|
||||
f"《{game.title}》" + \
|
||||
rating_to_emoji(form.cleaned_data['rating'])
|
||||
rating_to_emoji(form.cleaned_data['rating'], MastodonApplication.objects.get(domain_name=request.user.mastodon_site).star_mode)
|
||||
|
||||
# tags = settings.MASTODON_TAGS % {'category': '书', 'type': '标记'}
|
||||
tags = ''
|
||||
|
|
|
@ -9,6 +9,8 @@ class MastodonApplication(models.Model):
|
|||
client_id = models.CharField(_('client id'), max_length=100)
|
||||
client_secret = models.CharField(_('client secret'), max_length=100)
|
||||
vapid_key = models.CharField(_('vapid key'), max_length=200)
|
||||
star_mode = models.PositiveIntegerField(_('0: custom emoji; 1: unicode moon; 2: text'), blank=False, default=0)
|
||||
max_status_len = models.PositiveIntegerField(_('max toot len'), blank=False, default=500)
|
||||
|
||||
is_proxy = models.BooleanField(default=False, blank=True)
|
||||
proxy_to = models.CharField(max_length=100, blank=True, default='')
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
from django.conf import settings
|
||||
|
||||
|
||||
def rating_to_emoji(score):
|
||||
def rating_to_emoji(score, star_mode = 0):
|
||||
""" convert score to mastodon star emoji code """
|
||||
if score is None or score == '' or score == 0:
|
||||
return ''
|
||||
solid_stars = score // 2
|
||||
half_star = int(bool(score % 2))
|
||||
empty_stars = 5 - solid_stars if not half_star else 5 - solid_stars - 1
|
||||
emoji_code = settings.STAR_SOLID * solid_stars + settings.STAR_HALF * half_star + settings.STAR_EMPTY * empty_stars
|
||||
if star_mode == 1:
|
||||
emoji_code = "🌕" * solid_stars + "🌗" * half_star + "🌑" * empty_stars
|
||||
else:
|
||||
emoji_code = settings.STAR_SOLID * solid_stars + settings.STAR_HALF * half_star + settings.STAR_EMPTY * empty_stars
|
||||
emoji_code = emoji_code.replace("::", ": :")
|
||||
emoji_code = ' ' + emoji_code + ' '
|
||||
return emoji_code
|
|
@ -9,6 +9,7 @@ from django.db.models import Count
|
|||
from django.utils import timezone
|
||||
from django.core.paginator import Paginator
|
||||
from mastodon import mastodon_request_included
|
||||
from mastodon.models import MastodonApplication
|
||||
from mastodon.api import check_visibility, post_toot, TootVisibilityEnum
|
||||
from mastodon.utils import rating_to_emoji
|
||||
from common.utils import PageLinksGenerator
|
||||
|
@ -313,7 +314,7 @@ def create_update_mark(request):
|
|||
args=[movie.id])
|
||||
words = MovieMarkStatusTranslator(form.cleaned_data['status']) +\
|
||||
f"《{movie.title}》" + \
|
||||
rating_to_emoji(form.cleaned_data['rating'])
|
||||
rating_to_emoji(form.cleaned_data['rating'], MastodonApplication.objects.get(domain_name=request.user.mastodon_site).star_mode)
|
||||
|
||||
# tags = settings.MASTODON_TAGS % {'category': '书', 'type': '标记'}
|
||||
tags = ''
|
||||
|
|
|
@ -3,6 +3,7 @@ from .models import *
|
|||
from common.models import SourceSiteEnum
|
||||
from common.views import PAGE_LINK_NUMBER, jump_or_scrape
|
||||
from common.utils import PageLinksGenerator
|
||||
from mastodon.models import MastodonApplication
|
||||
from mastodon.utils import rating_to_emoji
|
||||
from mastodon.api import check_visibility, post_toot, TootVisibilityEnum
|
||||
from mastodon import mastodon_request_included
|
||||
|
@ -332,7 +333,7 @@ def create_update_song_mark(request):
|
|||
args=[song.id])
|
||||
words = MusicMarkStatusTranslator(form.cleaned_data['status']) +\
|
||||
f"《{song.title}》" + \
|
||||
rating_to_emoji(form.cleaned_data['rating'])
|
||||
rating_to_emoji(form.cleaned_data['rating'], MastodonApplication.objects.get(domain_name=request.user.mastodon_site).star_mode)
|
||||
|
||||
# tags = MASTODON_TAGS % {'category': '书', 'type': '标记'}
|
||||
tags = ''
|
||||
|
@ -903,7 +904,7 @@ def create_update_album_mark(request):
|
|||
args=[album.id])
|
||||
words = MusicMarkStatusTranslator(form.cleaned_data['status']) +\
|
||||
f"《{album.title}》" + \
|
||||
rating_to_emoji(form.cleaned_data['rating'])
|
||||
rating_to_emoji(form.cleaned_data['rating'], MastodonApplication.objects.get(domain_name=request.user.mastodon_site).star_mode)
|
||||
|
||||
# tags = MASTODON_TAGS % {'category': '书', 'type': '标记'}
|
||||
tags = ''
|
||||
|
|
Loading…
Add table
Reference in a new issue