def update_friends(request, caller_context, container_user): response = { 'success' : False, 'message' : 'unknown error'} if request.method != "POST": response.message ='only POST method is supported' else: friends_controller = Friends_controller() friends_json = request.raw_post_data logging.debug('friends json from update_friends: %s' % friends_json) decoder = simplejson.JSONDecoder() friends = decoder.decode(friends_json) try: pyramidController = PyramidController() saved, failed = friends_controller.save_container_friends(container_user, friends) friend_pyramid_ids = pyramidController.get_friend_pyramid_ids(container_user.character, True) response['success'] = True response['message'] = 'friend list updated - %d saved, %d failed to save' % (saved, failed) response['friendPyramidCount'] = len(friend_pyramid_ids) except Exception, e: logging.warn('failed to save friends') logging.warn('friends json: %s' % friends_json) logging.exception(e) response['success'] = False response['message'] = 'error saving friends'
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())