-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a trailing slash to non contentfile OCW resources (#1877)
* add a trailing slash to non contentfile OCW resources * refactoring / simplification * add a migration that ensures all OCW courses and runs have a trailing slash on their url
- Loading branch information
Showing
2 changed files
with
28 additions
and
4 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
26 changes: 26 additions & 0 deletions
26
learning_resources/migrations/0079_ocw_pages_trailing_slash.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,26 @@ | ||
# Generated by Django 4.2.16 on 2024-12-06 22:02 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def ensure_trailing_slashes(apps, schema_editor): | ||
LearningResource = apps.get_model("learning_resources", "LearningResource") | ||
|
||
for resource in LearningResource.objects.filter( | ||
resource_type="course", offered_by_id="ocw" | ||
): | ||
resource.url = f"{resource.url.rstrip('/')}/" | ||
resource.save() | ||
for run in resource.runs.all(): | ||
run.url = f"{run.url.rstrip('/')}/" | ||
run.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("learning_resources", "0078_alter_contentfile_content_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(ensure_trailing_slashes, migrations.RunPython.noop), | ||
] |