def filter_from_mapping(self, mapping, backend=None):
        """
        Return mappings that either exactly correspond to the given `mapping`
        tuple, or, if the second item of `mapping` is `None`, include mappings
        that only match the first item of `mapping` (useful to show all
        mappings for a given project).
        """
        def mapping_filter(key_item):
            key, item = key_item

            return (
                (mapping is None or item.mapping == mapping or
                    (mapping[1] is None and item.mapping is not None and item.mapping[0] == mapping[0])) and
                (backend is None or item.backend == backend)
            )

        items = [item for item in six.iteritems(self) if mapping_filter(item)]

        aliases = collections.OrderedDict(
            sorted(items, key=lambda alias: alias[1].mapping
                   if alias[1] is not None else (0, 0))
        )

        return aliases