Safer author add logic
This commit is contained in:
parent
28db3e2733
commit
b42c761b0b
|
@ -74,7 +74,9 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
|
<button class="button is-primary" type="submit">{% trans "Confirm" %}</button>
|
||||||
<button class="button" type="button">{% trans "Back" %}</button>
|
<a href="#" class="button" data-back>
|
||||||
|
<span>{% trans "Back" %}</span>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr class="block">
|
<hr class="block">
|
||||||
|
@ -129,7 +131,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<label class="label" for="id_add_author">{% trans "Add Authors:" %}</label>
|
<label class="label" for="id_add_author">{% trans "Add Authors:" %}</label>
|
||||||
<p class="help">Separate multiple author names with commas.</p>
|
<p class="help">Separate multiple author names with commas.</p>
|
||||||
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'John Doe, Jane Smith' %}" value="{{ add_author }}">
|
<input class="input" type="text" name="add_author" id="id_add_author" placeholder="{% trans 'John Doe, Jane Smith' %}" value="{{ add_author }}" {% if confirm_mode %}readonly{% endif %}>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,8 @@ class EditBook(View):
|
||||||
data["add_author"] = add_author
|
data["add_author"] = add_author
|
||||||
data["author_matches"] = []
|
data["author_matches"] = []
|
||||||
for author in add_author.split(","):
|
for author in add_author.split(","):
|
||||||
|
if not author:
|
||||||
|
continue
|
||||||
# check for existing authors
|
# check for existing authors
|
||||||
vector = SearchVector("name", weight="A") + SearchVector(
|
vector = SearchVector("name", weight="A") + SearchVector(
|
||||||
"aliases", weight="B"
|
"aliases", weight="B"
|
||||||
|
@ -200,6 +202,8 @@ class ConfirmEditBook(View):
|
||||||
# get or create author as needed
|
# get or create author as needed
|
||||||
if request.POST.get("add_author"):
|
if request.POST.get("add_author"):
|
||||||
for (i, author) in enumerate(request.POST.get("add_author").split(",")):
|
for (i, author) in enumerate(request.POST.get("add_author").split(",")):
|
||||||
|
if not author:
|
||||||
|
continue
|
||||||
match = request.POST.get("author_match-%d" % i)
|
match = request.POST.get("author_match-%d" % i)
|
||||||
if match and match != "0":
|
if match and match != "0":
|
||||||
author = get_object_or_404(
|
author = get_object_or_404(
|
||||||
|
|
Loading…
Reference in New Issue