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 2534781d99 - Show all commits

View File

@ -48,10 +48,14 @@ class HomeView(ListedExtensionsView):
addons_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:24])
themes_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:12])
# Get 8 add-ons, 4 themes, or the minimum available.
addons_sample_size = min(8, len(addons_list))
themes_sample_size = min(4, len(themes_list))
# Randomize a sample of the extensions to list.
context = {
'addons': random.sample(addons_list, 8),
'themes': random.sample(themes_list, 4),
'addons': random.sample(addons_list, addons_sample_size),
'themes': random.sample(themes_list, themes_sample_size),
}
return context