diff --git a/breathecode/registry/actions.py b/breathecode/registry/actions.py index 6f804236d..080211f41 100644 --- a/breathecode/registry/actions.py +++ b/breathecode/registry/actions.py @@ -902,7 +902,7 @@ def pull_learnpack_asset(github, asset: Asset, override_meta): return asset -def pull_project_dependencies(github, asset): +def pull_repo_dependencies(github, asset): """ Pulls the main programming languages and their versions from a GitHub repository. diff --git a/breathecode/registry/migrations/0049_remove_asset_is_template_alter_asset_asset_type_and_more.py b/breathecode/registry/migrations/0049_remove_asset_is_template_alter_asset_asset_type_and_more.py new file mode 100644 index 000000000..47869900a --- /dev/null +++ b/breathecode/registry/migrations/0049_remove_asset_is_template_alter_asset_asset_type_and_more.py @@ -0,0 +1,53 @@ +# Generated by Django 5.1.1 on 2024-11-12 18:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("registry", "0048_asset_dependencies_asset_is_template_and_more"), + ] + + operations = [ + migrations.RemoveField( + model_name="asset", + name="is_template", + ), + migrations.AlterField( + model_name="asset", + name="asset_type", + field=models.CharField( + choices=[ + ("PROJECT", "Project"), + ("STARTER", "Starter Template"), + ("EXERCISE", "Exercise"), + ("QUIZ", "Quiz"), + ("LESSON", "Lesson"), + ("VIDEO", "Video"), + ("ARTICLE", "Article"), + ], + db_index=True, + max_length=20, + ), + ), + migrations.AlterField( + model_name="asseterrorlog", + name="asset_type", + field=models.CharField( + blank=True, + choices=[ + ("PROJECT", "Project"), + ("STARTER", "Starter Template"), + ("EXERCISE", "Exercise"), + ("QUIZ", "Quiz"), + ("LESSON", "Lesson"), + ("VIDEO", "Video"), + ("ARTICLE", "Article"), + ], + default=None, + max_length=20, + null=True, + ), + ), + ] diff --git a/breathecode/registry/models.py b/breathecode/registry/models.py index 97c820b21..0618188f0 100644 --- a/breathecode/registry/models.py +++ b/breathecode/registry/models.py @@ -227,6 +227,7 @@ def save(self, *args, **kwargs): PROJECT = "PROJECT" +STARTER = "STARTER" EXERCISE = "EXERCISE" LESSON = "LESSON" QUIZ = "QUIZ" @@ -234,6 +235,7 @@ def save(self, *args, **kwargs): ARTICLE = "ARTICLE" TYPE = ( (PROJECT, "Project"), + (STARTER, "Starter Template"), (EXERCISE, "Exercise"), (QUIZ, "Quiz"), (LESSON, "Lesson"), @@ -329,11 +331,6 @@ def __init__(self, *args, **kwargs): help_text="Only applies to LearnPack tutorials that have been published in the LearnPack cloud", ) - is_template = models.BooleanField( - default=False, - help_text="Automatically set by the system, if true, it means that this asset is set as template by another asset", - db_index=True, - ) template_url = models.URLField( null=True, blank=True, diff --git a/breathecode/registry/tasks.py b/breathecode/registry/tasks.py index 6c4506109..54a5770af 100644 --- a/breathecode/registry/tasks.py +++ b/breathecode/registry/tasks.py @@ -33,7 +33,7 @@ clean_asset_readme, generate_screenshot, pull_from_github, - pull_project_dependencies, + pull_repo_dependencies, screenshots_bucket, test_asset, upload_image_to_bucket, @@ -86,7 +86,11 @@ def async_pull_project_dependencies(asset_slug): raise Exception( f"Asset {asset_slug} template {asset.template_url} not found in the database as another asset" ) - target_asset.is_template = True + if target_asset.asset_type != "STARTER": + target_asset.log_error( + "not-a-template", + f"Asset {asset_slug} references {target_asset.slug} as a template but its type != 'STARTER'", + ) target_asset.save() logger.debug(f"Retrieving asset dependencies for {asset_slug}") @@ -101,7 +105,7 @@ def async_pull_project_dependencies(asset_slug): g = Github(credentials.token) - dependency_string = pull_project_dependencies(g, target_asset) + dependency_string = pull_repo_dependencies(g, target_asset) logger.debug(dependency_string) target_asset.dependencies = dependency_string if target_asset.id != asset.id: