feat: pagination for videos and icon separating
This commit is contained in:
+80
-2
@@ -2,6 +2,7 @@ import mimetypes
|
||||
|
||||
from django.http import FileResponse, Http404
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
from django.views.generic import DetailView, ListView, TemplateView
|
||||
|
||||
@@ -9,6 +10,18 @@ from .models import Article, ArticleCitation, ArticleSection, MainProduct, Produ
|
||||
from .release_assets import FILE_FIELD_BY_ASSET_KEY, RELEASE_ASSET_KEYS, URL_FIELD_BY_ASSET_KEY
|
||||
from .release_context import build_archive_context, build_release_context
|
||||
|
||||
VIDEO_PREVIEW_LIMIT = 3
|
||||
VIDEO_ARCHIVE_PAGE_SIZE = 6
|
||||
|
||||
|
||||
def _product_video_preview(queryset, archive_url):
|
||||
total = queryset.count()
|
||||
return {
|
||||
"product_videos": queryset[:VIDEO_PREVIEW_LIMIT],
|
||||
"videos_total_count": total,
|
||||
"videos_archive_url": archive_url if total > VIDEO_PREVIEW_LIMIT else "",
|
||||
}
|
||||
|
||||
|
||||
class ReleaseAssetDownloadView(View):
|
||||
def get(self, request, version_id, asset):
|
||||
@@ -58,7 +71,16 @@ class MainProductDetailView(DetailView):
|
||||
context["articles"] = self.object.articles.prefetch_related(
|
||||
"sections", "citations"
|
||||
).all()
|
||||
context["product_videos"] = self.object.videos.filter(is_active=True).order_by("order")
|
||||
videos = self.object.videos.filter(is_active=True).order_by("order", "pk")
|
||||
context.update(
|
||||
_product_video_preview(
|
||||
videos,
|
||||
reverse(
|
||||
"products:main_product_videos",
|
||||
kwargs={"main_slug": self.object.slug},
|
||||
),
|
||||
)
|
||||
)
|
||||
release_context = build_release_context(
|
||||
self.object.distribution,
|
||||
self.object.versions.filter(is_active=True),
|
||||
@@ -112,7 +134,19 @@ class SubProductDetailView(TemplateView):
|
||||
context["articles"] = sub_product.articles.prefetch_related(
|
||||
"sections", "citations"
|
||||
).all()
|
||||
context["product_videos"] = sub_product.videos.filter(is_active=True).order_by("order")
|
||||
videos = sub_product.videos.filter(is_active=True).order_by("order", "pk")
|
||||
context.update(
|
||||
_product_video_preview(
|
||||
videos,
|
||||
reverse(
|
||||
"products:sub_product_videos",
|
||||
kwargs={
|
||||
"main_slug": main_product.slug,
|
||||
"sub_slug": sub_product.slug,
|
||||
},
|
||||
),
|
||||
)
|
||||
)
|
||||
context["siblings"] = (
|
||||
SubProduct.objects.filter(main_product=main_product, is_active=True)
|
||||
.exclude(pk=sub_product.pk)
|
||||
@@ -127,6 +161,50 @@ class SubProductDetailView(TemplateView):
|
||||
return context
|
||||
|
||||
|
||||
class ProductVideoArchiveView(ListView):
|
||||
model = ProductVideo
|
||||
template_name = "videos/archive.html"
|
||||
context_object_name = "videos"
|
||||
paginate_by = VIDEO_ARCHIVE_PAGE_SIZE
|
||||
|
||||
def get_parent(self):
|
||||
main_product = get_object_or_404(
|
||||
MainProduct,
|
||||
slug=self.kwargs["main_slug"],
|
||||
is_active=True,
|
||||
)
|
||||
sub_slug = self.kwargs.get("sub_slug")
|
||||
if sub_slug:
|
||||
return get_object_or_404(
|
||||
SubProduct,
|
||||
slug=sub_slug,
|
||||
main_product=main_product,
|
||||
is_active=True,
|
||||
)
|
||||
return main_product
|
||||
|
||||
def get_queryset(self):
|
||||
self.parent_object = self.get_parent()
|
||||
return self.parent_object.videos.filter(is_active=True).order_by("order", "pk")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update(
|
||||
{
|
||||
"library_title": f"{self.parent_object.name} videos",
|
||||
"library_description": (
|
||||
"Tutorials, demonstrations, and technical guides."
|
||||
),
|
||||
"library_back_url": self.parent_object.get_absolute_url(),
|
||||
"library_back_label": f"Back to {self.parent_object.name}",
|
||||
"pagination_range": context["paginator"].get_elided_page_range(
|
||||
context["page_obj"].number
|
||||
),
|
||||
}
|
||||
)
|
||||
return context
|
||||
|
||||
|
||||
class SubProductOlderVersionsView(TemplateView):
|
||||
template_name = "products/versions_archive.html"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user