Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-node-20
Browse files Browse the repository at this point in the history
  • Loading branch information
RayBB committed Sep 26, 2023
2 parents d774b5c + 1205b5f commit 00d6b6e
Show file tree
Hide file tree
Showing 21 changed files with 306 additions and 279 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.288
rev: v0.0.291
hooks:
- id: ruff

Expand Down Expand Up @@ -66,7 +66,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.49.0
rev: v8.50.0
hooks:
- id: eslint
types: [file]
Expand Down
2 changes: 1 addition & 1 deletion bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
{
"path": "static/build/lists.*.js",
"maxSize": "5.5KB"
"maxSize": "8KB"
},
{
"path": "static/build/all.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
* Defines functionality related to librarian request table and header.
*
* Base template for the table is openlibrary/templates/merge_queue/merge_queue.html
* @module merge-request-table/LibrarianQueue
* @module merge-request-table/MergeRequestTable
*/

import TableHeader from './LibrarianQueue/TableHeader'
import { setI18nStrings, TableRow } from './LibrarianQueue/TableRow'
import TableHeader from './MergeRequestTable/TableHeader'
import { setI18nStrings, TableRow } from './MergeRequestTable/TableRow'

/**
* Class representing the librarian request table.
*
* @class
*/
export default class LibrarianQueue {
export default class MergeRequestTable {

/**
* Creates references to the table and its header and hydrates each.
*
* @param {HTMLElement} librarianRequestTable
* @param {HTMLElement} mergeRequestTable
*/
constructor(librarianRequestTable) {
constructor(mergeRequestTable) {
/**
* The `username` of the authenticated patron, or '' if logged out.
*
* @param {string}
*/
this.username = librarianRequestTable.dataset.username
this.username = mergeRequestTable.dataset.username

const localizedStrings = JSON.parse(librarianRequestTable.dataset.i18n)
const localizedStrings = JSON.parse(mergeRequestTable.dataset.i18n)
setI18nStrings(localizedStrings)

/**
* Reference to this table's header.
*
* @param {HTMLElement}
*/
this.tableHeader = new TableHeader(librarianRequestTable.querySelector('.table-header'))
this.tableHeader = new TableHeader(mergeRequestTable.querySelector('.table-header'))

/**
* References to each row in the table.
*
* @param {Array<TableRow>}
*/
this.tableRows = []
const rowElements = librarianRequestTable.querySelectorAll('.mr-table-row')
const rowElements = mergeRequestTable.querySelectorAll('.mr-table-row')
for (const elem of rowElements) {
this.tableRows.push(new TableRow(elem, this.username))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Defines functionality related to librarian request table header.
*
* @module merge-request-table/LibrarianQueue/TableHeader
* @module merge-request-table/MergeRequestTable/TableHeader
*/

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Defines functionality related to librarian request table rows.
*
* @module merge-request-table/LibrarianQueue/TableRow
* @module merge-request-table/MergeRequestTable/TableRow
*/

import { claimRequest, commentOnRequest, declineRequest, unassignRequest } from '../MergeRequestService'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import LibrarianQueue from './LibrarianQueue';
import MergeRequestTable from './MergeRequestTable';

/**
* Hydrates given librarian request queue.
*
* @param {HTMLElement} elem Reference to the queue's root element.
*/
export function initLibrarianQueue(elem) {
const librarianQueue = new LibrarianQueue(elem)
const librarianQueue = new MergeRequestTable(elem)
librarianQueue.initialize()
}
2 changes: 1 addition & 1 deletion openlibrary/plugins/upstream/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def GET(self):
}

return render_template(
'merge_queue/merge_queue',
'merge_request_table/merge_request_table',
total_found,
librarians,
merge_requests=merge_requests,
Expand Down
6 changes: 3 additions & 3 deletions openlibrary/solr/data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class DataProvider:
"""

def __init__(self) -> None:
self.ia_cache: dict[str, Optional[dict]] = {}
self.ia_cache: dict[str, dict | None] = {}

@staticmethod
async def _get_lite_metadata(ocaids: list[str], _recur_depth=0, _max_recur_depth=3):
Expand Down Expand Up @@ -285,7 +285,7 @@ def get_editions_of_work(self, work):
"""
raise NotImplementedError()

def get_work_ratings(self, work_key: str) -> Optional[WorkRatingsSummary]:
def get_work_ratings(self, work_key: str) -> WorkRatingsSummary | None:
raise NotImplementedError()

def get_work_reading_log(self, work_key: str) -> WorkReadingLogSolrSummary | None:
Expand Down Expand Up @@ -318,7 +318,7 @@ async def get_document(self, key):
logger.info("get_document %s", key)
return self._withKey(key)

def get_work_ratings(self, work_key: str) -> Optional[WorkRatingsSummary]:
def get_work_ratings(self, work_key: str) -> WorkRatingsSummary | None:
work_id = int(work_key[len('/works/OL') : -len('W')])
return Ratings.get_work_ratings_summary(work_id)

Expand Down
2 changes: 1 addition & 1 deletion openlibrary/solr/query_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def luqum_parser(query: str) -> Item:
"""
tree = parser.parse(query)

def find_next_word(item: Item) -> Optional[tuple[Word, Optional[BaseOperation]]]:
def find_next_word(item: Item) -> tuple[Word, BaseOperation | None] | None:
if isinstance(item, Word):
return item, None
elif isinstance(item, BaseOperation) and isinstance(item.children[0], Word):
Expand Down
14 changes: 7 additions & 7 deletions openlibrary/solr/update_edition.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def key(self):
return self.edition['key']

@property
def title(self) -> Optional[str]:
def title(self) -> str | None:
return self.get('title')

@property
def subtitle(self) -> Optional[str]:
def subtitle(self) -> str | None:
return self.get('subtitle')

@property
Expand All @@ -60,7 +60,7 @@ def alternative_title(self) -> set[str]:
return result

@property
def cover_i(self) -> Optional[int]:
def cover_i(self) -> int | None:
return next(
(cover_id for cover_id in self.get('covers', []) if cover_id != -1), None
)
Expand All @@ -83,7 +83,7 @@ def publisher(self) -> list[str]:
)

@property
def number_of_pages(self) -> Optional[int]:
def number_of_pages(self) -> int | None:
try:
return int(self.get('number_of_pages')) or None
except (TypeError, ValueError): # int(None) -> TypeErr, int("vii") -> ValueErr
Expand All @@ -110,19 +110,19 @@ def lccn(self) -> list[str]:
return uniq(lccn.strip() for lccn in self.get('lccn', []))

@property
def publish_date(self) -> Optional[str]:
def publish_date(self) -> str | None:
return self.get('publish_date')

@property
def publish_year(self) -> Optional[int]:
def publish_year(self) -> int | None:
if self.publish_date:
m = re_year.search(self.publish_date)
return int(m.group(1)) if m else None
else:
return None

@property
def ia(self) -> Optional[str]:
def ia(self) -> str | None:
ocaid = self.get('ocaid')
return ocaid.strip() if ocaid else None

Expand Down
10 changes: 5 additions & 5 deletions openlibrary/solr/update_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
data_provider = cast(DataProvider, None)

solr_base_url = None
solr_next: Optional[bool] = None
solr_next: bool | None = None


def get_solr_base_url():
Expand Down Expand Up @@ -187,8 +187,8 @@ def pick_cover_edition(editions, work_cover_id):
)


def pick_number_of_pages_median(editions: list[dict]) -> Optional[int]:
def to_int(x: Any) -> Optional[int]:
def pick_number_of_pages_median(editions: list[dict]) -> int | None:
def to_int(x: Any) -> int | None:
try:
return int(x) or None
except (TypeError, ValueError): # int(None) -> TypeErr, int("vii") -> ValueErr
Expand Down Expand Up @@ -1245,7 +1245,7 @@ async def update_work(work: dict) -> list[SolrUpdateRequest]:

async def update_author(
akey, a=None, handle_redirects=True
) -> Optional[list[SolrUpdateRequest]]:
) -> list[SolrUpdateRequest] | None:
"""
Get the Solr requests necessary to insert/update/delete an Author in Solr.
:param akey: The author key, e.g. /authors/OL23A
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def load_configs(
c_host: str,
c_config: str,
c_data_provider: (
Union[DataProvider, Literal['default', 'legacy', 'external']]
DataProvider | Literal["default", "legacy", "external"]
) = 'default',
) -> DataProvider:
host = web.lstrips(c_host, "http://").strip("/")
Expand Down
14 changes: 12 additions & 2 deletions openlibrary/templates/account/books.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,19 @@

$ url_prefix = "/people/" + username
$ readlog_url = url_prefix + "/books/%s/"
$ options = [(_("Want to Read (%(count)d)", count=shelf_counts['want-to-read']), readlog_url % "want-to-read"), (_("Currently Reading (%(count)d)", count=shelf_counts['currently-reading']), readlog_url % "currently-reading"), (_("Already Read (%(count)d)", count=shelf_counts['already-read']), readlog_url % "already-read"), (_("My Lists (%(count)d)" if owners_page else "Lists (%(count)d)", count=len(lists)) , url_prefix + "/lists")]
$ options = [
$ (_("Want to Read (%(count)d)", count=shelf_counts['want-to-read']), readlog_url % "want-to-read"),
$ (_("Currently Reading (%(count)d)", count=shelf_counts['currently-reading']), readlog_url % "currently-reading"),
$ (_("Already Read (%(count)d)", count=shelf_counts['already-read']), readlog_url % "already-read"),
$ (_("My Lists (%(count)d)" if owners_page else "Lists (%(count)d)", count=len(lists)) , url_prefix + "/lists")
$ ]
$if owners_page:
$ options = [("My Loans", "/account/loans")] + options + [(_("My Notes"), url_prefix + "/books/notes"), (_("My Reviews"), url_prefix + "/books/observations")]
$ options += [
$ (_("My Loans"), "/account/loans"),
$ (_("My Notes"), url_prefix + "/books/notes"),
$ (_("My Reviews"), url_prefix + "/books/observations"),
$ (_("Imports and Exports"), "/account/import")
$ ]

<div class="mybooks">

Expand Down
Loading

0 comments on commit 00d6b6e

Please sign in to comment.