'Given a list of (unique) ids and a list of items having an \'id\' attribute,
return items that have the given ids in that order.
If an id in ids is not found or if an item in items doesn\'t have a given
id, they will not be in the returned list.'

def _order_items_by_id(self, ids, items):

    ID_ATTR_NAME = 'id'
    item_dict = {}
    for item in items:
        item_id = getattr(item, ID_ATTR_NAME, None)
        if item_id:
            item_dict[item_id] = item
    in_order = []
    for id in ids:
        if (id in item_dict):
            in_order.append(item_dict[id])
    return in_order
