Skip to content

Commit

Permalink
feat(topic source api): new api endpoint for posting a list of topic …
Browse files Browse the repository at this point in the history
…links
  • Loading branch information
yonadavGit committed Feb 12, 2024
1 parent 6ab31b9 commit 25cc159
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions reader/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,27 @@ def reorder_topics(request):
results.append(topic.contents())
return jsonResponse({"topics": results})

@staff_member_required()
def topic_ref_bulk_api(request):
data = json.loads(request.body)
all_links_touched = []
for data_item in data:
tref = data_item.get('ref', data_item.get("tref"))
tref = Ref(tref).normal()
slug = data_item.get("toTopic", data_item.get("topic"))
linkType = _CAT_REF_LINK_TYPE_FILTER_MAP['authors'][0] if AuthorTopic.init(slug) else 'about'
descriptions = data_item.get("descriptions", data_item.get("description"))
languages = descriptions.keys()
ref_topic_aggregated_dict = {}
for language in languages:
ref_topic_dict = edit_topic_source(slug, orig_tref=tref, new_tref=tref,
linkType=linkType, description=descriptions[language], interface_lang=language)
ref_topic_aggregated_dict = {**ref_topic_aggregated_dict, **ref_topic_dict}
all_links_touched.append(ref_topic_aggregated_dict)
return jsonResponse(all_links_touched)



@staff_member_required
def topic_ref_api(request, tref):
"""
Expand Down
1 change: 1 addition & 0 deletions sefaria/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
urlpatterns += [
url(r'^api/topics$', reader_views.topics_list_api),
url(r'^api/topics-graph/(?P<topic>.+)$', reader_views.topic_graph_api),
url(r'^api/ref-topic-links/bulk$', reader_views.topic_ref_bulk_api),
url(r'^api/ref-topic-links/(?P<tref>.+)$', reader_views.topic_ref_api),
url(r'^api/v2/topics/(?P<topic>.+)$', reader_views.topics_api, {'v2': True}),
url(r'^api/topics/(?P<topic>.+)$', reader_views.topics_api),
Expand Down

0 comments on commit 25cc159

Please sign in to comment.