Set preferred language

This commit is contained in:
Mouse Reeve 2021-04-29 10:40:49 -07:00
parent ca86af22ce
commit b1c38d291c
5 changed files with 26 additions and 5 deletions

View file

@ -7,6 +7,9 @@ DEBUG=true
DOMAIN=your.domain.here DOMAIN=your.domain.here
#EMAIL=your@email.here #EMAIL=your@email.here
# Used for deciding which editions to prefer
DEFAULT_LANGUAGE="English"
## Leave unset to allow all hosts ## Leave unset to allow all hosts
# ALLOWED_HOSTS="localhost,127.0.0.1,[::1]" # ALLOWED_HOSTS="localhost,127.0.0.1,[::1]"

View file

@ -7,6 +7,9 @@ DEBUG=false
DOMAIN=your.domain.here DOMAIN=your.domain.here
EMAIL=your@email.here EMAIL=your@email.here
# Used for deciding which editions to prefer
DEFAULT_LANGUAGE="English"
## Leave unset to allow all hosts ## Leave unset to allow all hosts
# ALLOWED_HOSTS="localhost,127.0.0.1,[::1]" # ALLOWED_HOSTS="localhost,127.0.0.1,[::1]"

View file

@ -23,7 +23,9 @@ class Connector(AbstractConnector):
Mapping("title", remote_field="wdt:P1476", formatter=get_first), Mapping("title", remote_field="wdt:P1476", formatter=get_first),
Mapping("subtitle", remote_field="wdt:P1680", formatter=get_first), Mapping("subtitle", remote_field="wdt:P1680", formatter=get_first),
Mapping("inventaireId", remote_field="uri"), Mapping("inventaireId", remote_field="uri"),
Mapping("description", remote_field="sitelinks", formatter=self.get_description), Mapping(
"description", remote_field="sitelinks", formatter=self.get_description
),
Mapping("cover", remote_field="image", formatter=self.get_cover_url), Mapping("cover", remote_field="image", formatter=self.get_cover_url),
Mapping("isbn13", remote_field="wdt:P212", formatter=get_first), Mapping("isbn13", remote_field="wdt:P212", formatter=get_first),
Mapping("isbn10", remote_field="wdt:P957", formatter=get_first), Mapping("isbn10", remote_field="wdt:P957", formatter=get_first),
@ -84,7 +86,9 @@ class Connector(AbstractConnector):
return SearchResult( return SearchResult(
title=search_result.get("label"), title=search_result.get("label"),
key=self.get_remote_id(search_result.get("uri")), key=self.get_remote_id(search_result.get("uri")),
view_link="{:s}/entity/{:s}".format(self.base_url, search_result.get("uri")), view_link="{:s}/entity/{:s}".format(
self.base_url, search_result.get("uri")
),
cover=cover, cover=cover,
connector=self, connector=self,
) )
@ -104,7 +108,9 @@ class Connector(AbstractConnector):
return SearchResult( return SearchResult(
title=title[0], title=title[0],
key=self.get_remote_id(search_result.get("uri")), key=self.get_remote_id(search_result.get("uri")),
view_link="{:s}/entity/{:s}".format(self.base_url, search_result.get("uri")), view_link="{:s}/entity/{:s}".format(
self.base_url, search_result.get("uri")
),
cover=self.get_cover_url(search_result.get("image")), cover=self.get_cover_url(search_result.get("image")),
connector=self, connector=self,
) )
@ -187,7 +193,7 @@ class Connector(AbstractConnector):
return results return results
def get_description(self, links): def get_description(self, links):
""" grab an extracted except from wikipedia """ """grab an extracted except from wikipedia"""
link = links.get("enwiki") link = links.get("enwiki")
if not link: if not link:
return "" return ""

View file

@ -5,7 +5,7 @@ from django.db import models
from model_utils.managers import InheritanceManager from model_utils.managers import InheritanceManager
from bookwyrm import activitypub from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN from bookwyrm.settings import DOMAIN, DEFAULT_LANGUAGE
from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin from .activitypub_mixin import OrderedCollectionPageMixin, ObjectMixin
from .base_model import BookWyrmModel from .base_model import BookWyrmModel
@ -211,7 +211,15 @@ class Edition(Book):
def get_rank(self): def get_rank(self):
"""calculate how complete the data is on this edition""" """calculate how complete the data is on this edition"""
rank = 0 rank = 0
# big ups for havinga cover
rank += int(bool(self.cover)) * 3 rank += int(bool(self.cover)) * 3
# is it in the instance's preferred language?
rank += int(bool(DEFAULT_LANGUAGE in self.languages))
print(DEFAULT_LANGUAGE)
# prefer print editions
rank += int(bool(self.physical_format.lower() in ['paperback', 'hardcover']))
# does it have metadata?
rank += int(bool(self.isbn_13)) rank += int(bool(self.isbn_13))
rank += int(bool(self.isbn_10)) rank += int(bool(self.isbn_10))
rank += int(bool(self.oclc_number)) rank += int(bool(self.oclc_number))

View file

@ -11,6 +11,7 @@ DOMAIN = env("DOMAIN")
VERSION = "0.0.1" VERSION = "0.0.1"
PAGE_LENGTH = env("PAGE_LENGTH", 15) PAGE_LENGTH = env("PAGE_LENGTH", 15)
DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English")
# celery # celery
CELERY_BROKER = env("CELERY_BROKER") CELERY_BROKER = env("CELERY_BROKER")