Skip to content

Commit

Permalink
Merge pull request #9775 from jimchamp/9685/feature/pre-populate-tag-…
Browse files Browse the repository at this point in the history
…creation-form

Prefill "Add Tag" form
  • Loading branch information
mekarpeles authored Aug 26, 2024
2 parents 35d4258 + b884f7c commit b13950f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 8 additions & 2 deletions openlibrary/plugins/upstream/addtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from openlibrary.accounts import get_current_user
from openlibrary.plugins.upstream import spamcheck, utils
from openlibrary.plugins.upstream.models import Tag
from openlibrary.plugins.upstream.addbook import get_recaptcha, safe_seeother, trim_doc
from openlibrary.plugins.upstream.addbook import safe_seeother, trim_doc
from openlibrary.plugins.upstream.utils import render_template


Expand All @@ -32,7 +32,13 @@ def GET(self):
if not self.has_permission(patron):
raise web.unauthorized(message='Permission denied to add tags')

return render_template('tag/add', recaptcha=get_recaptcha())
i = web.input(name=None, type=None, sub_type=None)

# Validate input:
if not i.name or not i.type:
raise web.badrequest('Tag name and type must be specified')

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

def has_permission(self, user) -> bool:
"""
Expand Down
4 changes: 3 additions & 1 deletion openlibrary/templates/subjects.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<div class="page-heading-search-box">
$if can_add_tag:
<div class="subjectTagEdit">
$ edit_tag_url = page.tag.get('id') + '/edit' if 'tag' in page else '/tag/add'
$ edit_tag_url = page.tag.get('id') + '/edit' if has_tag else '/tag/add'
$if not has_tag:
$ edit_tag_url += '?name=%s&type=subject&sub_type=%s' % (page.name, page.subject_type)
<a
class="editTagButton"
href="$edit_tag_url"
Expand Down
12 changes: 6 additions & 6 deletions openlibrary/templates/tag/add.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$def with (tag=None, name=None, recaptcha=None)
$def with (name, type, subject_type=None)

$var title: $_("Add a tag")

Expand All @@ -20,7 +20,7 @@ <h1>$_("Add a tag to Open Library")</h1>
<label for="tagname">$_("Name of Tag")</label>*<span class="tip">$_("Required field")</span>
</div>
<div class="input">
<input type="text" name="tag_name" id="tag_name" required/>
<input type="text" name="tag_name" id="tag_name" value="$name" required/>
</div>
</div>

Expand All @@ -43,14 +43,14 @@ <h1>$_("Add a tag to Open Library")</h1>
<option value="">$_("Select")</option>
$ tag_types = get_tag_types()
$for tag_type in tag_types:
<option value="$tag_type">$tag_type</option>
$if tag_type == type:
<option value="$tag_type" selected>$tag_type</option>
$else:
<option value="$tag_type">$tag_type</option>
</select>
</div>
</div>

$if recaptcha and not ctx.user:
$:render_template("recaptcha", recaptcha.public_key, error=None)

<div class="formElement bottom">
<br/>
<div class="cclicense">
Expand Down

0 comments on commit b13950f

Please sign in to comment.