<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def notification_update(request):
 """ Handles live updating of notifications, follows ajax-polling approach. Read more: http://stackoverflow.com/a/12855533/4726598 Required URL parameters: ``flag``. Explanation: - The ``flag`` parameter carries the last notification ID \ received by the user's browser. - This ``flag`` is most likely to be generated by using \ a simple JS/JQuery DOM. Just grab the first element of \ the notification list. - The element will have a ``data-id`` attribute set to the \ corresponding notification. - We'll use it's value as the flag parameter. - The view treats the ``last notification flag`` as a model \ ```filter()`` and fetches all notifications greater than \ the flag for the user. - Then the a JSON data is prepared with all necessary \ details such as, ``verb``, ``actor``, ``target`` and their \ URL etc. The foreignkey are serialized as their \ default ``__str__`` value. - Everything will be HTML escaped by django's ``escape()``. - Since these notification sent will only serve temporarily \ on the notification box and will be generated fresh \ using a whole template, to avoid client-side notification \ generation using the JSON data, the JSON data will also \ contain a rendered HTML string so that you can easily \ do a JQuery ``$yourNotificationBox.prepend()`` on the \ rendered html string of the notification. - The template used is expected to be different than the \ template used in full page notification as the css \ and some other elements are highly likely to be \ different than the full page notification list. \ - The template used will be the ``notification type`` of the \ notification suffixed ``_box.html``. So, if your \ notification type is ``comment_reply``, the template \ will be ``comment_reply_box.html``. - This template will be stored in ``notifications/includes/`` \ of your template directory. - That makes: ``notifications/includes/comment_reply_box.html`` - The rest is self-explanatory. :param request: HTTP request context. :return: Notification updates (if any) in JSON format. """

    flag = request.GET.get('flag', None)
    target = request.GET.get('target', 'box')
    last_notification = int(flag) if flag.isdigit() else None

    if last_notification:

        new_notifications = request.user.notifications.filter(
            id__gt=last_notification).active().prefetch()

        msg = _("Notifications successfully retrieved.") \
            if new_notifications else _("No new notifications.")
        notification_list = []
        for nf in new_notifications:
            notification = nf.as_json()
            notification_list.append(notification)
            notification['html'] = render_notification(
                nf, render_target=target, **notification)

        ctx = {
            "retrieved": len(new_notifications),
            "unread_count": request.user.notifications.unread().count(),
            "notifications": notification_list,
            "success": True,
            "msg": msg,
        }

        return JsonResponse(ctx)

    else:
        msg = _("Notification flag not sent.")

    ctx = {"success": False, "msg": msg}
    return JsonResponse(ctx)