Homepage: Randomize the position of items #215
@ -44,14 +44,15 @@ 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 = {
|
|
||||||
'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.
|
addons_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.BPY)[:24])
|
||||||
random.shuffle(context['addons'])
|
themes_list = list(q.filter(type=EXTENSION_TYPE_CHOICES.THEME)[:12])
|
||||||
random.shuffle(context['themes'])
|
|
||||||
|
# Randomize a sample of the extensions to list.
|
||||||
|
context = {
|
||||||
|
'addons': random.sample(addons_list, 8),
|
||||||
|
'themes': random.sample(themes_list, 4),
|
||||||
|
}
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user