apply user language for their review feed
This commit is contained in:
parent
9dc81968cb
commit
432d47251a
3 changed files with 15 additions and 6 deletions
|
@ -131,7 +131,6 @@ class ItemType(models.TextChoices):
|
|||
PodcastEpisode = "podcastepisode", _("Podcast Episode") # type:ignore[reportCallIssue]
|
||||
Performance = "performance", _("Performance") # type:ignore[reportCallIssue]
|
||||
PerformanceProduction = "production", _("Production") # type:ignore[reportCallIssue]
|
||||
FanFic = "fanfic", _("Fanfic") # type:ignore[reportCallIssue]
|
||||
Exhibition = "exhibition", _("Exhibition") # type:ignore[reportCallIssue]
|
||||
Collection = "collection", _("Collection") # type:ignore[reportCallIssue]
|
||||
|
||||
|
@ -256,6 +255,7 @@ class LocalizedTitleSchema(Schema):
|
|||
|
||||
|
||||
class ItemInSchema(Schema):
|
||||
type: str
|
||||
title: str = Field(alias="display_title")
|
||||
description: str = Field(default="", alias="display_description")
|
||||
localized_title: list[LocalizedTitleSchema] = []
|
||||
|
@ -346,6 +346,7 @@ class Item(PolymorphicModel):
|
|||
collections: QuerySet["Collection"]
|
||||
merged_from_items: QuerySet["Item"]
|
||||
merged_to_item_id: int
|
||||
type: ItemType # subclass must specify this
|
||||
schema = ItemSchema
|
||||
category: ItemCategory # subclass must specify this
|
||||
url_path = "item" # subclass must specify this
|
||||
|
|
|
@ -15,6 +15,7 @@ from django.views.decorators.http import require_http_methods
|
|||
from catalog.models import *
|
||||
from common.utils import AuthedHttpRequest, get_uuid_or_404
|
||||
from journal.models.renderers import convert_leading_space_in_md, render_md
|
||||
from users.middlewares import activate_language_for_user
|
||||
from users.models.apidentity import APIdentity
|
||||
|
||||
from ..forms import *
|
||||
|
@ -105,7 +106,9 @@ MAX_ITEM_PER_TYPE = 10
|
|||
|
||||
class ReviewFeed(Feed):
|
||||
def get_object(self, request, *args, **kwargs):
|
||||
return APIdentity.get_by_handle(kwargs["username"], match_linked=True)
|
||||
o = APIdentity.get_by_handle(kwargs["username"], match_linked=True)
|
||||
activate_language_for_user(o.user)
|
||||
return o
|
||||
|
||||
def title(self, owner):
|
||||
return (
|
||||
|
@ -114,10 +117,10 @@ class ReviewFeed(Feed):
|
|||
else _("Link invalid")
|
||||
)
|
||||
|
||||
def link(self, owner):
|
||||
def link(self, owner: APIdentity):
|
||||
return owner.url if owner else settings.SITE_INFO["site_url"]
|
||||
|
||||
def description(self, owner):
|
||||
def description(self, owner: APIdentity):
|
||||
if not owner:
|
||||
return _("Link invalid")
|
||||
elif not owner.anonymous_viewable:
|
||||
|
@ -125,7 +128,7 @@ class ReviewFeed(Feed):
|
|||
else:
|
||||
return _("Reviews by {0}").format(owner.display_name)
|
||||
|
||||
def items(self, owner):
|
||||
def items(self, owner: APIdentity):
|
||||
if owner is None or not owner.anonymous_viewable:
|
||||
return []
|
||||
reviews = Review.objects.filter(owner=owner, visibility=0)[:MAX_ITEM_PER_TYPE]
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.conf import settings
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
from django.utils import translation
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from users.models import User
|
||||
|
||||
def activate_language_for_user(user, request=None):
|
||||
|
||||
def activate_language_for_user(user: "User | None", request=None):
|
||||
user_language = None
|
||||
if user and user.is_authenticated:
|
||||
user_language = getattr(user, "language", "")
|
||||
|
|
Loading…
Add table
Reference in a new issue