#NEWLINE# @ get ( '/s/cards/{card_id}/learn' ) #NEWLINE# def learn_card_route( request , card_id ) : #NEWLINE# #INDENT# "\n    Render the card's data, ready for learning.\n\n    NEXT STATE\n    GET Learn Card\n        -> POST Respond Card\n    " #NEWLINE# db_conn = request [ 'db_conn' ] #NEWLINE# current_user = get_current_user ( request ) #NEWLINE# if ( not current_user ) : #NEWLINE# #INDENT# return abort ( 401 ) #NEWLINE# #UNINDENT# card = get_card_by_kind ( db_conn , card_id ) #NEWLINE# if ( not card ) : #NEWLINE# #INDENT# return abort ( 404 ) #NEWLINE# #UNINDENT# context = current_user . get_learning_context ( ) #NEWLINE# if ( context . get ( 'unit' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'entity_id' ) != card [ 'unit_id' ] ) : #NEWLINE# #INDENT# return abort ( 400 ) #NEWLINE# #UNINDENT# next_ = { #NEWLINE# #INDENT# 'method' : 'POST' , #NEWLINE# 'path' : '/s/cards/{card_id}/responses' . format ( card_id = card [ 'entity_id' ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# current_user . set_learning_context ( card = card . data , next = card_id ) #NEWLINE# return ( 200 , { #NEWLINE# #INDENT# 'card' : card . deliver ( access = '' ) , #NEWLINE# 'set' : context . get ( 'set' ) , #NEWLINE# 'unit' : context . get ( 'unit' ) , #NEWLINE# 'next' : next_ , #NEWLINE# #UNINDENT# } )