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 Sep 10, 2024
1 parent 8f47922 commit 670055b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
19 changes: 15 additions & 4 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,18 @@ msgstr ""
msgid "Name"
msgstr ""

#: subjects.html
msgid "Promote to Tag"
msgstr ""

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

#: subjects.html
msgid "Create Tag from this subject"
msgstr ""

#: subjects.html
msgid "See all works"
msgstr ""
Expand Down Expand Up @@ -7010,12 +7018,15 @@ msgid "Tag Description"
msgstr ""

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

#: type/tag/view.html
#, python-format
msgid "View subject page for %(name)s."
#: type/tag/tag_form_inputs.html
msgid "Subject Key"
msgstr ""

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

#: type/template/edit.html
Expand Down
23 changes: 18 additions & 5 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
def get_tag_types():
return ["subject", "work", "collection"]


def validate_tag(tag, for_promotion=False):
return (tag.get('name', '') and tag.get('fkey', None)) if for_promotion else (tag.get('name', '') and tag.get('tag_type', ''))
return (
(tag.get('name', '') and tag.get('fkey', None))
if for_promotion
else (tag.get('name', '') and tag.get('tag_type', ''))
)


def has_permission(user) -> bool:
"""
Expand All @@ -32,14 +38,17 @@ def has_permission(user) -> bool:
user.is_librarian() or user.is_super_librarian() or user.is_admin()
)

def create_subject_tag(name: str, description: str, fkey: str | None = None, body: str = '') -> Tag:

def create_subject_tag(
name: str, description: str, fkey: str | None = None, body: str = ''
) -> Tag:
tag = Tag.create(name, description, 'subject', fkey=fkey, body=body)
if fkey and not body:
subject = get_subject(
fkey,
details=True,
filters={'public_scan_b': 'false', 'lending_edition_s': '*'},
sort='readinglog'
sort='readinglog',
)
if subject and subject.work_count > 0:
tag.body = str(render_template('subjects', page=subject))
Expand All @@ -54,7 +63,9 @@ def GET(self):
if not (patron := get_current_user()):
raise web.seeother(f'/account/login?redirect={self.path}')
if not has_permission(patron):
raise web.unauthorized(message='Permission denied to promote subject to tags')
raise web.unauthorized(
message='Permission denied to promote subject to tags'
)

i = web.input(name="", fkey=None, description="")

Expand All @@ -78,7 +89,9 @@ def GET(self):

i = web.input(name=None, type=None, sub_type=None, fkey=None)

return render_template('tag/add', i.name, i.type, subject_type=i.sub_type, fkey=i.fkey)
return render_template(
'tag/add', i.name, i.type, subject_type=i.sub_type, fkey=i.fkey
)

def POST(self):
i = web.input(
Expand Down
3 changes: 1 addition & 2 deletions openlibrary/plugins/worksearch/subjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def GET(self, key):
raise web.redirect(nkey)

q = {"type": "/type/tag", "fkey": key, "tag_type": "subject"}
match = web.ctx.site.things(q)
if match:
if match := web.ctx.site.things(q):
tag = web.ctx.site.get(match[0])
raise web.redirect(tag.key)

Expand Down

0 comments on commit 670055b

Please sign in to comment.