-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adds Collection.key which uniquely identifies a Collection within a Learning Package. Existing Collection keys are initialized with a random string. * refactor: updates collections api to use learning_package_id + key to identify Collections. We do this because the `key` will be used in the Collection's opaque key (not the ID). * chore: bumps version to 0.11.4
- Loading branch information
1 parent
9cf134d
commit 6fa83ba
Showing
5 changed files
with
159 additions
and
35 deletions.
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.