Skip to content

Commit

Permalink
is_template property was not the right approach, a new asset type "ST…
Browse files Browse the repository at this point in the history
…ARTER" was created
  • Loading branch information
alesanchezr committed Nov 12, 2024
1 parent 65ac9ce commit dca9376
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion breathecode/registry/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
7 changes: 2 additions & 5 deletions breathecode/registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ def save(self, *args, **kwargs):


PROJECT = "PROJECT"
STARTER = "STARTER"
EXERCISE = "EXERCISE"
LESSON = "LESSON"
QUIZ = "QUIZ"
VIDEO = "VIDEO"
ARTICLE = "ARTICLE"
TYPE = (
(PROJECT, "Project"),
(STARTER, "Starter Template"),
(EXERCISE, "Exercise"),
(QUIZ, "Quiz"),
(LESSON, "Lesson"),
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions breathecode/registry/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}")

Expand All @@ -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:
Expand Down

0 comments on commit dca9376

Please sign in to comment.