-
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.
Change readable_id values for podcasts and episodes (#1232)
- Loading branch information
Showing
9 changed files
with
261 additions
and
54 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
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
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
63 changes: 63 additions & 0 deletions
63
learning_resources/management/commands/transfer_list_resources.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,63 @@ | ||
"""Management command for migrating unpublished resource path/list relationships""" | ||
|
||
from django.core.management import BaseCommand | ||
|
||
from learning_resources.utils import transfer_list_resources | ||
from main.utils import now_in_utc | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Migrate relationships in learningpaths and userlists from unpublished | ||
resources to published replacement resources. | ||
""" | ||
|
||
help = "Migrate relationships from unpublished resources to published resources." | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("resource_type", type=str, help="Resource type to migrate") | ||
parser.add_argument( | ||
"match_field", type=str, help="Resource field to match resources by" | ||
) | ||
parser.add_argument( | ||
"from_source", type=str, help="ETL Source for unpublished resources" | ||
) | ||
parser.add_argument( | ||
"to_source", type=str, help="ETL Source for published resources" | ||
) | ||
parser.add_argument( | ||
"--delete", | ||
dest="delete", | ||
action="store_true", | ||
help="Delete unpublished resources after migrating relationships", | ||
) | ||
super().add_arguments(parser) | ||
|
||
def handle(self, *args, **options): # noqa: ARG002 | ||
""" | ||
Migrate relationships in learningpaths and userlists from unpublished | ||
resources to published replacement resources. | ||
""" | ||
resource_type = options["resource_type"] | ||
match_field = options["match_field"] | ||
from_source = options["from_source"] | ||
to_source = options["to_source"] | ||
delete = options["delete"] | ||
|
||
self.stdout.write( | ||
f"Migrate {resource_type} relationships from " | ||
f"{from_source} to {to_source}, matching on {match_field}" | ||
) | ||
start = now_in_utc() | ||
unpublished, matching = transfer_list_resources( | ||
resource_type, | ||
match_field, | ||
from_source, | ||
to_source, | ||
delete_unpublished=delete, | ||
) | ||
total_seconds = (now_in_utc() - start).total_seconds() | ||
self.stdout.write( | ||
f"Processed {unpublished} resources and found {matching} " | ||
f"published matches, took {total_seconds} seconds" | ||
) |
17 changes: 17 additions & 0 deletions
17
learning_resources/migrations/0056_alter_learningresource_readable_id.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,17 @@ | ||
# Generated by Django 4.2.13 on 2024-07-08 16:30 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("learning_resources", "0055_alter_relationship_options_ordering"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="learningresource", | ||
name="readable_id", | ||
field=models.CharField(max_length=512), | ||
), | ||
] |
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
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.