Skip to content

Commit

Permalink
Merge pull request #9862 from scottbarnes/9487/feature/batch-import-a…
Browse files Browse the repository at this point in the history
…dd-text-area-for-raw-JSON

Feature: Add a text area for raw JSON copy/paste on /import/batch/new
  • Loading branch information
mekarpeles authored Sep 12, 2024
2 parents d5a4d0f + d5ba8da commit 35cc48d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
12 changes: 11 additions & 1 deletion openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ msgid "Batch Imports"
msgstr ""

#: batch_import.html
msgid "Attach a JSONL formatted document with import records."
msgid ""
"Attach a JSONL formatted document with import records or copy/paste the "
"JSONL text into the textarea."
msgstr ""

#: batch_import.html
Expand All @@ -121,6 +123,14 @@ msgid ""
"more."
msgstr ""

#: batch_import.html
msgid "Attach a file:"
msgstr ""

#: batch_import.html
msgid "Or copy/paste JSONL text:"
msgstr ""

#: batch_import.html
msgid "Import"
msgstr ""
Expand Down
13 changes: 11 additions & 2 deletions openlibrary/plugins/openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,17 @@ def POST(self):
raise Forbidden('Permission Denied.')

# Get the upload from web.py. See the template for the <form> used.
form_data = web.input(batchImport={})
batch_result = batch_import(form_data['batchImport'].file.read())
batch_result = None
form_data = web.input()
if form_data.get("batchImportFile"):
batch_result = batch_import(form_data['batchImportFile'])
elif form_data.get("batchImportText"):
batch_result = batch_import(form_data['batchImportText'].encode("utf-8"))
else:
add_flash_message(
'error',
'Either attach a JSONL file or copy/paste JSONL into the text area.',
)

return render_template("batch_import.html", batch_result=batch_result)

Expand Down
8 changes: 6 additions & 2 deletions openlibrary/templates/batch_import.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<h1>$_("Batch Imports")</h1>
</div>
<div id="contentBody" class="batchImport">
<p>$_('Attach a JSONL formatted document with import records.')</p>
<p>$_('Attach a JSONL formatted document with import records or copy/paste the JSONL text into the textarea.')</p>
<p>$:_('See the <a href=\"https://github.com/internetarchive/openlibrary-client/tree/master/olclient/schemata\">olclient import schemata</a> for more.')</p>
<form method="POST" enctype="multipart/form-data" action="">
<input type="file" name="batchImport" required>
<p>$_('Attach a file:')</p>
<input type="file" name="batchImportFile">
<hr/>
<p>$_('Or copy/paste JSONL text:')</p>
<textarea name="batchImportText" rows="10" cols="70"></textarea>
<hr/>
<button type="submit">$_('Import')</button>
</form>
Expand Down

0 comments on commit 35cc48d

Please sign in to comment.