#NEWLINE# def get_request_query( request , attrs = None ) : #NEWLINE# #INDENT# '\n    Resolves the appropriate DataQuery object for use from the request.\n    ' #NEWLINE# if ( attrs is None ) : #NEWLINE# #INDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# attrs = request . data . get ( 'query' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . method == 'GET' ) : #NEWLINE# #INDENT# attrs = request . GET . get ( 'query' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( attrs is None ) : #NEWLINE# #INDENT# json = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# context = get_request_context ( request ) #NEWLINE# if context : #NEWLINE# #INDENT# json [ 'context' ] = context . json #NEWLINE# #UNINDENT# view = get_request_view ( request ) #NEWLINE# if view : #NEWLINE# #INDENT# json [ 'view' ] = view . json #NEWLINE# #UNINDENT# return DataQuery ( json ) #NEWLINE# #UNINDENT# if isinstance ( attrs , dict ) : #NEWLINE# #INDENT# json = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# context = get_request_context ( request , attrs = attrs ) #NEWLINE# if context : #NEWLINE# #INDENT# json [ 'context' ] = context . json #NEWLINE# #UNINDENT# view = get_request_view ( request , attrs = attrs ) #NEWLINE# if view : #NEWLINE# #INDENT# json [ 'view' ] = view . json #NEWLINE# #UNINDENT# DataQuery . validate ( json ) #NEWLINE# return DataQuery ( json ) #NEWLINE# #UNINDENT# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( getattr ( request , 'user' , None ) and request . user . is_authenticated ( ) ) : #NEWLINE# #INDENT# kwargs [ 'user' ] = request . user #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( request . session . session_key is None ) : #NEWLINE# #INDENT# return DataQuery ( ) #NEWLINE# #UNINDENT# kwargs [ 'session_key' ] = request . session . session_key #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# kwargs [ 'pk' ] = int ( attrs ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# kwargs [ 'session' ] = True #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return DataQuery . objects . get ( ** kwargs ) #NEWLINE# #UNINDENT# except DataQuery . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# instance = DataQuery ( ) #NEWLINE# default = DataQuery . objects . get_default_template ( ) #NEWLINE# if default : #NEWLINE# #INDENT# instance . json = default . json #NEWLINE# #UNINDENT# return instance