add language filter to discover page
This commit is contained in:
parent
e3d629ea77
commit
6f7043e54f
5 changed files with 39 additions and 8 deletions
|
@ -83,6 +83,8 @@ env = environ.FileAwareEnv(
|
||||||
NEODB_DOWNLOADER_RETRIES=(int, 3),
|
NEODB_DOWNLOADER_RETRIES=(int, 3),
|
||||||
# Number of marks required for an item to be included in discover
|
# Number of marks required for an item to be included in discover
|
||||||
NEODB_MIN_MARKS_FOR_DISCOVER=(int, 1),
|
NEODB_MIN_MARKS_FOR_DISCOVER=(int, 1),
|
||||||
|
# if True, only show title language with NEODB_PREFERRED_LANGUAGES
|
||||||
|
NEODB_FILTER_LANGUAGE_FOR_DISCOVER=(bool, False),
|
||||||
# Disable cron jobs, * for all
|
# Disable cron jobs, * for all
|
||||||
NEODB_DISABLE_CRON_JOBS=(list, []),
|
NEODB_DISABLE_CRON_JOBS=(list, []),
|
||||||
# federated search peers
|
# federated search peers
|
||||||
|
@ -215,6 +217,8 @@ DISABLE_DEFAULT_RELAY = env("NEODB_DISABLE_DEFAULT_RELAY", default=DEBUG)
|
||||||
|
|
||||||
MIN_MARKS_FOR_DISCOVER = env("NEODB_MIN_MARKS_FOR_DISCOVER")
|
MIN_MARKS_FOR_DISCOVER = env("NEODB_MIN_MARKS_FOR_DISCOVER")
|
||||||
|
|
||||||
|
FILTER_LANGUAGE_FOR_DISCOVER = env("NEODB_FILTER_LANGUAGE_FOR_DISCOVER")
|
||||||
|
|
||||||
MASTODON_ALLOWED_SITES = env("NEODB_LOGIN_MASTODON_WHITELIST")
|
MASTODON_ALLOWED_SITES = env("NEODB_LOGIN_MASTODON_WHITELIST")
|
||||||
|
|
||||||
# Allow user to login via any Mastodon/Pleroma sites
|
# Allow user to login via any Mastodon/Pleroma sites
|
||||||
|
|
|
@ -3,13 +3,14 @@ from datetime import timedelta
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.db.models import Count, F
|
from django.db.models import Count, F, Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from boofilsic.settings import MIN_MARKS_FOR_DISCOVER
|
from boofilsic.settings import MIN_MARKS_FOR_DISCOVER
|
||||||
from catalog.models import *
|
from catalog.models import *
|
||||||
from common.models import BaseJob, JobManager
|
from common.models import BaseJob, JobManager
|
||||||
|
from common.models.lang import PREFERRED_LOCALES
|
||||||
from journal.models import (
|
from journal.models import (
|
||||||
Collection,
|
Collection,
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -33,12 +34,23 @@ class DiscoverGenerator(BaseJob):
|
||||||
interval = timedelta(hours=1)
|
interval = timedelta(hours=1)
|
||||||
|
|
||||||
def get_popular_marked_item_ids(self, category, days, exisiting_ids):
|
def get_popular_marked_item_ids(self, category, days, exisiting_ids):
|
||||||
item_ids = [
|
qs = (
|
||||||
m["item_id"]
|
ShelfMember.objects.filter(q_item_in_category(category))
|
||||||
for m in ShelfMember.objects.filter(q_item_in_category(category))
|
|
||||||
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
||||||
.exclude(item_id__in=exisiting_ids)
|
.exclude(item_id__in=exisiting_ids)
|
||||||
.values("item_id")
|
)
|
||||||
|
if settings.FILTER_LANGUAGE_FOR_DISCOVER:
|
||||||
|
q = None
|
||||||
|
for loc in PREFERRED_LOCALES:
|
||||||
|
if q:
|
||||||
|
q = q | Q(item__metadata__localized_title__contains=[{"lang": loc}])
|
||||||
|
else:
|
||||||
|
q = Q(item__metadata__localized_title__contains=[{"lang": loc}])
|
||||||
|
if q:
|
||||||
|
qs = qs.filter(q)
|
||||||
|
item_ids = [
|
||||||
|
m["item_id"]
|
||||||
|
for m in qs.values("item_id")
|
||||||
.annotate(num=Count("item_id"))
|
.annotate(num=Count("item_id"))
|
||||||
.filter(num__gte=MIN_MARKS)
|
.filter(num__gte=MIN_MARKS)
|
||||||
.order_by("-num")[:MAX_ITEMS_PER_PERIOD]
|
.order_by("-num")[:MAX_ITEMS_PER_PERIOD]
|
||||||
|
|
|
@ -5,6 +5,7 @@ import dateparser
|
||||||
from catalog.common import *
|
from catalog.common import *
|
||||||
from catalog.models import *
|
from catalog.models import *
|
||||||
from common.models.lang import detect_language
|
from common.models.lang import detect_language
|
||||||
|
from common.models.misc import uniq
|
||||||
|
|
||||||
from .douban import DoubanDownloader
|
from .douban import DoubanDownloader
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ class DoubanGame(AbstractSite):
|
||||||
)
|
)
|
||||||
img_url = img_url_elem[0].strip() if img_url_elem else None
|
img_url = img_url_elem[0].strip() if img_url_elem else None
|
||||||
|
|
||||||
titles = set([title] + other_title + ([orig_title] if orig_title else []))
|
titles = uniq([title] + other_title + ([orig_title] if orig_title else []))
|
||||||
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
|
localized_title = [{"lang": detect_language(t), "text": t} for t in titles]
|
||||||
localized_desc = [{"lang": detect_language(brief), "text": brief}]
|
localized_desc = [{"lang": detect_language(brief), "text": brief}]
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,20 @@ ZH_LANGUAGE_SUBTAGS = {
|
||||||
"hak": _("Hakka Chinese"),
|
"hak": _("Hakka Chinese"),
|
||||||
}
|
}
|
||||||
|
|
||||||
ZH_LOCALE_SUBTAGS_PRIO.keys()
|
|
||||||
|
def get_preferred_locales():
|
||||||
|
locales = []
|
||||||
|
for k in PREFERRED_LANGUAGES:
|
||||||
|
if k == "zh":
|
||||||
|
locales += list(ZH_LOCALE_SUBTAGS_PRIO.keys()) + list(
|
||||||
|
ZH_LOCALE_SUBTAGS.keys()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
locales.append(k)
|
||||||
|
return locales
|
||||||
|
|
||||||
|
|
||||||
|
PREFERRED_LOCALES = get_preferred_locales()
|
||||||
|
|
||||||
|
|
||||||
def get_base_lang_list():
|
def get_base_lang_list():
|
||||||
|
|
|
@ -25,7 +25,7 @@ x-shared:
|
||||||
NEODB_SITE_LINKS:
|
NEODB_SITE_LINKS:
|
||||||
NEODB_SITE_DESCRIPTION:
|
NEODB_SITE_DESCRIPTION:
|
||||||
NEODB_ALTERNATIVE_DOMAINS:
|
NEODB_ALTERNATIVE_DOMAINS:
|
||||||
NEODB_LANGUAGE:
|
NEODB_PREFERRED_LANGUAGES:
|
||||||
NEODB_ADMIN_USERNAMES:
|
NEODB_ADMIN_USERNAMES:
|
||||||
NEODB_INVITE_ONLY:
|
NEODB_INVITE_ONLY:
|
||||||
NEODB_LOGIN_MASTODON_WHITELIST:
|
NEODB_LOGIN_MASTODON_WHITELIST:
|
||||||
|
@ -34,6 +34,7 @@ x-shared:
|
||||||
NEODB_DISABLE_CRON_JOBS:
|
NEODB_DISABLE_CRON_JOBS:
|
||||||
NEODB_SEARCH_PEERS:
|
NEODB_SEARCH_PEERS:
|
||||||
NEODB_MIN_MARKS_FOR_DISCOVER:
|
NEODB_MIN_MARKS_FOR_DISCOVER:
|
||||||
|
NEODB_FILTER_LANGUAGE_FOR_DISCOVER:
|
||||||
NEODB_SENTRY_DSN:
|
NEODB_SENTRY_DSN:
|
||||||
TAKAHE_SENTRY_DSN:
|
TAKAHE_SENTRY_DSN:
|
||||||
NEODB_SENTRY_SAMPLE_RATE:
|
NEODB_SENTRY_SAMPLE_RATE:
|
||||||
|
|
Loading…
Add table
Reference in a new issue