final home desing
This commit is contained in:
@@ -76,16 +76,38 @@ def gate(request):
|
||||
|
||||
|
||||
def home(request):
|
||||
latest_projects = (
|
||||
Project.objects.select_related('owner', 'thumbnail')
|
||||
.prefetch_related('tag_links__tag__category', 'versions')
|
||||
.order_by('-created_at')[:4]
|
||||
)
|
||||
total_downloads = Version.objects.aggregate(total=Sum('downloads'))['total'] or 0
|
||||
creators = (
|
||||
get_user_model().objects.filter(projects__isnull=False).distinct().count()
|
||||
)
|
||||
|
||||
# Per-category Popular (by rating) + Recent columns, 6 packs each.
|
||||
def _base_query(category):
|
||||
return (
|
||||
Project.objects.filter(category=category)
|
||||
.select_related('owner', 'thumbnail')
|
||||
.prefetch_related('versions')
|
||||
.annotate(downloads_total=Sum('versions__downloads'))
|
||||
)
|
||||
|
||||
home_sections = []
|
||||
for value, label in Project.CATEGORY_CHOICES:
|
||||
base = _base_query(value)
|
||||
popular = list(base.order_by('-rating_score', '-created_at')[:6])
|
||||
recent = list(base.order_by('-created_at')[:6])
|
||||
if popular or recent:
|
||||
home_sections.append({
|
||||
'value': value,
|
||||
'label': label,
|
||||
'popular': popular,
|
||||
'recent': recent,
|
||||
})
|
||||
|
||||
# Two categories share each row (compact cards leave room for it).
|
||||
home_rows = [
|
||||
home_sections[i:i + 2] for i in range(0, len(home_sections), 2)
|
||||
]
|
||||
|
||||
announcements = (
|
||||
Announcement.objects.filter(published=True)
|
||||
.annotate(comments_count=Count('comments'))
|
||||
@@ -106,7 +128,7 @@ def home(request):
|
||||
)
|
||||
|
||||
context = {
|
||||
'latest_projects': latest_projects,
|
||||
'home_rows': home_rows,
|
||||
'stats': {
|
||||
'creators': creators,
|
||||
'packs': Project.objects.count(),
|
||||
|
||||
Reference in New Issue
Block a user