Updated event display algorithm on home page.
authorJonathan S. Katz <jonathan.katz@excoventures.com>
Thu, 17 May 2018 16:25:27 +0000 (12:25 -0400)
committerJonathan S. Katz <jonathan.katz@excoventures.com>
Thu, 17 May 2018 16:25:27 +0000 (12:25 -0400)
The homepage will now display seven events, allowing up to two
events that are not community badged to be present.

pgweb/core/views.py

index 336b82796e0b395c433cc3caff4cbc228cc98727..d60c82eab0e0d487115f5ee01ee2f97d72cad887 100644 (file)
@@ -41,13 +41,18 @@ from forms import OrganisationForm, MergeOrgsForm
 @cache(minutes=10)
 def home(request):
        news = NewsArticle.objects.filter(approved=True)[:5]
-       # get the first five community events
-       events = Event.objects.select_related('country').filter(
+       # get up to seven events to display on the homepage
+       event_base_queryset = Event.objects.select_related('country').filter(
                approved=True,
                training=False,
                enddate__gte=date.today(),
-               badged=True,
-       ).order_by('enddate', 'startdate')[:5]
+       )
+       # first, see if there are up to do non-badged events
+       other_events = event_base_queryset.filter(badged=False)[:2]
+       # based on that, get 7 - |other_events| community events to display
+       community_event_queryset = event_base_queryset.filter(badged=True)[:(7 - other_events.count())]
+       # now, return all the events in one unioned array!
+       events = community_event_queryset.union(other_events).order_by('enddate', 'startdate').all()
        versions = Version.objects.filter(supported=True)
        planet = ImportedRSSItem.objects.filter(feed__internalname="planet").order_by("-posttime")[:9]