-
-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/sc 28125/backend for sheets with ref #1940
Feature/sc 28125/backend for sheets with ref #1940
Conversation
…ria-Project into modularization-main
…ts to return collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tabs throughout this PR seem way too big
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure github is formatting it strangely. The tabs don't look weird on my screen
sefaria/sheets.py
Outdated
@@ -874,6 +889,9 @@ def get_sheets_for_ref(tref, uid=None, in_collection=None): | |||
"category": "Sheets", # ditto | |||
"type": "sheet", # ditto | |||
} | |||
if include_collections: | |||
sheet_data["collections"] = sheet_id_to_collection[sheet["id"]] | |||
sheet_data["dateCreated"] = sheet["dateCreated"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is dateCreated part of this if statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure where to put it. It's supposed to show up next to the user profile in SearchSheetResult now. It's not necessary for the related API to have access to dateCreated, so I didn't add dateCreated to the big "sheet_data = {...}" but it is necessary for the sheets ref API to have access to dateCreated. But it is definitely confusing to set dateCreated only when include_collections is True, so maybe dateCreated should just be set in the original "sheet_data = {...}". What do you think?
sourcesheets/views.py
Outdated
@@ -1020,7 +1020,7 @@ def sheets_by_ref_api(request, ref): | |||
""" | |||
API to get public sheets by ref. | |||
""" | |||
return jsonResponse(get_sheets_for_ref(ref)) | |||
return jsonResponse(get_sheets_for_ref(ref, include_collections=True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this API should take a URL parameter that indicates whether it should include collections. For boolean parameters, our standard is to use 0 to mean false and 1 to mean true. Here's an example bool(int(request.GET.get("annotate", 0)))
For /api/sheets/ref, passed parameter include_collections to
get_sheets_for_ref
, which in turn callsget_collections_with_sheets
. This function returns every public collection that has a sheet insheet_ids
so thatget_sheets_for_ref
returns sheets with a collections field. Instead of including the whole collection, I include the name and slug only. I also added a 'dateCreated' field since on the front end, in the "Sheets With" page, each sheet entry displays a date.