Пример #1
0
def apimethod_get_pulse_list(page=0, page_row=10):
    """Returns the list of current_status messages matching the given criteria.

    Args:
        page(int)    : Page number
        page_row(int): Number of items per page

    Returns:
        A tuple (boolean,data) where the first argument indicates whether the operation went well or not,
        and the second one contains the data, in case the operation went wll or an error string otherwise

    """
    pulse_list = {"total": 0, "pulses": []}
    start = page
    end = start + page_row - 1

    try:
        pulse_db = PulseDB()
        p_keys = pulse_db.keys()
        p_vals = pulse_db.get_range(start, end, 'desc')
        del pulse_db

        pulses = []
        for p in p_vals:
            pulses.append({
                "id": p.get('id'),
                "name": p.get('name'),
                "author_name": p.get('author_name'),
                "created": p.get('created'),
                "description": p.get('description'),
                "modified": p.get('modified'),
                "tags": p.get('tags')
            })

        pulse_list["total"] = len(p_keys)
        pulse_list["pulses"] = pulses

    except Exception as err:
        api_log.error("[apimethod_get_pulse_list] %s" % str(err))
        return False, "Error retrieving the Pulse List: %s" % str(err)

    return True, pulse_list
Пример #2
0
def apimethod_get_pulse_list(page=0, page_row=10):
    """Returns the list of current_status messages matching the given criteria.

    Args:
        page(int)    : Page number
        page_row(int): Number of items per page

    Returns:
        A tuple (boolean,data) where the first argument indicates whether the operation went well or not,
        and the second one contains the data, in case the operation went wll or an error string otherwise

    """
    pulse_list = {"total": 0, "pulses": []}
    start = page
    end = start + page_row - 1

    try:
        pulse_db = PulseDB()
        p_keys = pulse_db.keys()
        p_vals = pulse_db.get_range(start, end, 'desc')
        del pulse_db

        pulses = []
        for p in p_vals:
            pulses.append({"id": p.get('id'),
                           "name": p.get('name'),
                           "author_name": p.get('author_name'),
                           "created": p.get('created'),
                           "description": p.get('description'),
                           "modified": p.get('modified'),
                           "tags": p.get('tags')})

        pulse_list["total"] = len(p_keys)
        pulse_list["pulses"] = pulses

    except Exception as err:
        api_log.error("[apimethod_get_pulse_list] %s" % str(err))
        return False, "Error retrieving the Pulse List: %s" % str(err)

    return True, pulse_list