Homepage: Randomize the position of items #215

Merged
Pablo Vazquez merged 3 commits from ui-home-randomize into main 2024-07-19 14:46:59 +02:00
Showing only changes of commit 764c1c3fa1 - Show all commits

View File

@ -1,5 +1,6 @@
from collections import OrderedDict from collections import OrderedDict
import logging import logging
import random
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import connection from django.db import connection
@ -44,9 +45,14 @@ class HomeView(ListedExtensionsView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
q = super().get_queryset().order_by('-rating_sortkey') q = super().get_queryset().order_by('-rating_sortkey')
context = { context = {
'addons': q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:8], 'addons': list(q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:8]),
'themes': q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:8], 'themes': list(q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:8]),
} }
# Randomize items in each list.
random.shuffle(context['addons'])
random.shuffle(context['themes'])
return context return context