def getReturnPage(siteHistory,prior=False):
    '''
    This helper function is called in various places to get the return page from current
    session data.  The session data (in the 'SITE_HISTORY' key) is a required argument.
    '''

    expiry = parse_datetime(
        siteHistory.get('expiry',''),
    )
    if prior:
        returnPage = siteHistory.get('priorPage',None)
        returnPageName = siteHistory.get('priorPageName',None)
    else:
        returnPage = siteHistory.get('returnPage',None)
        returnPageName = siteHistory.get('returnPageName',None)

    if expiry and expiry >= timezone.now() and returnPage[0]:
        return {
            'url': reverse(returnPage[0],kwargs=returnPage[1]),
            'title': returnPageName,
        }
    else:
        return {'url': None, 'title': None}