forked from breatheco-de/apiv2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request breatheco-de#1498 from tommygonzaleza/asset-context
Asset context
- Loading branch information
Showing
12 changed files
with
495 additions
and
13 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
22 changes: 22 additions & 0 deletions
22
breathecode/registry/management/commands/generate_asset_context.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,22 @@ | ||
import logging | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from ...models import Asset, AssetContext | ||
from ...tasks import async_build_asset_context | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Generate asset context for all assets." | ||
|
||
def handle(self, *args, **options): | ||
assets = Asset.objects.filter(assetcontext__isnull=True) | ||
for asset in assets: | ||
try: | ||
AssetContext.objects.update_or_create(asset=asset, defaults={"status": "PROCESSING"}) | ||
async_build_asset_context.delay(asset.id) | ||
|
||
except Exception as e: | ||
AssetContext.objects.update_or_create(asset=asset, defaults={"status": "ERROR", "status_text": e}) |
43 changes: 43 additions & 0 deletions
43
breathecode/registry/migrations/0048_asset_dependencies_asset_is_template_and_more.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,43 @@ | ||
# Generated by Django 5.1.1 on 2024-11-12 15:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("registry", "0047_asset_preview_in_tutorial_alter_asset_preview"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="asset", | ||
name="dependencies", | ||
field=models.CharField( | ||
blank=True, | ||
default=None, | ||
help_text="Automatically calculated based on the package.json, pipfile or alternatives. String like: python=3.10,node=16.0", | ||
max_length=50, | ||
null=True, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="asset", | ||
name="is_template", | ||
field=models.BooleanField( | ||
db_index=True, | ||
default=False, | ||
help_text="Automatically set by the system, if true, it means that this asset is set as template by another asset", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="asset", | ||
name="template_url", | ||
field=models.URLField( | ||
blank=True, | ||
default=None, | ||
help_text="This template will be used to open the asset (only applied for projects)", | ||
null=True, | ||
), | ||
), | ||
] |
53 changes: 53 additions & 0 deletions
53
...code/registry/migrations/0049_remove_asset_is_template_alter_asset_asset_type_and_more.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,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, | ||
), | ||
), | ||
] |
34 changes: 34 additions & 0 deletions
34
breathecode/registry/migrations/0050_assetcontext_status_assetcontext_status_text.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,34 @@ | ||
# Generated by Django 5.1.2 on 2024-11-13 16:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("registry", "0049_remove_asset_is_template_alter_asset_asset_type_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="assetcontext", | ||
name="status", | ||
field=models.CharField( | ||
choices=[("PENDING", "Pending"), ("PROCESSING", "Processing"), ("DONE", "Done"), ("ERROR", "Error")], | ||
db_index=True, | ||
default="PENDING", | ||
help_text="If pending, it means it hasn't been generated yet, processing means that is being generated at this moment, done means it has been generated", | ||
max_length=20, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="assetcontext", | ||
name="status_text", | ||
field=models.TextField( | ||
blank=True, | ||
default=None, | ||
help_text="Status details, it may be set automatically if enough error information", | ||
null=True, | ||
), | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
breathecode/registry/migrations/0051_alter_assetcontext_status.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,24 @@ | ||
# Generated by Django 5.1.2 on 2024-11-13 22:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("registry", "0050_assetcontext_status_assetcontext_status_text"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="assetcontext", | ||
name="status", | ||
field=models.CharField( | ||
choices=[("PENDING", "PENDING"), ("PROCESSING", "PROCESSING"), ("DONE", "DONE"), ("ERROR", "ERROR")], | ||
db_index=True, | ||
default="PENDING", | ||
help_text="If pending, it means it hasn't been generated yet, processing means that is being generated at this moment, done means it has been generated", | ||
max_length=20, | ||
), | ||
), | ||
] |
Oops, something went wrong.