Skip to content
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

Merged

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Aug 5, 2024

Description

This PR adds the Collection model and some basic APIs to create/get collections.

More information

Closes openedx/modular-learning#225

Testing Instructions

  • Please ensure that the tests cover the expected behavior

Private ref: FAL-3782

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Aug 5, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Aug 5, 2024

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If 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 @axim-engineering. Tag them in a comment and let them know that your changes are ready for review.

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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@rpenido rpenido force-pushed the rpenido/fal-3782-collections-model branch 3 times, most recently from 329c77f to 0acacf2 Compare August 5, 2024 20:55
@rpenido rpenido force-pushed the rpenido/fal-3782-collections-model branch from 0acacf2 to bd78879 Compare August 5, 2024 21:00
@yusuf-musleh
Copy link
Member

@rpenido This is looking good to me so far, great work!

@rpenido rpenido marked this pull request as ready for review August 6, 2024 19:44
@rpenido rpenido requested a review from pomegranited August 6, 2024 19:44
Copy link
Contributor

@pomegranited pomegranited left a 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 issues N/A
  • Includes documentation
  • User-facing strings are extracted for translation

openedx_learning/apps/authoring/collections/readme.rst Outdated Show resolved Hide resolved
@rpenido
Copy link
Contributor Author

rpenido commented Aug 7, 2024

One little nit and could you please bump the minor version for this package?

Done! 370e73a

@rpenido rpenido force-pushed the rpenido/fal-3782-collections-model branch from 8c56b26 to ec9365c Compare August 8, 2024 12:26
@rpenido rpenido force-pushed the rpenido/fal-3782-collections-model branch from ec9365c to d6cdf08 Compare August 8, 2024 12:28
@rpenido
Copy link
Contributor Author

rpenido commented Aug 8, 2024

Hi @pomegranited! I added a update_collection function and more tests here: d6cdf08

@rpenido rpenido requested a review from pomegranited August 8, 2024 12:35
Copy link
Contributor

@pomegranited pomegranited left a 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 issues N/A
  • Includes documentation -- readme, field help, and docstrings
  • User-facing strings are extracted for translation

@pomegranited pomegranited merged commit ddb78bb into openedx:main Aug 8, 2024
9 checks passed
@openedx-webhooks
Copy link

@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 pomegranited deleted the rpenido/fal-3782-collections-model branch August 8, 2024 16:37
@ormsbee
Copy link
Contributor

ormsbee commented Aug 8, 2024

@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 openedx_learning package? I've had my head wrapped around that area for a while, and I haven't properly documented up all the considerations like I should.

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.

@pomegranited
Copy link
Contributor

My apologies @ormsbee ! I thought you had approved the discovery so we were ok to proceed here.
Will tag you before merging in future, and please let me know if we need to change anything here.

@ormsbee
Copy link
Contributor

ormsbee commented Aug 8, 2024

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:

I'm good with the general approach. There are some low level details that we can work out in the PRs–e.g. keeping field naming in line with existing openedx-learning conventions, or understanding exactly what some fields mean (allow_multiple?).

Will tag you before merging in future, and please let me know if we need to change anything here.

Thank you!

Copy link
Contributor

@ormsbee ormsbee left a 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(
Copy link
Contributor

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(
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor

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,
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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?

Comment on lines +78 to +79
.filter(learning_package_id=learning_package_id, enabled=True)
.select_related("learning_package")
Copy link
Contributor

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")

@rpenido
Copy link
Contributor Author

rpenido commented Aug 9, 2024

Sorry I didn't get this feedback to you folks sooner. Thank you!

No worries, and thank you for your review @ormsbee! I addressed the issues in #208.

Could you check and see if you find more room for improvements there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Libraries] [Collections] [Backend] Collections model in Learning Core
6 participants