Skip to content

template_views

django_spire.notification.app.views.template_views

notification_dropdown_template_view

Source code in django_spire/notification/app/views/template_views.py
def notification_dropdown_template_view(request: WSGIRequest) -> TemplateResponse:
    if isinstance(request.user, AnonymousUser):
        app_notification_list = []

    else:
        app_notification_list = (
            AppNotification.objects.active()
            .is_sent()
            .annotate_is_viewed_by_user(request.user)
            .select_related('notification')
            .distinct()
            .ordered_by_priority_and_sent_datetime()
        )

    body_data = json.loads(request.body.decode('utf-8'))

    return TemplateResponse(
        request,
        context={
            'app_notification_list': app_notification_list,
            'app_notification_list_url': body_data.get('app_notification_list_url'),
        },
        template='django_spire/notification/app/dropdown/notification_dropdown_content.html'
    )