code: def get_announcements_list(request, context):
      
      user = context["user"]
  
      if context["announcements_admin"] and context["show_all"]:
          # Show all announcements if user has admin permissions and the
          # show_all GET argument is given.
          announcements = (Announcement.objects.all())
      else:
          # Only show announcements for groups that the user is enrolled in.
          if context["show_expired"]:
              announcements = (Announcement.objects.visible_to_user(user))
          else:
              announcements = (Announcement.objects.visible_to_user(user).filter(expiration_date__gt=timezone.now()))
  
      if context["events_admin"] and context["show_all"]:
          events = (Event.objects.all())
      else:
          if context["show_expired"]:
              events = (Event.objects.visible_to_user(user))
          else:
              # Unlike announcements, show events for the rest of the day after they occur.
              midnight = timezone.make_aware(timezone.datetime.combine(datetime.now(), time(0, 0)))
              events = (Event.objects.visible_to_user(user).filter(time__gte=midnight, show_on_dashboard=True))
  
      items = sorted(chain(announcements, events), key=lambda item: (item.pinned, item.added))
      items.reverse()
  
      return items
docs: An announcement will be shown if:
      * It is not expired
  
        * unless ?show_expired=1
  
      * It is visible to the user
  
        * There are no groups on the announcement (so it is public)
        * The user's groups are in union with the groups on the
          announcement (at least one matches)
        * The user submitted the announcement directly
        * The user submitted the announcement through a request
        * The user approved the announcement through a request
        * ...unless ?show_all=1
  
      An event will be shown if:
      * It is not expired
  
        * unless ?show_expired=1
  
      * It is approved
  
        * unless an events admin
  
      * It is visible to the user
  
        * There are no groups
        * The groups are in union