Repository: internetarchive/openlibrary

Issue:
ILE Bulk add Subject Tags
* Using auto-complete from #6888
* Slide-up menu to see + managed actively selected ILE records

e.g. https://www.figma.com/file/dYQkIJOJeMo9hx7ewZQH9x/Open-Library%3A-Design-System-%26-Component-Library?node-id=607%3A662&t=uMqWRoMcKGnKePf2-0

<img width="383" alt="Screenshot 2023-03-14 at 7 35 26 PM" src="https://user-images.githubusercontent.com/978325/225190541-cf46b39b-33e8-4bf8-b9cc-31f7c3db3b12.png">





Discussion:
Here's a codepen to help: https://codepen.io/mekarpeles/pen/xxQyqrM

Resolving patch:
diff --git a/openlibrary/plugins/openlibrary/bulk_tag.py b/openlibrary/plugins/openlibrary/bulk_tag.py
new file mode 100644
--- /dev/null
+++ b/openlibrary/plugins/openlibrary/bulk_tag.py
@@ -0,0 +1,65 @@
+from infogami.utils import delegate
+from infogami.utils.view import render_template, public
+from openlibrary.utils import uniq
+import web
+import json
+
+
+class tags_partials(delegate.page):
+    path = "/tags/partials"
+    encoding = "json"
+
+    def GET(self):
+        i = web.input(key=None)
+
+        works = i.work_ids
+
+        tagging_menu = render_template('subjects/tagging_menu', works)
+
+        partials = {
+            'tagging_menu': str(tagging_menu),
+        }
+
+        return delegate.RawText(json.dumps(partials))
+
+
+class bulk_tag_works(delegate.page):
+    path = "/tags/bulk_tag_works"
+
+    def POST(self):
+        i = web.input(work_ids='', tag_subjects='[]')
+        works = i.work_ids.split(',')
+        incoming_subjects = json.loads(i.tag_subjects)
+        docs_to_update = []
+
+        for work in works:
+            w = web.ctx.site.get(f"/works/{work}")
+            current_subjects = {
+                'subjects': uniq(w.get('subjects', '')),
+                'subject_people': uniq(w.get('subject_people', '')),
+                'subject_places': uniq(w.get('subject_places', '')),
+                'subject_times': uniq(w.get('subject_times', '')),
+            }
+            for subject_type, subject_list in incoming_subjects.items():
+                if subject_list:
+                    current_subjects[subject_type] = uniq(  # dedupe incoming subjects
+                        current_subjects[subject_type] + subject_list
+                    )
+                    w[subject_type] = current_subjects[subject_type]
+
+            docs_to_update.append(
+                w.dict()
+            )  # need to convert class to raw dict in order for save_many to work
+
+        web.ctx.site.save_many(docs_to_update, comment="Bulk tagging works")
+
+        def response(msg, status="success"):
+            return delegate.RawText(
+                json.dumps({status: msg}), content_type="application/json"
+            )
+
+        return response('Tagged works successfully')
+
+
+def setup():
+    pass
diff --git a/openlibrary/plugins/openlibrary/code.py b/openlibrary/plugins/openlibrary/code.py
--- a/openlibrary/plugins/openlibrary/code.py
+++ b/openlibrary/plugins/openlibrary/code.py
@@ -75,9 +75,10 @@
     h for h in infogami._install_hooks if h.__name__ != 'movefiles'
 ]
 
-from openlibrary.plugins.openlibrary import lists
+from openlibrary.plugins.openlibrary import lists, bulk_tag
 
 lists.setup()
+bulk_tag.setup()
 
 logger = logging.getLogger('openlibrary')
 


Test patch: