Skip to content

Commit

Permalink
support comma separated author merge url (#10114)
Browse files Browse the repository at this point in the history
* support comma separated author merge url

* add support in community edit queue

* add support in selection toolbar

* add support for work search faceets

* add support for author search page

* Strip trailing commas from author merge endpoint
  • Loading branch information
RayBB authored Dec 5, 2024
1 parent fc975df commit 89d69ed
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,6 @@ SelectionManager.ACTIONS = [
requires_type: ['author'],
multiple_only: true,
name: 'Merge Authors...',
href: olids => `/authors/merge?${olids.map(olid => `key=${olid}`).join('&')}`,
href: olids => `/authors/merge?records=${olids.join(',')}`,
},
];
2 changes: 1 addition & 1 deletion openlibrary/plugins/upstream/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_url(mr_type: int, olids: list[str], primary: str | None = None) -> st
primary_param = f'&primary={primary}' if primary else ''
return f'/works/merge?records={",".join(olids)}{primary_param}'
elif mr_type == CommunityEditsQueue.TYPE['AUTHOR_MERGE']:
return f'/authors/merge?key={"&key=".join(olids)}'
return f'/authors/merge?records={",".join(olids)}'
return ''

@staticmethod
Expand Down
10 changes: 8 additions & 2 deletions openlibrary/plugins/upstream/merge_authors.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,14 @@ def filter_authors(self, keys):
return [k for k in keys if d.get("/authors/" + k) == '/type/author']

def GET(self):
i = web.input(key=[], mrid=None)
keys = uniq(i.key)
i = web.input(key=[], mrid=None, records='')

# key is deprecated in favor of records but we will support both
if deprecated_keys := uniq(i.key):
redir_url = f'/authors/merge/?records={",".join(deprecated_keys)}'
raise web.redirect(redir_url)

keys = uniq(i.records.strip(',').split(','))

# filter bad keys
keys = self.filter_authors(keys)
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/templates/search/authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ <h1>$_("Search Authors")</h1>
$:render_template("search/sort_options.html", selected_sort=sort, search_scheme="authors")
$ user_can_merge = ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin())
$if results.num_found >= 2 and user_can_merge:
$ keys = '&'.join('key=%s' % doc['key'].split("/")[-1] for doc in results.docs)
<div class="mergeThis">$_('Is the same author listed twice?') <a class="large sansserif" href="/authors/merge?$keys">$_('Merge authors')</a></div>
$ keys = ','.join(doc['key'].split("/")[-1] for doc in results.docs)
<div class="mergeThis">$_('Is the same author listed twice?') <a class="large sansserif" href="/authors/merge?records=$keys">$_('Merge authors')</a></div>
</div>
$else:
<center>
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/templates/search/work_search_facets.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<div class="facet $header">
$ magic_wand_markup = ''
$if header == 'author_key' and len(counts) > 1 and ctx.user and ("merge-authors" in ctx.features or ctx.user.is_admin()):
$ keys = '&'.join('key=%s' % k for k, display, count in counts)
$ magic_wand_markup = ' <span class="merge"><a href="/authors/merge?%s" title="%s">%s</a></span>' % (keys, _('Merge duplicate authors from this search'), _("Merge duplicates"))
$ keys = ','.join(k for k, display, count in counts)
$ magic_wand_markup = ' <span class="merge"><a href="/authors/merge?records=%s" title="%s">%s</a></span>' % (keys, _('Merge duplicate authors from this search'), _("Merge duplicates"))
<h4 class="facetHead">$(label)$:(magic_wand_markup)</h4>
$ num = 0
$for k, display, count in counts:
Expand Down

0 comments on commit 89d69ed

Please sign in to comment.