Homepage: Randomize the position of items #215
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user