Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RUF012) Fixed mutable class Defaults- Task 1 #10278 #10281

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ msgstr ""
msgid "Batch Imports"
msgstr ""

#: BatchImportNavigation.html batch_import.html
msgid "New Batch Import"
msgstr ""

#: batch_import.html
msgid ""
"Attach a JSONL formatted document with import records or copy/paste the "
Expand Down Expand Up @@ -7146,6 +7150,10 @@ msgid ""
"class=\"nostyle\" href=\"/help/faq/about#selling\">small commission</a>."
msgstr ""

#: BatchImportNavigation.html
msgid "Pending Imports"
msgstr ""

#: BookByline.html
#, python-format
msgid "%(n)s other"
Expand Down
10 changes: 10 additions & 0 deletions openlibrary/macros/BatchImportNavigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$def with ()

<ul class="nav-bar">
<li class="$('selected' if ctx.path=='/new' else '')">
<a data-ol-link-track="BatchImportNav|Submit" href="/import/batch/new">$_("New Batch Import")</a>
</li>
<li class="$('selected' if ctx.path=='/pending' else '')">
<a data-ol-link-track="BatchImportNav|Pending" href="/import/batch/pending">$_("Pending Imports")</a>
</li>
</ul>
20 changes: 11 additions & 9 deletions openlibrary/plugins/worksearch/schemes/authors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
from collections.abc import Callable
from datetime import datetime
from typing import ClassVar

from openlibrary.plugins.worksearch.schemes import SearchScheme

logger = logging.getLogger("openlibrary.worksearch")


class AuthorSearchScheme(SearchScheme):
universe = ['type:author']
all_fields = {
universe: ClassVar[list] = ['type:author']
all_fields: ClassVar[set] = {
'key',
'name',
'alternate_names',
Expand All @@ -19,10 +19,10 @@ class AuthorSearchScheme(SearchScheme):
'top_subjects',
'work_count',
}
non_solr_fields: set[str] = set()
facet_fields: set[str] = set()
field_name_map: dict[str, str] = {}
sorts = {
non_solr_fields: ClassVar[set] = set()
facet_fields: ClassVar[set] = set()
field_name_map: ClassVar[dict] = {}
sorts: ClassVar[dict] = {
'work_count desc': 'work_count desc',
# Random
'random': 'random_1 asc',
Expand All @@ -31,7 +31,7 @@ class AuthorSearchScheme(SearchScheme):
'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc',
'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc',
}
default_fetched_fields = {
default_fetched_fields: ClassVar[set] = { # Annotated with ClassVar
'key',
'name',
'birth_date',
Expand All @@ -40,7 +40,9 @@ class AuthorSearchScheme(SearchScheme):
'top_subjects',
'work_count',
}
facet_rewrites: dict[tuple[str, str], str | Callable[[], str]] = {}
facet_rewrites: ClassVar[dict] = { # Annotated with ClassVar
('public_scan', 'true'): 'ebook_access:public'
}

def q_to_solr_params(
self,
Expand Down
23 changes: 10 additions & 13 deletions openlibrary/plugins/worksearch/schemes/subjects.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import logging
from collections.abc import Callable
from datetime import datetime
from typing import ClassVar

from openlibrary.plugins.worksearch.schemes import SearchScheme

logger = logging.getLogger("openlibrary.worksearch")


class SubjectSearchScheme(SearchScheme):
universe = ['type:subject']
all_fields = {
universe: ClassVar[list] = ['type:subject']
all_fields: ClassVar[set] = {
'key',
'name',
'subject_type',
'work_count',
}
non_solr_fields: set[str] = set()
facet_fields: set[str] = set()
field_name_map: dict[str, str] = {}
sorts = {
non_solr_fields: ClassVar[set] = set()
facet_fields: ClassVar[set] = set()
field_name_map: ClassVar[dict] = {}
sorts: ClassVar[dict] = {
'work_count desc': 'work_count desc',
# Random
'random': 'random_1 asc',
Expand All @@ -27,19 +27,16 @@ class SubjectSearchScheme(SearchScheme):
'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc',
'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc',
}
default_fetched_fields = {
default_fetched_fields: ClassVar[set] = {
'key',
'name',
'subject_type',
'work_count',
}
facet_rewrites: dict[tuple[str, str], str | Callable[[], str]] = {}
facet_rewrites: ClassVar[dict] = {('public_scan', 'true'): 'ebook_access:public'}

def q_to_solr_params(
self,
q: str,
solr_fields: set[str],
cur_solr_params: list[tuple[str, str]],
self, q: str, solr_fields: set[str], cur_solr_params: list[tuple[str, str]]
) -> list[tuple[str, str]]:
return [
('q', q),
Expand Down
18 changes: 9 additions & 9 deletions openlibrary/plugins/worksearch/schemes/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Callable
from copy import deepcopy
from datetime import datetime
from typing import Any, cast
from typing import Any, ClassVar, cast

import luqum.tree
import web
Expand Down Expand Up @@ -39,8 +39,8 @@


class WorkSearchScheme(SearchScheme):
universe = ['type:work']
all_fields = {
universe = ClassVar[list]
all_fields: ClassVar[set] = {
"key",
"redirects",
"title",
Expand Down Expand Up @@ -95,11 +95,11 @@ class WorkSearchScheme(SearchScheme):
"ddc_sort",
"osp_count",
}
non_solr_fields = {
non_solr_fields: ClassVar[set] = {
'description',
'providers',
}
facet_fields = {
facet_fields: ClassVar[set] = {
"has_fulltext",
"author_facet",
"language",
Expand All @@ -111,7 +111,7 @@ class WorkSearchScheme(SearchScheme):
"time_facet",
"public_scan_b",
}
field_name_map = {
field_name_map: ClassVar[dict] = {
'author': 'author_name',
'authors': 'author_name',
'by': 'author_name',
Expand All @@ -126,7 +126,7 @@ class WorkSearchScheme(SearchScheme):
# plain string at the next opportunity, which will make it much more usable.
'_ia_collection': 'ia_collection_s',
}
sorts = {
sorts: ClassVar[dict] = {
'editions': 'edition_count desc',
'old': 'def(first_publish_year, 9999) asc',
'new': 'first_publish_year desc',
Expand Down Expand Up @@ -165,7 +165,7 @@ class WorkSearchScheme(SearchScheme):
'random.hourly': lambda: f'random_{datetime.now():%Y%m%dT%H} asc',
'random.daily': lambda: f'random_{datetime.now():%Y%m%d} asc',
}
default_fetched_fields = {
default_fetched_fields: ClassVar[set] = {
'key',
'author_name',
'author_key',
Expand All @@ -192,7 +192,7 @@ class WorkSearchScheme(SearchScheme):
'id_cita_press',
'id_wikisource',
}
facet_rewrites = {
facet_rewrites: ClassVar[dict] = {
('public_scan', 'true'): 'ebook_access:public',
('public_scan', 'false'): '-ebook_access:public',
('print_disabled', 'true'): 'ebook_access:printdisabled',
Expand Down
3 changes: 2 additions & 1 deletion openlibrary/templates/batch_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
$var title: $_("Batch Imports")

<div id="contentHead">
<h1>$_("Batch Imports")</h1>
<h1>$_("New Batch Import")</h1>
</div>
<div id="contentBody" class="batchImport">
$:macros.BatchImportNavigation()
<p>$_('Attach a JSONL formatted document with import records or copy/paste the JSONL text into the textarea.')</p>
<p>$:_('See the <a href=\"https://github.com/internetarchive/openlibrary-client/tree/master/olclient/schemata\">olclient import schemata</a> for more.')</p>
<form method="POST" enctype="multipart/form-data" action="">
Expand Down
1 change: 1 addition & 0 deletions openlibrary/templates/batch_import_pending_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<h1>$_("Pending Batch Imports")</h1>
</div>
<div id="contentBody" class="batchImportPendingStatus">
$:macros.BatchImportNavigation()
<table class="changeHistory">
<thead>
<tr>
Expand Down
Loading