#NEWLINE# @ post ( '/s/sets/{set_id}/units/{unit_id}' ) #NEWLINE# def choose_unit_route( request , set_id , unit_id ) : #NEWLINE# #INDENT# "\n    Updates the learner's information based on the unit they have chosen.\n\n    NEXT STATE\n    POST Chosen Unit\n        -> GET Learn 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# unit = Unit . get_latest_accepted ( db_conn , unit_id ) #NEWLINE# if ( not unit ) : #NEWLINE# #INDENT# return abort ( 404 ) #NEWLINE# #UNINDENT# context = current_user . get_learning_context ( ) #NEWLINE# set_ids = [ set_ [ 'entity_id' ] for set_ in Set . list_by_unit_id ( db_conn , unit_id ) ] #NEWLINE# if ( context . get ( 'set' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . get ( 'entity_id' ) not in set_ids ) : #NEWLINE# #INDENT# return abort ( 400 ) #NEWLINE# #UNINDENT# status = judge ( db_conn , unit , current_user ) #NEWLINE# if ( status == 'done' ) : #NEWLINE# #INDENT# return abort ( 400 ) #NEWLINE# #UNINDENT# card = choose_card ( db_conn , current_user , unit ) #NEWLINE# if card : #NEWLINE# #INDENT# next_ = { #NEWLINE# #INDENT# 'method' : 'GET' , #NEWLINE# 'path' : '/s/cards/{card_id}/learn' . format ( card_id = card [ 'entity_id' ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# next_ = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# current_user . set_learning_context ( unit = unit . data , card = ( card . data if card else None ) , next = next_ ) #NEWLINE# return ( 200 , { #NEWLINE# #INDENT# 'next' : next_ , #NEWLINE# #UNINDENT# } )