-
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: adds Collection.key #223
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6d7797
feat: adds Collection.key
pomegranited 8b17282
refactor: updates collections api to use learning_package_id + key
pomegranited 56b5fb6
chore: bumps version to 0.11.4
pomegranited 8b75af1
fix: ensure unique key in data migration
pomegranited bdcb52b
fix: add lp.id to Collection repr/str
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 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.3" | ||
__version__ = "0.11.4" |
This file contains 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
57 changes: 57 additions & 0 deletions
57
openedx_learning/apps/authoring/collections/migrations/0004_collection_key.py
This file contains 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,57 @@ | ||
# Generated by Django 4.2.15 on 2024-09-04 23:15 | ||
|
||
from django.db import migrations, models | ||
from django.utils.crypto import get_random_string | ||
|
||
import openedx_learning.lib.fields | ||
|
||
|
||
def generate_keys(apps, schema_editor): | ||
""" | ||
Generates a random strings to initialize the key field where NULL. | ||
""" | ||
length = 50 | ||
Collection = apps.get_model("oel_collections", "Collection") | ||
for collection in Collection.objects.filter(key=None): | ||
# Keep generating keys until we get a unique one | ||
key = get_random_string(length) | ||
while Collection.objects.filter(key=key).exists(): | ||
key = get_random_string(length) | ||
|
||
collection.key = key | ||
collection.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('oel_collections', '0003_collection_entities'), | ||
] | ||
|
||
operations = [ | ||
# 1. Temporarily add this field with null=True, blank=True | ||
migrations.AddField( | ||
model_name='collection', | ||
name='key', | ||
field=openedx_learning.lib.fields.MultiCollationCharField( | ||
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'}, | ||
db_column='_key', max_length=500, null=True, blank=True), | ||
preserve_default=False, | ||
), | ||
# 2. Populate the null keys | ||
migrations.RunPython(generate_keys), | ||
# 3. Add null=False, blank=False to disallow NULL values | ||
migrations.AlterField( | ||
model_name='collection', | ||
name='key', | ||
field=openedx_learning.lib.fields.MultiCollationCharField( | ||
db_collations={'mysql': 'utf8mb4_bin', 'sqlite': 'BINARY'}, | ||
db_column='_key', max_length=500, null=False, blank=False), | ||
preserve_default=False, | ||
), | ||
# 4. Enforce unique constraint | ||
migrations.AddConstraint( | ||
model_name='collection', | ||
constraint=models.UniqueConstraint(fields=('learning_package', 'key'), name='oel_coll_uniq_lp_key'), | ||
), | ||
] |
This file contains 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
Oops, something went wrong.
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.
Sorry for not catching this before. 😞
I think we should be able to update the key here.
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.
Hmm.. if we allow that, it'll change the Collection's opaque key, which will disconnect it from any applied tags.. so I think it should be immutable.
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.
You're right! My bad!