Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 17, 2024
1 parent 860a95e commit 4468b30
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
71 changes: 48 additions & 23 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,11 @@ msgid "Name"
msgstr ""

#: subjects.html
msgid "Edit Subject Tag"
msgid "Edit tag for this subject"
msgstr ""

#: subjects.html
msgid "Create tag for this subject"
msgstr ""

#: subjects.html
Expand All @@ -725,6 +729,10 @@ msgstr[1] ""
msgid "Search for books with subject %(name)s."
msgstr ""

#: subjects.html
msgid "Disambiguations"
msgstr ""

#: support.html
msgid "How can we help?"
msgstr ""
Expand Down Expand Up @@ -786,7 +794,7 @@ msgstr ""
#: CreateListModal.html EditButtons.html account/notifications.html
#: account/password/reset.html account/privacy.html admin/imports-add.html
#: admin/permissions.html books/add.html databarEdit.html merge/authors.html
#: my_books/dropdown_content.html support.html tag/add.html
#: my_books/dropdown_content.html support.html type/tag/form.html
msgid "Cancel"
msgstr ""

Expand Down Expand Up @@ -1987,7 +1995,7 @@ msgid "Imports"
msgstr ""

#: admin/imports-add.html books/add.html books/edit/edition.html
#: books/edit/excerpts.html covers/change.html tag/add.html
#: books/edit/excerpts.html covers/change.html type/tag/form.html
msgid "Add"
msgstr ""

Expand Down Expand Up @@ -3165,7 +3173,7 @@ msgstr ""
msgid "Add a book to Open Library"
msgstr ""

#: books/add.html tag/add.html
#: books/add.html
msgid ""
"We require a minimum set of fields to create a new record. These are "
"those fields."
Expand Down Expand Up @@ -3263,7 +3271,7 @@ msgstr ""
msgid "Only fill this out if this is a web book"
msgstr ""

#: EditButtons.html books/add.html tag/add.html
#: EditButtons.html books/add.html type/tag/form.html
msgid ""
"By saving a change to this wiki, you agree that your contribution is "
"given freely to the world under <a "
Expand Down Expand Up @@ -6249,18 +6257,6 @@ msgstr ""
msgid "OpenAPI"
msgstr ""

#: tag/add.html
msgid "Add a tag"
msgstr ""

#: tag/add.html
msgid "Add a tag to Open Library"
msgstr ""

#: tag/add.html
msgid "Add this tag now"
msgstr ""

#: type/about/edit.html type/page/edit.html type/permission/edit.html
#: type/template/edit.html type/usergroup/edit.html
#, python-format
Expand Down Expand Up @@ -6890,8 +6886,24 @@ msgstr ""
msgid "Writers"
msgstr ""

#: type/tag/edit.html
msgid "Edit Tag"
#: type/tag/form.html
msgid "Edit tag"
msgstr ""

#: type/tag/form.html
msgid "Add a tag"
msgstr ""

#: type/tag/form.html
msgid "Add a tag to Open Library"
msgstr ""

#: type/tag/form.html
msgid "We require a minimum set of fields to create a new collection tag."
msgstr ""

#: type/tag/form.html
msgid "Add this tag now"
msgstr ""

#: type/tag/tag_form_inputs.html
Expand All @@ -6902,10 +6914,27 @@ msgstr ""
msgid "Tag Description"
msgstr ""

#: type/tag/tag_form_inputs.html
msgid "Page Body"
msgstr ""

#: type/tag/tag_form_inputs.html
msgid "Tag type"
msgstr ""

#: type/tag/view.html
#, python-format
msgid "<strong>Type:</strong> %(tag_type)s"
msgstr ""

#: type/tag/view.html type/user/edit.html
msgid "Description"
msgstr ""

#: type/tag/view.html
msgid "Tag Body"
msgstr ""

#: type/tag/view.html
#, python-format
msgid "View subject page for %(name)s."
Expand Down Expand Up @@ -6956,10 +6985,6 @@ msgstr ""
msgid "Display Name"
msgstr ""

#: type/user/edit.html
msgid "Description"
msgstr ""

#: type/user/view.html
msgid "admin page"
msgstr ""
Expand Down
12 changes: 8 additions & 4 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def get_subject_tag_types():


def validate_tag(tag):
return tag.get('name', '') and tag.get('tag_type', '') in get_tag_types() and tag.get('body')
return (
tag.get('name', '')
and tag.get('tag_type', '') in get_tag_types()
and tag.get('body')
)


def validate_subject_tag(tag):
Expand Down Expand Up @@ -66,7 +70,7 @@ def find_match(name: str, tag_type: str) -> str:
Tries to find an existing tag that matches the data provided by the user.
Returns the key of the matching tag, or an empty string if no such tag exists.
"""
matches = Tag.find(name, tag_type=tag_type)
matches = Tag.find(name, tag_type=tag_type)
return matches[0] if matches else ''


Expand Down Expand Up @@ -120,7 +124,7 @@ def POST(self):
# A tag with the same name and type already exists
add_flash_message(
'error',
f'A matching tag with the same name and type already exists: <a href="{match}">{match}</a>'
f'A matching tag with the same name and type already exists: <a href="{match}">{match}</a>',
)
return render_template('type/tag/form', i)

Expand Down Expand Up @@ -171,7 +175,7 @@ def POST(self, key):
# A tag with the same name and type already exists
add_flash_message(
'error',
f'A matching tag with the same name and type already exists: <a href="{match}">{match}</a>'
f'A matching tag with the same name and type already exists: <a href="{match}">{match}</a>',
)
return render_template("type/tag/form", formdata, redirect=i.redir)

Expand Down
13 changes: 9 additions & 4 deletions openlibrary/plugins/worksearch/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ def normalize_key(self, key):
return key

def decorate_with_tags(self, subject) -> None:
tag_keys = Tag.find(subject.name)
if tag_keys:
if tag_keys := Tag.find(subject.name):
tags = web.ctx.site.get_many(tag_keys)
subject.disambiguations = tags

if filtered_tags := [tag for tag in tags if tag.tag_type == subject.subject_type]:
if filtered_tags := [
tag for tag in tags if tag.tag_type == subject.subject_type
]:
subject.tag = filtered_tags[0]
# Remove matching subject tag from disambiguated tags:
subject.disambiguations = list(set(tags) - {subject.tag})

for tag in subject.disambiguations:
tag.subject_key = f"/subjects/{tag.name}" if tag.tag_type == "subject" else f"/subjects/{tag.tag_type}:{tag.name}"
tag.subject_key = (
f"/subjects/{tag.name}"
if tag.tag_type == "subject"
else f"/subjects/{tag.tag_type}:{tag.name}"
)


class subjects_json(delegate.page):
Expand Down

0 comments on commit 4468b30

Please sign in to comment.