Skip to content

Commit 3f76fce

Browse files
Copilotmekarpeles
andcommitted
Address code review feedback: use work.url() and pass bulk explicitly
Co-authored-by: mekarpeles <978325+mekarpeles@users.noreply.github.com>
1 parent cd07257 commit 3f76fce

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

openlibrary/plugins/openlibrary/api.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@ def GET(self):
620620
class work_delete(delegate.page):
621621
path = r"/works/(OL\d+W)/[^/]+/delete"
622622

623-
def get_editions_of_work(self, work: Work) -> list[dict]:
624-
i = web.input(bulk=False)
623+
def get_editions_of_work(self, work: Work, bulk: bool = False) -> list[dict]:
625624
limit = 1_000 # This is the max limit of the things function
626625
all_keys: list = []
627626
offset = 0
@@ -637,7 +636,7 @@ def get_editions_of_work(self, work: Work) -> list[dict]:
637636
)
638637
all_keys.extend(keys)
639638
if len(keys) == limit:
640-
if not i.bulk:
639+
if not bulk:
641640
raise web.HTTPError(
642641
'400 Bad Request',
643642
data=json.dumps(
@@ -668,7 +667,7 @@ def POST(self, work_id: str):
668667
if work is None:
669668
return web.HTTPError(status='404 Not Found')
670669

671-
editions: list[dict] = self.get_editions_of_work(work)
670+
editions: list[dict] = self.get_editions_of_work(work, bulk=bulk)
672671

673672
# Check if super-librarian is required for bulk operations with 1000+ editions
674673
if bulk and len(editions) >= 1_000 and not (user and user.is_super_librarian()):

openlibrary/templates/books/edit.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@
3939
$if ctx.user and (ctx.user.is_admin() or ctx.user.is_super_librarian()):
4040
<span class="adminOnly right">
4141
$if work and work.key:
42-
$ work_id = work.key.split('/')[-1]
43-
$ work_title_slug = work.title.replace(' ', '_') if work.title else 'untitled'
44-
<form method="post" action="/works/$work_id/$work_title_slug/delete?bulk=true" id="delete-work-and-editions" name="delete-work" onsubmit="return confirm('Delete work and all of its editions?')" style="display: inline;">
42+
<form method="post" action="$work.url(suffix='/delete', bulk='true')" id="delete-work-and-editions" name="delete-work" onsubmit="return confirm('Delete work and all of its editions?')" style="display: inline;">
4543
<button type="submit" name="_delete_work" value="true" id="delete-work-btn">$_("Delete work and all editions")</button>
4644
</form>
4745
$if edition:
4846
<form method="post" id="delete-record" name="delete" style="display: inline;">
4947
<button type="submit" name="_delete" value="true" id="delete-btn">$_("Delete edition")</button>
5048
</form>
51-
$elif not edition:
49+
$else:
5250
<form method="post" id="delete-record" name="delete" style="display: inline;">
5351
<button type="submit" name="_delete" value="true" id="delete-btn">$_("Delete Record")</button>
5452
</form>

0 commit comments

Comments
 (0)