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

Subject tag changes #10138

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
33 changes: 13 additions & 20 deletions openlibrary/core/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Models of various OL objects.
"""

import json
import logging
from collections import defaultdict
from dataclasses import dataclass, field
Expand Down Expand Up @@ -1145,42 +1144,36 @@ def get_url_suffix(self):
return self.name or "unnamed"

@classmethod
def find(cls, tag_name, tag_type):
"""Returns a Tag key for a given tag name and tag type."""
q = {'type': '/type/tag', 'name': tag_name, 'tag_type': tag_type}
match = list(web.ctx.site.things(q))
return match[0] if match else None
def find(cls, tag_name, tag_type=None):
"""Returns a Tag key for a given tag name."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Returns a Tag key for a given tag name."""
"""Returns a list of keys for Tags that match the search criteria."""

q = {'type': '/type/tag', 'name': tag_name}
if tag_type:
q['tag_type'] = tag_type
matches = list(web.ctx.site.things(q))
return matches

@classmethod
def create(
cls,
tag_name,
tag_description,
tag_type,
tag_plugins,
tag,
ip='127.0.0.1',
comment='New Tag',
):
"""Creates a new Tag object."""
current_user = web.ctx.site.get_user()
patron = current_user.get_username() if current_user else 'ImportBot'
key = web.ctx.site.new_key('/type/tag')
tag['key'] = key

from openlibrary.accounts import RunAs

with RunAs(patron):
web.ctx.ip = web.ctx.ip or ip
web.ctx.site.save(
{
'key': key,
'name': tag_name,
'tag_description': tag_description,
'tag_type': tag_type,
'tag_plugins': json.loads(tag_plugins or "[]"),
'type': {"key": '/type/tag'},
},
t = web.ctx.site.save(
tag,
comment=comment,
)
return key
return t


@dataclass
Expand Down
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
1 change: 0 additions & 1 deletion openlibrary/plugins/openlibrary/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,3 @@ jQuery(function () {
.then(module => module.initGoBackLinks(backLinks))
}
});

Loading
Loading