#NEWLINE# @ tornado . gen . coroutine #NEWLINE# def render_focus( task , loctx , conn , focusobj ) : #NEWLINE# #INDENT# 'The part of generate_update() that deals with focus.\n    Returns (focus, focusspecial).\n    ' #NEWLINE# if ( focusobj is None ) : #NEWLINE# #INDENT# return ( False , False ) #NEWLINE# #UNINDENT# assert ( conn . uid == loctx . uid ) #NEWLINE# if ( type ( focusobj ) is list ) : #NEWLINE# #INDENT# restype = focusobj [ 0 ] #NEWLINE# if ( restype == 'player' ) : #NEWLINE# #INDENT# player = ( yield motor . Op ( task . app . mongodb . players . find_one , { #NEWLINE# #INDENT# '_id' : focusobj [ 1 ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'name' : 1 , #NEWLINE# 'desc' : 1 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if ( not player ) : #NEWLINE# #INDENT# return ( 'There is no such person.' , False ) #NEWLINE# #UNINDENT# focusdesc = ( '%s is %s' % ( player . get ( 'name' , '???' ) , player . get ( 'desc' , '...' ) ) ) #NEWLINE# conn . focusdependencies . add ( ( 'players' , focusobj [ 1 ] , 'desc' ) ) #NEWLINE# conn . focusdependencies . add ( ( 'players' , focusobj [ 1 ] , 'name' ) ) #NEWLINE# return ( focusdesc , False ) #NEWLINE# #UNINDENT# if ( restype == 'portlist' ) : #NEWLINE# #INDENT# ( dummy , plistid , editable , extratext , withback , portid ) = focusobj #NEWLINE# if extratext : #NEWLINE# #INDENT# ctx = EvalPropContext ( task , loctx = loctx , level = LEVEL_DISPLAY ) #NEWLINE# extratext = ( yield ctx . eval ( extratext , evaltype = EVALTYPE_TEXT ) ) #NEWLINE# if ctx . linktargets : #NEWLINE# #INDENT# conn . focusactions . update ( ctx . linktargets ) #NEWLINE# #UNINDENT# if ctx . dependencies : #NEWLINE# #INDENT# conn . focusdependencies . update ( ctx . dependencies ) #NEWLINE# #UNINDENT# #UNINDENT# portlist = ( yield motor . Op ( task . app . mongodb . portlists . find_one , { #NEWLINE# #INDENT# '_id' : plistid , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if ( not portlist ) : #NEWLINE# #INDENT# raise ErrorMessageException ( 'No such portal list.' ) #NEWLINE# #UNINDENT# if ( ( 'uid' in portlist ) and ( portlist [ 'uid' ] != conn . uid ) ) : #NEWLINE# #INDENT# raise ErrorMessageException ( 'This portal list is not yours.' ) #NEWLINE# #UNINDENT# if ( ( 'wid' in portlist ) and ( portlist [ 'wid' ] != loctx . wid ) ) : #NEWLINE# #INDENT# raise ErrorMessageException ( 'This portal list is not available.' ) #NEWLINE# #UNINDENT# if portid : #NEWLINE# #INDENT# portal = ( yield motor . Op ( task . app . mongodb . portals . find_one , { #NEWLINE# #INDENT# '_id' : portid , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# if ( not portal ) : #NEWLINE# #INDENT# raise ErrorMessageException ( 'No such portal.' ) #NEWLINE# #UNINDENT# if ( portal . get ( 'plistid' , None ) != plistid ) : #NEWLINE# #INDENT# raise ErrorMessageException ( 'Portal does not match portlist.' ) #NEWLINE# #UNINDENT# if withback : #NEWLINE# #INDENT# backkey = ( 'plistback' + EvalPropContext . build_action_key ( ) ) #NEWLINE# conn . focusactions [ backkey ] = ( 'focusportal' , None , plistid ) #NEWLINE# extratext = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# backkey = None #NEWLINE# #UNINDENT# ( yield two . execute . portal_in_reach ( task . app , portal , conn . uid , loctx . wid ) ) #NEWLINE# portalobj = ( yield two . execute . portal_description ( task . app , portal , conn . uid , uidiid = loctx . iid , location = True ) ) #NEWLINE# portalobj [ 'portid' ] = str ( portal [ '_id' ] ) #NEWLINE# ackey = ( 'port' + EvalPropContext . build_action_key ( ) ) #NEWLINE# conn . focusactions [ ackey ] = ( 'portal' , portid ) #NEWLINE# if portalobj . get ( 'copyable' , False ) : #NEWLINE# #INDENT# copykey = ( 'copy' + EvalPropContext . build_action_key ( ) ) #NEWLINE# conn . focusactions [ copykey ] = ( 'copyportal' , portid ) #NEWLINE# portalobj [ 'copyable' ] = copykey #NEWLINE# #UNINDENT# altloctx = two . task . LocContext ( None , wid = portal [ 'wid' ] , locid = portal [ 'locid' ] ) #NEWLINE# ctx = EvalPropContext ( task , loctx = altloctx , level = LEVEL_FLAT ) #NEWLINE# try : #NEWLINE# #INDENT# desttext = ( yield ctx . eval ( 'portaldesc' ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# desttext = None #NEWLINE# #UNINDENT# if ctx . linktargets : #NEWLINE# #INDENT# conn . focusactions . update ( ctx . linktargets ) #NEWLINE# #UNINDENT# if ctx . dependencies : #NEWLINE# #INDENT# conn . focusdependencies . update ( ctx . dependencies ) #NEWLINE# #UNINDENT# if ( not desttext ) : #NEWLINE# #INDENT# desttext = task . app . localize ( 'message.no_portaldesc' ) #NEWLINE# #UNINDENT# portalobj [ 'view' ] = desttext #NEWLINE# specres = [ 'portal' , ackey , portalobj , backkey , extratext ] #NEWLINE# return ( specres , True ) #NEWLINE# #UNINDENT# if ( not loctx . iid ) : #NEWLINE# #INDENT# query = { #NEWLINE# #INDENT# 'plistid' : plistid , #NEWLINE# 'iid' : None , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query = { #NEWLINE# #INDENT# 'plistid' : plistid , #NEWLINE# '$or' : [ { #NEWLINE# #INDENT# 'iid' : None , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'iid' : loctx . iid , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# cursor = task . app . mongodb . portals . find ( query ) #NEWLINE# ls = [ ] #NEWLINE# while ( yield cursor . fetch_next ) : #NEWLINE# #INDENT# portal = cursor . next_object ( ) #NEWLINE# ls . append ( portal ) #NEWLINE# #UNINDENT# ls . sort ( key = ( lambda portal : portal . get ( 'listpos' , 0 ) ) ) #NEWLINE# conn . focusdependencies . add ( ( 'portlist' , plistid , None ) ) #NEWLINE# if loctx . iid : #NEWLINE# #INDENT# conn . focusdependencies . add ( ( 'portlist' , plistid , loctx . iid ) ) #NEWLINE# #UNINDENT# subls = [ ] #NEWLINE# for portal in ls : #NEWLINE# #INDENT# desc = ( yield two . execute . portal_description ( task . app , portal , conn . uid , uidiid = loctx . iid , short = True ) ) #NEWLINE# if ( not desc ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ackey = ( 'plist' + EvalPropContext . build_action_key ( ) ) #NEWLINE# conn . focusactions [ ackey ] = ( 'focusportal' , portal [ '_id' ] , plistid ) #NEWLINE# desc [ 'target' ] = ackey #NEWLINE# if ( editable and withback ) : #NEWLINE# #INDENT# desc [ 'portid' ] = str ( portal [ '_id' ] ) #NEWLINE# #UNINDENT# subls . append ( desc ) #NEWLINE# #UNINDENT# editkey = None #NEWLINE# if ( editable and withback ) : #NEWLINE# #INDENT# editkey = ( 'editplist' + EvalPropContext . build_action_key ( ) ) #NEWLINE# conn . focusactions [ editkey ] = ( 'editplist' , plistid ) #NEWLINE# #UNINDENT# specres = [ 'portlist' , subls , extratext , editkey ] #NEWLINE# return ( specres , True ) #NEWLINE# #UNINDENT# focusdesc = ( '[Focus: %s]' % ( focusobj , ) ) #NEWLINE# return ( focusdesc , False ) #NEWLINE# #UNINDENT# if ( type ( focusobj ) is not str ) : #NEWLINE# #INDENT# return ( str ( focusobj ) , False ) #NEWLINE# #UNINDENT# if focusobj . startswith ( '_' ) : #NEWLINE# #INDENT# raise Exception ( ( 'Temporary variable cannot be focus: %s' % ( focusobj , ) ) ) #NEWLINE# #UNINDENT# ctx = EvalPropContext ( task , loctx = loctx , level = LEVEL_DISPSPECIAL ) #NEWLINE# focusdesc = ( yield ctx . eval ( focusobj , evaltype = EVALTYPE_SYMBOL ) ) #NEWLINE# if ctx . linktargets : #NEWLINE# #INDENT# conn . focusactions . update ( ctx . linktargets ) #NEWLINE# #UNINDENT# if ctx . dependencies : #NEWLINE# #INDENT# conn . focusdependencies . update ( ctx . dependencies ) #NEWLINE# #UNINDENT# return ( focusdesc , ctx . wasspecial )