def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) output_format = self.request.get('output_format', default_value='zip') width = int(self.request.get('width', default_value=80)) # If the title of the exploration has changed, we use the new title. filename = 'oppia-%s-v%s' % (utils.to_ascii( exploration.title.replace(' ', '')), version) if output_format == feconf.OUTPUT_FORMAT_ZIP: self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Content-Disposition'] = ( 'attachment; filename=%s.zip' % str(filename)) self.response.write( exp_services.export_to_zip_file(exploration_id, version)) elif output_format == feconf.OUTPUT_FORMAT_JSON: self.render_json( exp_services.export_states_to_yaml(exploration_id, version=version, width=width)) else: raise self.InvalidInputException('Unrecognized output format %s' % output_format)
def get(self, exploration_id): """Handles GET requests.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version = self.normalized_request.get('v') output_format = self.normalized_request.get('output_format') if version is None: version = exploration.version # If the title of the exploration has changed, we use the new title. if not exploration.title: init_filename = 'oppia-unpublished_exploration-v%s.zip' % version else: init_filename = 'oppia-%s-v%s.zip' % (exploration.title.replace( ' ', ''), version) filename = utils.to_ascii(init_filename) if output_format == feconf.OUTPUT_FORMAT_ZIP: self.render_downloadable_file( exp_services.export_to_zip_file(exploration_id, version=version), filename, 'text/plain') elif output_format == feconf.OUTPUT_FORMAT_JSON: self.render_json( exp_services.export_states_to_yaml(exploration_id, version=version))
def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException if not rights_manager.Actor(self.user_id).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) width = int(self.request.get('width', default_value=80)) try: state = self.request.get('state') except: raise self.InvalidInputException('State not found') exploration_dict = exp_services.export_states_to_yaml(exploration_id, version=version, width=width) if state not in exploration_dict: raise self.PageNotFoundException self.response.write(exploration_dict[state])
def get(self, exploration_id): """Handles GET requests.""" exploration = exp_fetchers.get_exploration_by_id(exploration_id) version_str = self.request.get('v', default_value=exploration.version) output_format = self.request.get('output_format', default_value='zip') try: version = int(version_str) except ValueError: version = exploration.version # If the title of the exploration has changed, we use the new title. if not exploration.title: init_filename = 'oppia-unpublished_exploration-v%s.zip' % version else: init_filename = 'oppia-%s-v%s.zip' % ( exploration.title.replace(' ', ''), version) filename = utils.to_ascii(init_filename).decode('utf-8') if output_format == feconf.OUTPUT_FORMAT_ZIP: self.render_downloadable_file( exp_services.export_to_zip_file( exploration_id, version=version), filename, 'text/plain') elif output_format == feconf.OUTPUT_FORMAT_JSON: self.render_json(exp_services.export_states_to_yaml( exploration_id, version=version)) else: raise self.InvalidInputException( 'Unrecognized output format %s' % output_format)
def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException if not rights_manager.Actor(self.user_id).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) output_format = self.request.get('output_format', default_value='zip') width = int(self.request.get('width', default_value=80)) # If the title of the exploration has changed, we use the new title filename = 'oppia-%s-v%s' % ( utils.to_ascii(exploration.title.replace(' ', '')), version) if output_format == feconf.OUTPUT_FORMAT_ZIP: self.response.headers['Content-Type'] = 'text/plain' self.response.headers['Content-Disposition'] = ( 'attachment; filename=%s.zip' % str(filename)) self.response.write( exp_services.export_to_zip_file(exploration_id, version)) elif output_format == feconf.OUTPUT_FORMAT_JSON: self.render_json(exp_services.export_states_to_yaml( exploration_id, version=version, width=width)) else: raise self.InvalidInputException( 'Unrecognized output format %s' % output_format)
def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) width = int(self.request.get('width', default_value=80)) try: state = self.request.get('state') except: raise self.InvalidInputException('State not found') exploration_dict = exp_services.export_states_to_yaml( exploration_id, version=version, width=width) if state not in exploration_dict: raise self.PageNotFoundException self.response.write(exploration_dict[state])
def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) width = int(self.request.get('width', default_value=80)) try: state = self.request.get('state') except: raise self.InvalidInputException('State not found') exploration_dict = exp_services.export_states_to_yaml(exploration_id, version=version, width=width) if state not in exploration_dict: raise self.PageNotFoundException self.response.write(exploration_dict[state])
def get(self, exploration_id): """Handles GET requests.""" try: exploration = exp_services.get_exploration_by_id(exploration_id) except: raise self.PageNotFoundException if not rights_manager.Actor(self.user_id).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.PageNotFoundException version = self.request.get('v', default_value=exploration.version) width = int(self.request.get('width', default_value=80)) try: state = self.request.get('state') except: raise self.InvalidInputException('State not found') exploration_dict = exp_services.export_states_to_yaml( exploration_id, version=version, width=width) if state not in exploration_dict: raise self.PageNotFoundException self.response.write(exploration_dict[state])