-
Notifications
You must be signed in to change notification settings - Fork 26
fix: improve collections models and api [FC-0059] #208
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
Merged
pomegranited
merged 7 commits into
openedx:main
from
open-craft:rpenido/fal-3782-fix-collection-model-issues
Aug 21, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef09229
fix: improve collections models and api
rpenido fa03042
feat: export models
rpenido 9417609
fix: index field
rpenido a30e04a
fix: add created_by parameter
rpenido 87defd8
fix: assign to created_by_id instead of created_by
pomegranited a4540ec
test: small changes to improve test coverage for collections
pomegranited 1c3fdec
chore: bumps version to 0.11.1
pomegranited File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| """ | ||
| Open edX Learning ("Learning Core"). | ||
| """ | ||
| __version__ = "0.11.0" | ||
| __version__ = "0.11.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,15 +22,17 @@ | |||||||||||
|
|
||||||||||||
| def create_collection( | ||||||||||||
| learning_package_id: int, | ||||||||||||
| name: str, | ||||||||||||
| title: str, | ||||||||||||
| created_by: int | None, | ||||||||||||
| description: str = "", | ||||||||||||
| ) -> Collection: | ||||||||||||
| """ | ||||||||||||
| Create a new Collection | ||||||||||||
| """ | ||||||||||||
| collection = Collection.objects.create( | ||||||||||||
| learning_package_id=learning_package_id, | ||||||||||||
| name=name, | ||||||||||||
| title=title, | ||||||||||||
| created_by_id=created_by, | ||||||||||||
| description=description, | ||||||||||||
| ) | ||||||||||||
|
Comment on lines
36
to
37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Likewise we need to add the |
||||||||||||
| return collection | ||||||||||||
|
|
@@ -45,26 +47,26 @@ def get_collection(collection_id: int) -> Collection: | |||||||||||
|
|
||||||||||||
| def update_collection( | ||||||||||||
| collection_id: int, | ||||||||||||
| name: str | None = None, | ||||||||||||
| title: str | None = None, | ||||||||||||
| description: str | None = None, | ||||||||||||
| ) -> Collection: | ||||||||||||
| """ | ||||||||||||
| Update a Collection | ||||||||||||
| """ | ||||||||||||
| lp = Collection.objects.get(id=collection_id) | ||||||||||||
| collection = Collection.objects.get(id=collection_id) | ||||||||||||
|
|
||||||||||||
| # If no changes were requested, there's nothing to update, so just return | ||||||||||||
| # the Collection as-is | ||||||||||||
| if all(field is None for field in [name, description]): | ||||||||||||
| return lp | ||||||||||||
| if all(field is None for field in [title, description]): | ||||||||||||
| return collection | ||||||||||||
|
|
||||||||||||
| if name is not None: | ||||||||||||
| lp.name = name | ||||||||||||
| if title is not None: | ||||||||||||
| collection.title = title | ||||||||||||
| if description is not None: | ||||||||||||
| lp.description = description | ||||||||||||
| collection.description = description | ||||||||||||
|
|
||||||||||||
| lp.save() | ||||||||||||
| return lp | ||||||||||||
| collection.save() | ||||||||||||
| return collection | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def get_learning_package_collections(learning_package_id: int) -> QuerySet[Collection]: | ||||||||||||
|
|
@@ -73,8 +75,6 @@ def get_learning_package_collections(learning_package_id: int) -> QuerySet[Colle | |||||||||||
|
|
||||||||||||
| Only enabled collections are returned | ||||||||||||
| """ | ||||||||||||
| return ( | ||||||||||||
| Collection.objects | ||||||||||||
| .filter(learning_package_id=learning_package_id, enabled=True) | ||||||||||||
| .select_related("learning_package") | ||||||||||||
| ) | ||||||||||||
| return Collection.objects \ | ||||||||||||
| .filter(learning_package_id=learning_package_id, enabled=True) \ | ||||||||||||
| .select_related("learning_package") | ||||||||||||
53 changes: 53 additions & 0 deletions
53
...ring/collections/migrations/0002_remove_collection_name_collection_created_by_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Generated by Django 4.2.14 on 2024-08-14 14:20 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.conf import settings | ||
| from django.db import migrations, models | ||
|
|
||
| import openedx_learning.lib.fields | ||
| import openedx_learning.lib.validators | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
| ('oel_collections', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveField( | ||
| model_name='collection', | ||
| name='name', | ||
| ), | ||
| migrations.AddField( | ||
| model_name='collection', | ||
| name='created_by', | ||
| field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='collection', | ||
| name='title', | ||
| field=openedx_learning.lib.fields.MultiCollationCharField(db_collations={'mysql': 'utf8mb4_unicode_ci', 'sqlite': 'NOCASE'}, default='Collection', help_text='The title of the collection.', max_length=500), | ||
| preserve_default=False, | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='collection', | ||
| name='created', | ||
| field=models.DateTimeField(auto_now_add=True, validators=[openedx_learning.lib.validators.validate_utc_datetime]), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='collection', | ||
| name='description', | ||
| field=openedx_learning.lib.fields.MultiCollationTextField(blank=True, db_collations={'mysql': 'utf8mb4_unicode_ci', 'sqlite': 'NOCASE'}, default='', help_text='Provides extra information for the user about this collection.', max_length=10000), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name='collection', | ||
| name='modified', | ||
| field=models.DateTimeField(auto_now=True, validators=[openedx_learning.lib.validators.validate_utc_datetime]), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='collection', | ||
| index=models.Index(fields=['learning_package', 'title'], name='oel_collect_learnin_dfaf89_idx'), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 realized the
created_byvalue was missing from the params and in the.createbelow, would you mind adding them in this PR since I needed it when I was working on the REST endpoints.Uh oh!
There was an error while loading. Please reload this page.
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.
Good catch @yusuf-musleh!
Fixed here: a30e04a