def get_persistent_graph(request, *args, **kwargs):
 from open_facebook.api import OpenFacebook
 if (not request):
  raise (ValidationError, 'Request is required if you want to use persistent tokens')
 graph = None
 require_refresh = False
 code = request.POST.get('code', request.GET.get('code'))
 if code:
  require_refresh = True
 local_graph = getattr(request, 'facebook', None)
 if local_graph:
  graph = local_graph
 if (not graph):
  cached_graph_dict = request.session.get('graph_dict')
  if cached_graph_dict:
   graph = OpenFacebook()
   graph.__setstate__(cached_graph_dict)
   graph._me = None
 if ((not graph) or require_refresh):
  graph = get_facebook_graph(request, *args, **kwargs)
  if ((graph is not None) and graph.access_token):
   request.session['graph_dict'] = graph.__getstate__()
 _add_current_user_id(graph, request.user)
 request.facebook = graph
 return graph

def get_persistent_graph ( request , * args , ** kwargs ) : from open_facebook . api import OpenFacebook if ( not request ) : raise ( ValidationError , 'Request is required if you want to use persistent tokens' ) graph = None require_refresh = False code = request . POST . get ( 'code' , request . GET . get ( 'code' ) ) if code : require_refresh = True local_graph = getattr ( request , 'facebook' , None ) if local_graph : graph = local_graph if ( not graph ) : cached_graph_dict = request . session . get ( 'graph_dict' ) if cached_graph_dict : graph = OpenFacebook ( ) graph . __setstate__ ( cached_graph_dict ) graph . _me = None if ( ( not graph ) or require_refresh ) : graph = get_facebook_graph ( request , * args , ** kwargs ) if ( ( graph is not None ) and graph . access_token ) : request . session [ 'graph_dict' ] = graph . __getstate__ ( ) _add_current_user_id ( graph , request . user ) request . facebook = graph return graph
wraps itself around get facebook graph but stores the graph in the session .