feat: add import template download link
This commit is contained in:
+23
-1
@@ -19,7 +19,7 @@ from apps.billing.services import (
|
||||
from apps.users.models import ApiKey
|
||||
|
||||
from .forms import ApiKeyCreateForm, RechargeCreateForm
|
||||
from .models import DownloadRelease
|
||||
from .models import DownloadRelease, ImportTemplate
|
||||
|
||||
|
||||
NEW_API_KEY_SESSION_KEY = "portal_new_api_key"
|
||||
@@ -98,6 +98,14 @@ def paginate_records(request, queryset):
|
||||
}
|
||||
|
||||
|
||||
def build_public_download_url(request, url: str) -> str:
|
||||
if not url:
|
||||
return ""
|
||||
if url.startswith("/"):
|
||||
return request.build_absolute_uri(url)
|
||||
return url
|
||||
|
||||
|
||||
class HomeView(TemplateView):
|
||||
template_name = "portal/home.html"
|
||||
|
||||
@@ -111,6 +119,20 @@ class HomeView(TemplateView):
|
||||
.order_by("-created_at", "-id")
|
||||
.first()
|
||||
)
|
||||
current_import_template = (
|
||||
ImportTemplate.objects.filter(is_current=True)
|
||||
.order_by("-created_at", "-id")
|
||||
.first()
|
||||
)
|
||||
context["current_import_template"] = current_import_template
|
||||
context["current_import_template_download_url"] = (
|
||||
build_public_download_url(
|
||||
self.request,
|
||||
current_import_template.download_url
|
||||
if current_import_template is not None
|
||||
else "",
|
||||
)
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user