Skip to content

Commit

Permalink
fix language for tasks and top10
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Dec 26, 2024
1 parent efe6536 commit 564146d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
26 changes: 16 additions & 10 deletions journal/management/commands/top10.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from auditlog.context import set_actor
from django.core.management.base import BaseCommand
from django.db.models import Count, F, Q
from django.utils.translation import gettext_lazy as t

from catalog.models import *
from journal.models import *
from users.middlewares import activate_language_for_user
from users.models import *
from users.models import APIdentity

Expand All @@ -19,6 +22,8 @@ def add_arguments(self, parser):

def handle(self, year: int, top: int, save: str, **options): # type: ignore
collector = APIdentity.objects.get(username=save, local=True) if save else None
if collector:
activate_language_for_user(collector.user)
types = [
[Edition],
[Movie],
Expand All @@ -31,7 +36,7 @@ def handle(self, year: int, top: int, save: str, **options): # type: ignore
mapping = item_content_types()
for typ in types:
cids = [mapping[t] for t in typ]
title = f"{year}年标记最多的{typ[0].category.label}"
title = f"{year}年标记最多的{t(typ[0].category.label)}"
print(title)
top10 = list(
ShelfMember.objects.filter(
Expand All @@ -44,15 +49,16 @@ def handle(self, year: int, top: int, save: str, **options): # type: ignore
items = [(Item.objects.get(pk=i["item"]), i["c"]) for i in top10]
_ = [print(c, i.display_title, i.absolute_url) for i, c in items]
if collector:
print(f"Saving to {collector}")
c, _ = Collection.objects.get_or_create(
owner=collector,
title=title,
brief="*根据用户标记数统计*",
defaults={"visibility": 2},
)
for i in items:
c.append_item(i)
with set_actor(collector.user):
print(f"Saving to {collector}")
c, _ = Collection.objects.get_or_create(
owner=collector,
title=title,
brief="*根据用户标记数统计*",
defaults={"visibility": 2},
)
for i, cat in items:
c.append_item(i)

# top10 = list(
# Comment.objects.filter(
Expand Down
3 changes: 3 additions & 0 deletions users/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from typedmodels.models import TypedModel
from user_messages import api as msg

from users.middlewares import activate_language_for_user

from .user import User


Expand Down Expand Up @@ -61,6 +63,7 @@ def _run(cls, task_id: int):
return
task.state = cls.States.started
task.save()
activate_language_for_user(task.user)
with set_actor(task.user):
try:
task.run()
Expand Down

0 comments on commit 564146d

Please sign in to comment.