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 34dd1c4a15 - Show all commits

View File

@ -44,14 +44,15 @@ class HomeView(ListedExtensionsView):
def get_context_data(self, **kwargs):
q = super().get_queryset().order_by('-rating_sortkey')
context = {
'addons': list(q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:8]),
'themes': list(q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:8]),
}
# Randomize items in each list.
random.shuffle(context['addons'])
random.shuffle(context['themes'])
addons_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:24])
themes_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:12])
# Randomize a sample of the extensions to list.
context = {
'addons': random.sample(addons_list, 8),
'themes': random.sample(themes_list, 4),
}
return context