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 9, 2024
1 parent 1c17c70 commit 01aaaf0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
53 changes: 48 additions & 5 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ msgstr ""

#: account.html check_ins/check_in_prompt.html
#: check_ins/reading_goal_progress.html databarHistory.html
#: databarTemplate.html databarView.html subjects.html
#: type/edition/compact_title.html type/user/view.html
#: databarTemplate.html databarView.html type/edition/compact_title.html
#: type/user/view.html
msgid "Edit"
msgstr ""

Expand Down Expand Up @@ -706,7 +706,11 @@ msgid "Name"
msgstr ""

#: subjects.html
msgid "Edit Subject Tag"
msgid "Tag"
msgstr ""

#: subjects.html
msgid "Link this subject to a tag"
msgstr ""

#: subjects.html
Expand Down Expand Up @@ -787,6 +791,7 @@ msgstr ""
#: 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
#: type/tag/collection/edit.html type/tag/subject/edit.html
msgid "Cancel"
msgstr ""

Expand Down Expand Up @@ -1988,6 +1993,7 @@ msgstr ""

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

Expand Down Expand Up @@ -3263,7 +3269,8 @@ 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 tag/add.html type/tag/collection/edit.html
#: type/tag/subject/edit.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 @@ -6257,7 +6264,7 @@ msgstr ""
msgid "Add a tag to Open Library"
msgstr ""

#: tag/add.html
#: tag/add.html type/tag/collection/edit.html type/tag/subject/edit.html
msgid "Add this tag now"
msgstr ""

Expand Down Expand Up @@ -6911,6 +6918,42 @@ msgstr ""
msgid "View subject page for %(name)s."
msgstr ""

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

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

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

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

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

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

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

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

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

#: type/template/edit.html
msgid "Plugin"
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ jQuery(function () {

const tagTypeSelector = document.querySelector('#tag_type')
if (tagTypeSelector) {
import(/* webpackChunkName: "tag-form" */ "./tag-form")
import(/* webpackChunkName: "tag-form" */ './tag-form')
.then(module => module.initTagTypeSelector(tagTypeSelector))
}
});
Expand Down
12 changes: 6 additions & 6 deletions openlibrary/plugins/openlibrary/js/tag-form.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const SUBJECT_TYPES = ["subject", "person", "place", "time"]
const SUBJECT_TYPES = ['subject', 'person', 'place', 'time']

let inputContainer
const inputSetMapping = {}

export function initTagTypeSelector(selector) {
const subTypeInputs = document.querySelectorAll(".sub-type-inputs__input-set")
inputContainer = document.querySelector(".sub-type-inputs")
const subTypeInputs = document.querySelectorAll('.sub-type-inputs__input-set')
inputContainer = document.querySelector('.sub-type-inputs')

subTypeInputs.forEach((input) => {
inputSetMapping[input.dataset.inputType] = input
})
inputContainer.textContent = ""
inputContainer.textContent = ''

if (selector.value) {
if (SUBJECT_TYPES.includes(selector.value)) {
Expand All @@ -20,7 +20,7 @@ export function initTagTypeSelector(selector) {
}
}

selector.addEventListener("change", (event) => {
selector.addEventListener('change', (event) => {
const selectedValue = event.target.value
let selectedType
if (SUBJECT_TYPES.includes(selectedValue)) {
Expand All @@ -37,7 +37,7 @@ export function initTagTypeSelector(selector) {
}

function hideSubTypeInputs() {
inputContainer.textContent = ""
inputContainer.textContent = ''
}

function showSubTypeInputs(inputsToShow) {
Expand Down
8 changes: 6 additions & 2 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def validate_tag(tag):


def validate_subject_tag(tag):
return tag.get('name', '') and tag.get('tag_type', '') in get_subject_tag_types() and tag.get('body')
return (
tag.get('name', '')
and tag.get('tag_type', '') in get_subject_tag_types()
and tag.get('body')
)


def create_tag(tag: dict) -> Tag:
Expand Down Expand Up @@ -123,7 +127,7 @@ def find_match(self, i: web.utils.Storage):
"""
Tries to find an existing tag that matches the data provided by the user.
"""
matches = Tag.find(i.name, tag_type=i.tag_type)
matches = Tag.find(i.name, tag_type=i.tag_type)
return matches[0] if matches else None

def tag_match(self, match: list) -> NoReturn:
Expand Down
7 changes: 4 additions & 3 deletions openlibrary/plugins/worksearch/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ 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]


Expand Down

0 comments on commit 01aaaf0

Please sign in to comment.