-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: add Collection model and api #206
feat: add Collection model and api #206
Conversation
Thanks for the pull request, @rpenido! What's next?Please work through the following steps to get your changes ready for engineering review: 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Let us know that your PR is ready for review:Who will review my changes?This repository is currently maintained by Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
329c77f
to
0acacf2
Compare
0acacf2
to
bd78879
Compare
@rpenido This is looking good to me so far, great work! |
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.
Looks great @rpenido !
One little nit and could you please bump the minor version for this package?
👍
- I tested this by running the tests and checking for full coverage of the API and tests.
- I read through the code
-
I checked for accessibility issuesN/A - Includes documentation
- User-facing strings are extracted for translation
Co-authored-by: Jillian <[email protected]>
Done! 370e73a |
8c56b26
to
ec9365c
Compare
ec9365c
to
d6cdf08
Compare
Hi @pomegranited! I added a |
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.
👍 Thanks @rpenido ! I forgot to ask you to add collections.api
to api.authoring
, so did that here: ba04b4b.
Will merge this today, thank you!
- I tested this by checking the test coverage
- I read through the code
-
I checked for accessibility issuesN/A - Includes documentation -- readme, field help, and docstrings
- User-facing strings are extracted for translation
@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
@pomegranited, @rpenido: This is my fault for not watching the PRs flowing here more closely, but could you please tag me on PRs that make new models or significant changes to old ones in the I'll add comments about some of the specifics to this PR, even though I realize it's already merged. To be clear: I'm not asking for a revert–just followup at a later point in time. |
My apologies @ormsbee ! I thought you had approved the discovery so we were ok to proceed here. |
Yeah, that was totally my fault for not communicating clearly. I did approve the discovery doc, but with this comment:
Thank you! |
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.
Sorry I didn't get this feedback to you folks sooner. Thank you!
"The name of the collection." | ||
), | ||
) | ||
description = case_insensitive_char_field( |
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.
If we're intending this to be long, it should be a text field, not a char field. There's no helper for this in fields.py
right now–see the example for LearningPackage's description field.
Also, MySQL indexing limits means that even if you specify 10K as the max length here, only the first 767 characters will be guaranteed to be indexable as a varchar. We can just turn this off altogether and not make the name searchable at the database layer (relying on dedicated search later).
# Each collection belongs to a learning package | ||
learning_package = models.ForeignKey(LearningPackage, on_delete=models.CASCADE) | ||
|
||
name = case_insensitive_char_field( |
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.
Please use title
here instead of name
for consistency with LearningPackage and PublishableEntityVersion.
name = case_insensitive_char_field( | ||
null=False, | ||
max_length=255, | ||
db_index=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.
Please put all indexes in the indexes
attribute of this model's Meta
, even the ones for individual columns.
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.
Also, while it's fine to have a global index on the Collection titles, the most common sorting case is going to be to order by name, scoped to a particular LearningPackage. So you'll want to make a compound index on the combination of (learning_package_id, title)
.
|
||
name = case_insensitive_char_field( | ||
null=False, | ||
max_length=255, |
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.
Again for consistency, please use the same numbers as LearningPackage for now (500).
The historical reason for 255 was because that was the largest indexable value when using utf8mb3
encoding and the older InnoDB backend. We're now running utf8mb4
and newer InnoDB tables.
), | ||
) | ||
created = models.DateTimeField(auto_now_add=True) | ||
modified = models.DateTimeField(auto_now=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.
Most of Learning Core uses manually set datetimes (no auto), but I think it's okay to use here because Collections are created differently (e.g. you're not going to have Publish operation that creates a Collections in bulk).
But please do add the validate_utc_datetime
validator.
"Whether the collection is enabled or not." | ||
), | ||
) | ||
created = models.DateTimeField(auto_now_add=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.
In addition to when it was created, we need to track who it was created by (which should be nullable in case the system created it or the user is deleted). We have created_by
fields in some other models as well.
""" | ||
Update a Collection | ||
""" | ||
lp = Collection.objects.get(id=collection_id) |
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 this variable lp
? LearningPackage?
.filter(learning_package_id=learning_package_id, enabled=True) | ||
.select_related("learning_package") |
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.
Nit: I'm a little surprised the linter didn't error on this, since I thought it was pretty fussy about indentation, e.g.
Collection.objects \
.filter(learning_package_id=learning_package_id, enabled=True) \
.select_related("learning_package")
Description
This PR adds the
Collection
model and some basic APIs to create/get collections.More information
Closes openedx/modular-learning#225
Testing Instructions
Private ref: FAL-3782