<s> import datetime <EOL> import logging <EOL> from tornado import gen , web <EOL> import base <EOL> import models <EOL> class CalendarHandler ( base . BaseHandler ) : <EOL> @ web . asynchronous <EOL> @ gen . coroutine <EOL> @ base . authorized <EOL> def get ( self , url ) : <EOL> self . tf . send ( { '<STR_LIT>' : <NUM_LIT:1> } , lambda x : x ) <EOL> error = self . get_error ( ) <EOL> user = yield self . get_current_user_async ( ) <EOL> profile = user <EOL> if not user or user . url != url : <EOL> profile = models . User . objects ( url = url ) . first ( ) <EOL> calendar_runs = yield self . thread_pool . submit ( <EOL> models . Run . get_calendar_runs , profile ) <EOL> self . render ( '<STR_LIT>' , page_title = '<STR_LIT>' , user = user , today = datetime . date . today ( ) . strftime ( "<STR_LIT>" ) , this_year = datetime . date . today ( ) . year , error = error , profile = profile , calendar_runs = calendar_runs ) <EOL> class CalendarMilesHandler ( base . BaseHandler ) : <EOL> @ web . asynchronous <EOL> @ gen . coroutine <EOL> @ base . authorized <EOL> def get ( self , url ) : <EOL> self . tf . send ( { '<STR_LIT>' : <NUM_LIT:1> } , lambda x : x ) <EOL> error = self . get_error ( ) <EOL> user = yield self . get_current_user_async ( ) <EOL> profile = user <EOL> if not user or user . url != url : <EOL> profile = models . User . objects ( url = url ) . first ( ) <EOL> def calculate_miles ( ) : <EOL> calendar_runs = models . Run . get_calendar_runs ( profile ) <EOL> distances = [ x . distance for day in calendar_runs for x in day [ '<STR_LIT>' ] ] <EOL> return distances <EOL> distances = yield self . thread_pool . submit ( calculate_miles ) <EOL> self . finish ( str ( sum ( distances ) ) ) </s>
