def pyramids(request, caller_context, container_user, group, active_page=1, active_position=1):
    '''
    get page of pyramid by taking a pyramid id and finding its page
    '''
    pyramidController = PyramidController()
    pyramid_ids = None
    if (group == "joined"):
        pyramid_ids = pyramidController.get_character_pyramid_ids(container_user.character, True)
    elif (group == "friends"):
        pyramid_ids = pyramidController.get_friend_pyramid_ids(container_user.character, True)
    elif (group == "invited"):
        pyramid_ids, invites = pyramidController.get_invited_pyramid_ids(container_user, True)
    elif (group == "open"):
        character = None
        if container_user:
            character = container_user.character
        pyramid_ids = pyramidController.find_open_pyramid_ids(character, 1000)
        if len(pyramid_ids) < 10: # if there are fewer than 10 open pyramids, create one 
            pyramid = pyramidController.create_new_pyramid(4, 3, 100) # 4 total levels, fill 3 levels, $100 price
            pyramid_ids.append(pyramid.key().id())
            logging.debug('created new pyramid: ' + pyramid.to_xml())
        else:
            logging.debug('found open pyramids')
        #controller.set_game_invite(pyramid, container_user.character)
    elif (group == 'condemned'):
        pyramid_ids = pyramidController.get_character_pyramid_ids(container_user.character, active=False, paid=False)
        
    if pyramid_ids:
        pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user, 10, int(active_page), int(active_position))

    return render_to_response('pyramids.html', locals())
def main(request, caller_context, container_user, page=1):
    
    pyramidController = PyramidController()
    chamberController = ChamberController()
    characterController = CharacterController()
    
    current_time = datetime.utcnow() - timedelta(hours = 7) #show Pac time to see if this page gets cached

    if not container_user:
        #user isn't logged in, show some open pyramids
        pyramid_ids = pyramidController.find_open_pyramid_ids(None, 1000)
        if len(pyramid_ids) < 10: # if there are fewer than 10 open pyramids, create one 
            pyramid = pyramidController.create_new_pyramid(4, 3, 100) # 4 total levels, fill 3 levels, $100 price
            pyramid_ids.append(pyramid.key().id())
            logging.debug('created new pyramid: ' + pyramid.to_xml())
        if pyramid_ids:
            pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
        group = 'open'
        return render_to_response('_main.html', locals())

    if caller_context.platform == 'myspace_iframe':
        logging.debug('getting friends from container')
        friends_controller = Friends_controller()
        viewer_friends = friends_controller.refresh_container_friends(container_user)
        encoder = simplejson.JSONEncoder()
        viewer_friends_json = encoder.encode(viewer_friends)

    pyramid_ids = None
    if container_user.character:
        status_bar_dict = characterController.get_status_bar_dict(caller_context.config, container_user.character)
        pyramid_ids = pyramidController.get_character_pyramid_ids(container_user.character, True)
        if pyramid_ids:
            pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
            group = 'joined'
            return render_to_response('_main.html', locals())

    # do this here?  refresh friends?
    #saved, failed = friends_controller.save_container_friends(container_user, viewer_friends)
    #friend_pyramid_ids = pyramidController.get_friend_pyramid_ids(container_user.character, True)

    pyramid_ids = pyramidController.find_open_pyramid_ids(None, 200)
    if pyramid_ids:
        pyramid_display, paginator, pyramid_page = get_paged_pyramids(caller_context.config, pyramid_ids, container_user)
    group = 'open'
    return render_to_response('_main.html', locals())