Return a Page object from a slug or an id.

def get_page_from_string_or_id(page_string, lang=None):
    """Return a Page object from a slug or an id."""
    if type(page_string) == int:
        return Page.objects.get(pk=int(page_string))
    # if we have a string coming from some templates templates
    is_text = isinstance(page_string, SafeText)
    import sys
    PY3 = sys.version > '3'
    if PY3:
        is_string = isinstance(page_string, str)
    else:
        is_string = isinstance(page_string, unicode) or isinstance(page_string, str)
    if is_text or is_string:
        if page_string.isdigit():
            return Page.objects.get(pk=int(page_string))
        return Page.objects.from_path(page_string, lang)
    # in any other case we return the input becasue it's probably
    # a Page object.
    return page_string