Exemplo n.º 1
0
 def _get_notification_settings(self, store, language):
     """
     notification setting need to contains bot template
     and systemsettings
     """
     notif = store.find(models.Notification).one()
     return admin_serialize_notification(notif, language)
Exemplo n.º 2
0
def load_complete_events(store, event_number=GLSetting.notification_limit):
    """
    _complete_ is explicit because do not serialize, but make an OD() of the description.

    event_number represent the amount of event that can be returned by the function,
    event to be notified are taken in account later.
    """

    node_desc = db_admin_serialize_node(store, GLSetting.defaults.language)

    event_list = []
    storedevnts = store.find(EventLogs, EventLogs.mail_sent == False)
    storedevnts.order_by(Desc(EventLogs.creation_date))

    for i, stev in enumerate(storedevnts):

        if len(event_list) == event_number:
            log.debug(
                "Maximum number of notification event reach (Mailflush) %d, after %d"
                % (event_number, i))
            break

        if not stev.description['receiver_info']['file_notification'] and \
                        stev.event_reference['kind'] == 'File':
            continue
        if not stev.description['receiver_info']['message_notification'] and \
                        stev.event_reference['kind'] == 'Message':
            continue
        if not stev.description['receiver_info']['comment_notification'] and \
                        stev.event_reference['kind'] == 'Comment':
            continue
        if not stev.description['receiver_info']['tip_notification'] and \
                        stev.event_reference['kind'] == 'Tip':
            continue

        eventcomplete = OD()

        # node level information are not stored in the node, but fetch now
        eventcomplete.notification_settings = admin_serialize_notification(
            store.find(Notification).one(),
            stev.description['receiver_info']['language'])

        eventcomplete.node_info = node_desc

        # event level information are decoded form DB in the old 'Event'|nametuple format:
        eventcomplete.receiver_info = stev.description['receiver_info']
        eventcomplete.tip_info = stev.description['tip_info']
        eventcomplete.subevent_info = stev.description['subevent_info']
        eventcomplete.context_info = stev.description['context_info']
        eventcomplete.steps_info = stev.description['steps_info']

        eventcomplete.type = stev.description['type']  # 'Tip', 'Comment'
        eventcomplete.trigger = stev.event_reference[
            'kind']  # 'plaintext_blah' ...

        eventcomplete.storm_id = stev.id

        event_list.append(eventcomplete)

    return event_list
Exemplo n.º 3
0
def load_complete_events(store, events_limit=GLSettings.notification_limit):
    """
    This function do not serialize, but make an OD() of the description.
    events_limit represent the amount of event that can be returned by the function,
    events to be notified are taken in account later.
    """
    node_desc = db_admin_serialize_node(store, GLSettings.memory_copy.default_language)

    event_list = []

    totaleventinqueue = store.find(EventLogs, EventLogs.mail_sent == False).count()
    storedevnts = store.find(EventLogs, EventLogs.mail_sent == False)[: events_limit * 3]

    debug_event_counter = {}
    for i, stev in enumerate(storedevnts):
        if len(event_list) == events_limit:
            log.debug("Reached maximum number of event notifications doable on a single loop %d" % events_limit)
            break

        debug_event_counter.setdefault(stev.event_reference["kind"], 0)
        debug_event_counter[stev.event_reference["kind"]] += 1

        if not stev.description["receiver_info"]["tip_notification"]:
            continue

        eventcomplete = OD()

        # node level information are not stored in the node, but fetch now
        eventcomplete.notification_settings = admin_serialize_notification(
            store.find(Notification).one(), stev.description["receiver_info"]["language"]
        )

        eventcomplete.node_info = node_desc

        # event level information are decoded form DB in the old 'Event'|nametuple format:
        eventcomplete.receiver_info = stev.description["receiver_info"]
        eventcomplete.tip_info = stev.description["tip_info"]
        eventcomplete.subevent_info = stev.description["subevent_info"]
        eventcomplete.context_info = stev.description["context_info"]

        eventcomplete.type = stev.description["type"]  # 'Tip', 'Comment'
        eventcomplete.trigger = stev.event_reference["kind"]  # 'blah' ...

        eventcomplete.orm_id = stev.id

        event_list.append(eventcomplete)

    if debug_event_counter:
        if totaleventinqueue > (events_limit * 3):
            log.debug("load_complete_events: %s from %d Events" % (debug_event_counter, totaleventinqueue))
        else:
            log.debug(
                "load_complete_events: %s from %d Events, with a protection limit of %d"
                % (debug_event_counter, totaleventinqueue, events_limit * 3)
            )

    return event_list
Exemplo n.º 4
0
def load_complete_events(store, events_limit=GLSettings.notification_limit):
    """
    This function do not serialize, but make an OD() of the description.
    events_limit represent the amount of event that can be returned by the function,
    events to be notified are taken in account later.
    """
    node_desc = db_admin_serialize_node(store, GLSettings.defaults.language)

    event_list = []
    totaleventinqueue = store.find(EventLogs, EventLogs.mail_sent == False).count()
    storedevnts = store.find(EventLogs, EventLogs.mail_sent == False)[:events_limit * 3]

    debug_event_counter = {}
    for i, stev in enumerate(storedevnts):
        if len(event_list) == events_limit:
            log.debug("Maximum number of notification event reach (Mailflush) %d, after %d" %
                      (events_limit, i))
            break

        debug_event_counter.setdefault(stev.event_reference['kind'], 0)
        debug_event_counter[stev.event_reference['kind']] += 1

        if not stev.description['receiver_info']['tip_notification']:
            continue

        eventcomplete = OD()

        # node level information are not stored in the node, but fetch now
        eventcomplete.notification_settings = admin_serialize_notification(
            store.find(Notification).one(), stev.description['receiver_info']['language']
        )

        eventcomplete.node_info = node_desc

        # event level information are decoded form DB in the old 'Event'|nametuple format:
        eventcomplete.receiver_info = stev.description['receiver_info']
        eventcomplete.tip_info = stev.description['tip_info']
        eventcomplete.subevent_info = stev.description['subevent_info']
        eventcomplete.context_info = stev.description['context_info']

        eventcomplete.type = stev.description['type'] # 'Tip', 'Comment'
        eventcomplete.trigger = stev.event_reference['kind'] # 'blah' ...

        eventcomplete.orm_id = stev.id

        event_list.append(eventcomplete)

    if debug_event_counter:
        if totaleventinqueue > (events_limit * 3):
            log.debug("load_complete_events: %s from %d Events" %
                      (debug_event_counter, totaleventinqueue ))
        else:
            log.debug("load_complete_events: %s from %d Events, with a protection limit of %d" %
                      (debug_event_counter, totaleventinqueue, events_limit * 3 ))

    return event_list
Exemplo n.º 5
0
def load_complete_events(store, event_number=GLSetting.notification_limit):
    """
    _complete_ is explicit because do not serialize, but make an OD() of the description.

    event_number represent the amount of event that can be returned by the function,
    event to be notified are taken in account later.
    """

    node_desc = db_admin_serialize_node(store, GLSetting.defaults.language)

    event_list = []
    storedevnts = store.find(EventLogs, EventLogs.mail_sent == False)
    storedevnts.order_by(Asc(EventLogs.creation_date))

    debug_event_counter = {}
    for i, stev in enumerate(storedevnts):
        if len(event_list) == event_number:
            log.debug("Maximum number of notification event reach (Mailflush) %d, after %d" %
                      (event_number, i))
            break

        debug_event_counter.setdefault(stev.event_reference['kind'], 0)
        debug_event_counter[stev.event_reference['kind']] += 1

        if not stev.description['receiver_info']['tip_notification']:
            continue

        eventcomplete = OD()

        # node level information are not stored in the node, but fetch now
        eventcomplete.notification_settings = admin_serialize_notification(
            store.find(Notification).one(), stev.description['receiver_info']['language']
        )

        eventcomplete.node_info = node_desc

        # event level information are decoded form DB in the old 'Event'|nametuple format:
        eventcomplete.receiver_info = stev.description['receiver_info']
        eventcomplete.tip_info = stev.description['tip_info']
        eventcomplete.subevent_info = stev.description['subevent_info']
        eventcomplete.context_info = stev.description['context_info']
        eventcomplete.steps_info = stev.description['steps_info']

        eventcomplete.type = stev.description['type'] # 'Tip', 'Comment'
        eventcomplete.trigger = stev.event_reference['kind'] # 'plaintext_blah' ...

        eventcomplete.storm_id = stev.id

        event_list.append(eventcomplete)

    if debug_event_counter:
        log.debug("load_complete_events: %s" % debug_event_counter)

    return event_list