def get_queryset()

in src/olympia/accounts/views.py [0:0]


    def get_queryset(self, dev=False):
        user = self.get_user()
        queryset = UserNotification.objects.filter(user=user)

        # Fetch all `UserNotification` instances and then,
        # overwrite their value with the data from basket.

        # Put it into a dict so we can easily check for existence.
        set_notifications = {
            user_nfn.notification.short: user_nfn
            for user_nfn in queryset
            if user_nfn.notification
        }
        out = []

        newsletters = None  # Lazy - fetch the first time needed.
        by_basket_id = REMOTE_NOTIFICATIONS_BY_BASKET_ID
        for basket_id, notification in by_basket_id.items():
            if notification.group == 'dev' and not user.is_developer:
                # We only return dev notifications for developers.
                continue
            if newsletters is None:
                newsletters = fetch_subscribed_newsletters(user)
            user_notification = self._get_default_object(notification)
            user_notification.enabled = basket_id in newsletters
            set_notifications[notification.short] = user_notification

        include_dev = dev or user.is_developer
        for notification in NOTIFICATIONS_COMBINED:
            if notification.group == 'dev' and not include_dev:
                # We only return dev notifications for developers.
                continue
            out.append(
                set_notifications.get(
                    notification.short,  # It's been set by the user.
                    self._get_default_object(notification),
                )
            )  # Or, default.
        return out