<s> """<STR_LIT>""" <EOL> import logging <EOL> import jinja2 <EOL> from core import counters <EOL> from core import jobs <EOL> from core import jobs_registry <EOL> from core . controllers import base <EOL> from core . controllers import editor <EOL> from core . domain import collection_services <EOL> from core . domain import config_domain <EOL> from core . domain import config_services <EOL> from core . domain import exp_services <EOL> from core . domain import recommendations_services <EOL> from core . domain import rights_manager <EOL> from core . domain import rte_component_registry <EOL> from core . platform import models <EOL> import feconf <EOL> import utils <EOL> current_user_services = models . Registry . import_current_user_services ( ) <EOL> def require_super_admin ( handler ) : <EOL> """<STR_LIT>""" <EOL> def test_super_admin ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not self . user_id : <EOL> self . redirect ( <EOL> current_user_services . create_login_url ( self . request . uri ) ) <EOL> return <EOL> if not current_user_services . is_current_user_super_admin ( ) : <EOL> raise self . UnauthorizedUserException ( <EOL> '<STR_LIT>' , self . user_id ) <EOL> return handler ( self , ** kwargs ) <EOL> return test_super_admin <EOL> class AdminPage ( base . BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> PAGE_NAME_FOR_CSRF = '<STR_LIT>' <EOL> @ require_super_admin <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> self . values [ '<STR_LIT>' ] = [ { <EOL> '<STR_LIT:name>' : counter . name , <EOL> '<STR_LIT:description>' : counter . description , <EOL> '<STR_LIT:value>' : counter . value <EOL> } for counter in counters . Registry . get_all_counters ( ) ] <EOL> if counters . HTML_RESPONSE_COUNT . value : <EOL> average_time = ( <EOL> counters . HTML_RESPONSE_TIME_SECS . value / <EOL> counters . HTML_RESPONSE_COUNT . value ) <EOL> self . values [ '<STR_LIT>' ] . append ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : average_time <EOL> } ) <EOL> if counters . JSON_RESPONSE_COUNT . value : <EOL> average_time = ( <EOL> counters . JSON_RESPONSE_TIME_SECS . value / <EOL> counters . JSON_RESPONSE_COUNT . value ) <EOL> self . values [ '<STR_LIT>' ] . append ( { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:description>' : '<STR_LIT>' , <EOL> '<STR_LIT:value>' : average_time <EOL> } ) <EOL> demo_exploration_ids = feconf . DEMO_EXPLORATIONS . keys ( ) <EOL> recent_job_data = jobs . get_data_for_recent_jobs ( ) <EOL> unfinished_job_data = jobs . get_data_for_unfinished_jobs ( ) <EOL> for job in unfinished_job_data : <EOL> job [ '<STR_LIT>' ] = job [ '<STR_LIT>' ] and any ( [ <EOL> klass . __name__ == job [ '<STR_LIT>' ] <EOL> for klass in jobs_registry . ONE_OFF_JOB_MANAGERS ] ) <EOL> queued_or_running_job_types = set ( [ <EOL> job [ '<STR_LIT>' ] for job in unfinished_job_data ] ) <EOL> one_off_job_specs = [ { <EOL> '<STR_LIT>' : klass . __name__ , <EOL> '<STR_LIT>' : ( <EOL> klass . __name__ in queued_or_running_job_types ) <EOL> } for klass in jobs_registry . ONE_OFF_JOB_MANAGERS ] <EOL> continuous_computations_data = jobs . get_continuous_computations_info ( <EOL> jobs_registry . ALL_CONTINUOUS_COMPUTATION_MANAGERS ) <EOL> for computation in continuous_computations_data : <EOL> if computation [ '<STR_LIT>' ] : <EOL> computation [ '<STR_LIT>' ] = ( <EOL> utils . get_human_readable_time_string ( <EOL> computation [ '<STR_LIT>' ] ) ) <EOL> if computation [ '<STR_LIT>' ] : <EOL> computation [ '<STR_LIT>' ] = ( <EOL> utils . get_human_readable_time_string ( <EOL> computation [ '<STR_LIT>' ] ) ) <EOL> if computation [ '<STR_LIT>' ] : <EOL> computation [ '<STR_LIT>' ] = ( <EOL> utils . get_human_readable_time_string ( <EOL> computation [ '<STR_LIT>' ] ) ) <EOL> self . values . update ( { <EOL> '<STR_LIT>' : continuous_computations_data , <EOL> '<STR_LIT>' : sorted ( feconf . DEMO_COLLECTIONS . iteritems ( ) ) , <EOL> '<STR_LIT>' : sorted ( feconf . DEMO_EXPLORATIONS . iteritems ( ) ) , <EOL> '<STR_LIT>' : demo_exploration_ids , <EOL> '<STR_LIT>' : ( <EOL> utils . get_human_readable_time_string ( <EOL> utils . get_current_time_in_millisecs ( ) ) ) , <EOL> '<STR_LIT>' : one_off_job_specs , <EOL> '<STR_LIT>' : recent_job_data , <EOL> '<STR_LIT>' : jinja2 . utils . Markup ( <EOL> rte_component_registry . Registry . get_html_for_all_components ( ) ) , <EOL> '<STR_LIT>' : unfinished_job_data , <EOL> '<STR_LIT>' : jinja2 . utils . Markup ( <EOL> editor . get_value_generators_js ( ) ) , <EOL> } ) <EOL> self . render_template ( '<STR_LIT>' ) <EOL> class AdminHandler ( base . BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> PAGE_NAME_FOR_CSRF = '<STR_LIT>' <EOL> @ require_super_admin <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> self . render_json ( { <EOL> '<STR_LIT>' : ( <EOL> config_domain . Registry . get_config_property_schemas ( ) ) , <EOL> } ) <EOL> @ require_super_admin <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> exploration_id = self . payload . get ( '<STR_LIT>' ) <EOL> logging . info ( <EOL> '<STR_LIT>' % <EOL> ( self . user_id , exploration_id ) ) <EOL> exp_services . load_demo ( unicode ( exploration_id ) ) <EOL> rights_manager . release_ownership_of_exploration ( <EOL> feconf . SYSTEM_COMMITTER_ID , unicode ( exploration_id ) ) <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> collection_id = self . payload . get ( '<STR_LIT>' ) <EOL> logging . info ( <EOL> '<STR_LIT>' % <EOL> ( self . user_id , collection_id ) ) <EOL> collection_services . load_demo ( unicode ( collection_id ) ) <EOL> rights_manager . release_ownership_of_collection ( <EOL> feconf . SYSTEM_COMMITTER_ID , unicode ( collection_id ) ) <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> exp_services . clear_search_index ( ) <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> new_config_property_values = self . payload . get ( <EOL> '<STR_LIT>' ) <EOL> logging . info ( '<STR_LIT>' % <EOL> ( self . user_id , new_config_property_values ) ) <EOL> for ( name , value ) in new_config_property_values . iteritems ( ) : <EOL> config_services . set_property ( self . user_id , name , value ) <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> config_property_id = self . payload . get ( '<STR_LIT>' ) <EOL> logging . info ( '<STR_LIT>' % <EOL> ( self . user_id , config_property_id ) ) <EOL> config_services . revert_property ( <EOL> self . user_id , config_property_id ) <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> for klass in jobs_registry . ONE_OFF_JOB_MANAGERS : <EOL> if klass . __name__ == self . payload . get ( '<STR_LIT>' ) : <EOL> klass . enqueue ( klass . create_new ( ) ) <EOL> break <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> job_id = self . payload . get ( '<STR_LIT>' ) <EOL> job_type = self . payload . get ( '<STR_LIT>' ) <EOL> for klass in jobs_registry . ONE_OFF_JOB_MANAGERS : <EOL> if klass . __name__ == job_type : <EOL> klass . cancel ( job_id , self . user_id ) <EOL> break <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> computation_type = self . payload . get ( '<STR_LIT>' ) <EOL> for klass in jobs_registry . ALL_CONTINUOUS_COMPUTATION_MANAGERS : <EOL> if klass . __name__ == computation_type : <EOL> klass . start_computation ( ) <EOL> break <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> computation_type = self . payload . get ( '<STR_LIT>' ) <EOL> for klass in jobs_registry . ALL_CONTINUOUS_COMPUTATION_MANAGERS : <EOL> if klass . __name__ == computation_type : <EOL> klass . stop_computation ( self . user_id ) <EOL> break <EOL> elif self . payload . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> data = self . payload . get ( '<STR_LIT:data>' ) <EOL> recommendations_services . update_topic_similarities ( data ) <EOL> self . render_json ( { } ) <EOL> except Exception as e : <EOL> self . render_json ( { '<STR_LIT:error>' : unicode ( e ) } ) <EOL> raise <EOL> class AdminJobOutput ( base . BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> PAGE_NAME_FOR_CSRF = '<STR_LIT>' <EOL> @ require_super_admin <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> job_id = self . request . get ( '<STR_LIT>' ) <EOL> self . render_json ( { <EOL> '<STR_LIT>' : jobs . get_job_output ( job_id ) <EOL> } ) <EOL> class AdminTopicsCsvDownloadHandler ( base . BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> @ require_super_admin <EOL> def get ( self ) : <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> self . response . headers [ '<STR_LIT>' ] = ( <EOL> '<STR_LIT>' ) <EOL> self . response . write ( <EOL> recommendations_services . get_topic_similarities_as_csv ( ) ) </s>
