Skip to content

Commit

Permalink
added learnpack_deply_url to the asset
Browse files Browse the repository at this point in the history
  • Loading branch information
alesanchezr committed Sep 25, 2024
1 parent a243a44 commit 1399bb5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
38 changes: 30 additions & 8 deletions breathecode/provisioning/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

import pandas as pd
from capyc.rest_framework.exceptions import ValidationException
from circuitbreaker import CircuitBreakerError
from dateutil.relativedelta import relativedelta
from django.http import HttpResponse
Expand Down Expand Up @@ -35,7 +36,6 @@
from breathecode.utils.i18n import translation
from breathecode.utils.io.file import count_csv_rows
from breathecode.utils.views import private_view, render_message
from capyc.rest_framework.exceptions import ValidationException

from .actions import get_provisioning_vendor
from .models import BILL_STATUS, ProvisioningBill, ProvisioningUserConsumption
Expand Down Expand Up @@ -99,28 +99,50 @@ def redirect_new_container(request, token):

def redirect_new_container_public(request):

from breathecode.registry.models import Asset

# user = token.user

lang = request.GET.get("lang", None)
repo = request.GET.get("repo", None)
if repo is None:
return render_message(request, "Please specify a repository in the URL")

urls = {"gitpod": "https://gitpod.io/#", "codespaces": "https://github.com/codespaces/new/?repo="}
get_urls = {"codespaces": lambda x: x.replace("https://github.com/", "")}
url_modifiers = {"codespaces": lambda x: x.replace("https://github.com/", "")}
vendors = request.GET.get("vendor", "codespaces,gitpod").split(",")
buttons = []
for v in vendors:
if v not in urls:
return render_message(request, f"Invalid provisioning vendor: {v}")

asset = Asset.objects.filter(readme_url__icontains=repo)
if lang is not None:
asset = asset.filter(lang=lang)
asset = asset.first()
if asset and asset.learnpack_deploy_url:
buttons.append(
{
"label": f"Open in {v.capitalize()}",
"url": (get_urls[v](urls[v]) if v in get_urls else urls[v] + repo),
"icon": f"/static/img/{v}.svg",
"label": "Start tutorial",
"url": asset.learnpack_deploy_url,
"icon": "/static/img/learnpack.svg",
}
)

else:
for v in vendors:
if v not in urls:
return render_message(request, f"Invalid provisioning vendor: {v}")

_url = urls[v] + repo
if v in url_modifiers:
_url = urls[v] + url_modifiers[v](repo)

buttons.append(
{
"label": f"Open in {v.capitalize()}",
"url": _url,
"icon": f"/static/img/{v}.svg",
}
)

data = {
# 'title': item.academy.name,
"buttons": buttons,
Expand Down
23 changes: 23 additions & 0 deletions breathecode/registry/migrations/0044_asset_learnpack_deploy_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.1 on 2024-09-25 15:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("registry", "0043_asset_superseded_by"),
]

operations = [
migrations.AddField(
model_name="asset",
name="learnpack_deploy_url",
field=models.URLField(
blank=True,
default=None,
help_text="Only applies to LearnPack tutorials that have been published in the LearnPack cloud",
null=True,
),
),
]
7 changes: 7 additions & 0 deletions breathecode/registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ def __init__(self, *args, **kwargs):
help_text="Brief for the copywriters, mainly used to describe what this lessons needs to be about",
)

learnpack_deploy_url = models.URLField(
null=True,
blank=True,
default=None,
help_text="Only applies to LearnPack tutorials that have been published in the LearnPack cloud",
)

readme_url = models.URLField(
null=True,
blank=True,
Expand Down
6 changes: 6 additions & 0 deletions breathecode/static/img/learnpack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1399bb5

Please sign in to comment.