def base_context_processor(request):
    """This is a hook which adds the returned dictionary to the context for
    every view in the project.  It is used to allow the site name to be
    added to the base_template in every view.
    Namespace any items added here with 'base_' in order to avoid conflict.
    """
    site_name = models.GlobalConfig.objects.all().order_by('id')[0].site_name
    messages = models.Message.objects.filter(route="").filter(
        Q(status="unread", expires="read") | ~Q(expires="read"))
    from iondb.rundb.api import MessageResource
    resource = MessageResource()
    msg_list = [resource.full_dehydrate(Bundle(message)) for message in messages]
    serialized_messages = resource.serialize(None, msg_list, "application/json")
    base_js_extra = settings.JS_EXTRA
    if msg_list:
        logger.debug("Found %d global messages" % len(msg_list))
        
    logger.debug("Global messages are %s" % serialized_messages)
    
    if request.user:
        user_messages = models.Message.objects.filter(route=request.user).filter(Q(status="unread", expires="read") | ~Q(expires="read"))
        user_msglist = [resource.full_dehydrate(Bundle(message)) for message in user_messages]
        user_serialized_messages = resource.serialize(None, user_msglist, "application/json")
        logger.debug("User messages are %s" % user_serialized_messages)
    return {"base_site_name": site_name, "global_messages": serialized_messages,
            "user_messages":user_serialized_messages, "base_js_extra" : base_js_extra}
Beispiel #2
0
def base_context_processor(request):
    """This is a hook which adds the returned dictionary to the context for
    every view in the project.  It is used to allow the site name to be
    added to the base_template in every view.
    Namespace any items added here with 'base_' in order to avoid conflict.
    """
    gconfig = models.GlobalConfig.get()
    messages = models.Message.objects.filter(route="").filter(
        Q(status="unread", expires="read") | ~Q(expires="read"))
    from iondb.rundb.api import MessageResource
    resource = MessageResource()
    msg_list = [resource.full_dehydrate(Bundle(message)) for message in messages]
    serialized_messages = resource.serialize(None, msg_list, "application/json")
    base_js_extra = settings.JS_EXTRA
    
    if request.user:
        users = [request.user.username]
        if request.user.is_staff:
            users.append(models.Message.USER_STAFF)
        user_messages = models.Message.objects.filter(route__in=users).filter(Q(status="unread", expires="read") | ~Q(expires="read"))
        user_msglist = [resource.full_dehydrate(Bundle(message)) for message in user_messages]
        user_serialized_messages = resource.serialize(None, user_msglist, "application/json")

    unread_news = 0
    if request.user.is_authenticated() and gconfig.check_news_posts:
        unread_news = models.NewsPost.objects.filter(updated__gte=request.user.userprofile.last_read_news_post).count()

    return {"base_site_name": gconfig.site_name, "global_messages": serialized_messages,
            "user_messages":user_serialized_messages, "base_js_extra" : base_js_extra,
            "unread_news": unread_news, "DEBUG": settings.DEBUG}
Beispiel #3
0
def base_context_processor(request):
    """This is a hook which adds the returned dictionary to the context for
    every view in the project.  It is used to allow the site name to be
    added to the base_template in every view.
    Namespace any items added here with 'base_' in order to avoid conflict.
    """
    gconfig = models.GlobalConfig.get()
    messages = models.Message.objects.filter(route="").filter(
        Q(status="unread", expires="read") | ~Q(expires="read"))
    from iondb.rundb.api import MessageResource
    resource = MessageResource()
    msg_list = [resource.full_dehydrate(Bundle(message)) for message in messages]
    serialized_messages = resource.serialize(None, msg_list, "application/json")
    base_js_extra = settings.JS_EXTRA

    if request.user:
        users = [request.user.username]
        if request.user.is_staff:
            users.append(models.Message.USER_STAFF)
        user_messages = models.Message.objects.filter(route__in=users).filter(Q(status="unread", expires="read") | ~Q(expires="read"))
        user_msglist = [resource.full_dehydrate(Bundle(message)) for message in user_messages]
        user_serialized_messages = resource.serialize(None, user_msglist, "application/json")

    unread_news = 0
    if request.user.is_authenticated() and gconfig.check_news_posts:
        unread_news = models.NewsPost.objects.filter(updated__gte=request.user.userprofile.last_read_news_post).count()

    return {"base_site_name": gconfig.site_name, "global_messages": serialized_messages,
            "user_messages": user_serialized_messages, "base_js_extra": base_js_extra,
            "unread_news": unread_news, "DEBUG": settings.DEBUG, "version": settings.VERSION}
Beispiel #4
0
def base_context_processor(request):
    """This is a hook which adds the returned dictionary to the context for
    every view in the project.  It is used to allow the site name to be
    added to the base_template in every view.
    Namespace any items added here with 'base_' in order to avoid conflict.
    """
    site_name = models.GlobalConfig.objects.all().order_by('id')[0].site_name
    messages = models.Message.objects.filter(route="").filter(
        Q(status="unread", expires="read") | ~Q(expires="read"))
    from iondb.rundb.api import MessageResource
    resource = MessageResource()
    msg_list = [
        resource.full_dehydrate(Bundle(message)) for message in messages
    ]
    serialized_messages = resource.serialize(None, msg_list,
                                             "application/json")
    base_js_extra = settings.JS_EXTRA
    if msg_list:
        logger.debug("Found %d global messages" % len(msg_list))

    logger.debug("Global messages are %s" % serialized_messages)

    if request.user:
        user_messages = models.Message.objects.filter(
            route=request.user).filter(
                Q(status="unread", expires="read") | ~Q(expires="read"))
        user_msglist = [
            resource.full_dehydrate(Bundle(message))
            for message in user_messages
        ]
        user_serialized_messages = resource.serialize(None, user_msglist,
                                                      "application/json")
        logger.debug("User messages are %s" % user_serialized_messages)
    return {
        "base_site_name": site_name,
        "global_messages": serialized_messages,
        "user_messages": user_serialized_messages,
        "base_js_extra": base_js_extra
    }