Skip to content

Commit

Permalink
(Must be merged in conjunction with oppia#5490) RE -- -ExplorationMig…
Browse files Browse the repository at this point in the history
…ration --- renaming the files. (oppia#5509)

* constants.js

* exp_domain.py and exp_domain_test.py

* exp_jobs_one_off_test.py

* exp_services.py and exp_serivices_test.py

* html_validation_service.py and html_validation_service_test.py

* summary_services_test.py

* QuestionObjectFactorySpec.js

* ExtractImageFilenamesFromStateService.js

* ImagePreloaderService.js and ImagePreloaderSpec.js

* The testszip file

* test_cases_for_rte.json

* gae_suite.py

* base_test.py

* FilepathEditor.js

* feconf.py

* merged with develop

* inlined

* correct _height_
  • Loading branch information
ishucr7 authored and seanlip committed Aug 14, 2018
1 parent 11f5f6c commit e8db6b9
Show file tree
Hide file tree
Showing 18 changed files with 531 additions and 158 deletions.
2 changes: 1 addition & 1 deletion assets/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,5 @@ var constants = {
}
},

"CURRENT_STATES_SCHEMA_VERSION": 24
"CURRENT_STATES_SCHEMA_VERSION": 25
};
67 changes: 62 additions & 5 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

import copy
import functools
import logging
import re
import string
Expand Down Expand Up @@ -3553,9 +3554,41 @@ def _convert_states_v23_dict_to_v24_dict(cls, states_dict):
state_dict, html_validation_service.convert_to_ckeditor)
return states_dict

@classmethod
def _convert_states_v24_dict_to_v25_dict(cls, exp_id, states_dict):
"""Converts from version 24 to 25. Version 25 adds the dimensions of
images in the oppia-noninteractive-image tags.
Args:
exp_id: str. ID of the exploration.
states_dict: dict. A dict where each key-value pair represents,
respectively, a state name and a dict used to initialize a
State domain object.
Returns:
dict. The converted states_dict.
"""
for key, state_dict in states_dict.iteritems():
add_dimensions_to_image_tags = functools.partial(
html_validation_service.add_dimensions_to_image_tags, # pylint: disable=line-too-long
exp_id)
states_dict[key] = State.convert_html_fields_in_state(
state_dict,
add_dimensions_to_image_tags)
if state_dict['interaction']['id'] == 'ImageClickInput':
filename = state_dict['interaction']['customization_args'][
'imageAndRegions']['value']['imagePath']
state_dict['interaction']['customization_args'][
'imageAndRegions']['value']['imagePath'] = (
html_validation_service.get_filename_with_dimensions(
filename, exp_id))

return states_dict

@classmethod
def update_states_from_model(
cls, versioned_exploration_states, current_states_schema_version):
cls, versioned_exploration_states, current_states_schema_version,
exploration_id):
"""Converts the states blob contained in the given
versioned_exploration_states dict from current_states_schema_version to
current_states_schema_version + 1.
Expand All @@ -3571,20 +3604,23 @@ def update_states_from_model(
initialize a State domain object.
current_states_schema_version: int. The current states
schema version.
exploration_id: str. ID of the exploration.
"""
versioned_exploration_states['states_schema_version'] = (
current_states_schema_version + 1)

conversion_fn = getattr(cls, '_convert_states_v%s_dict_to_v%s_dict' % (
current_states_schema_version, current_states_schema_version + 1))
if current_states_schema_version == 24:
conversion_fn = functools.partial(conversion_fn, exploration_id)
versioned_exploration_states['states'] = conversion_fn(
versioned_exploration_states['states'])

# The current version of the exploration YAML schema. If any backward-
# incompatible changes are made to the exploration schema in the YAML
# definitions, this version number must be changed and a migration process
# put in place.
CURRENT_EXP_SCHEMA_VERSION = 29
CURRENT_EXP_SCHEMA_VERSION = 30
LAST_UNTITLED_SCHEMA_VERSION = 9

@classmethod
Expand Down Expand Up @@ -4118,14 +4154,29 @@ def _convert_v28_dict_to_v29_dict(cls, exploration_dict):

return exploration_dict

@classmethod
def _convert_v29_dict_to_v30_dict(cls, exp_id, exploration_dict):
"""Converts a v29 exploration dict into a v30 exploration dict.
Adds dimensions to all oppia-noninteractive-image tags.
"""
exploration_dict['schema_version'] = 30

exploration_dict['states'] = cls._convert_states_v24_dict_to_v25_dict(
exp_id, exploration_dict['states'])
exploration_dict['states_schema_version'] = 25

return exploration_dict

@classmethod
def _migrate_to_latest_yaml_version(
cls, yaml_content, title=None, category=None):
cls, yaml_content, exp_id, title=None, category=None):
"""Return the YAML content of the exploration in the latest schema
format.
Args:
yaml_content: str. The YAML representation of the exploration.
exp_id: str. ID of the exploration.
title: str. The exploration title.
category: str. The exploration category.
Expand Down Expand Up @@ -4295,6 +4346,11 @@ def _migrate_to_latest_yaml_version(
exploration_dict)
exploration_schema_version = 29

if exploration_schema_version == 29:
exploration_dict = cls._convert_v29_dict_to_v30_dict(
exp_id, exploration_dict)
exploration_schema_version = 30

return (exploration_dict, initial_schema_version)

@classmethod
Expand All @@ -4313,7 +4369,8 @@ def from_yaml(cls, exploration_id, yaml_content):
Exception: The initial schema version of exploration is less than
or equal to 9.
"""
migration_result = cls._migrate_to_latest_yaml_version(yaml_content)
migration_result = cls._migrate_to_latest_yaml_version(
yaml_content, exploration_id)
exploration_dict = migration_result[0]
initial_schema_version = migration_result[1]

Expand Down Expand Up @@ -4345,7 +4402,7 @@ def from_untitled_yaml(cls, exploration_id, title, category, yaml_content):
or equal to 9.
"""
migration_result = cls._migrate_to_latest_yaml_version(
yaml_content, title=title, category=category)
yaml_content, exploration_id, title=title, category=category)
exploration_dict = migration_result[0]
initial_schema_version = migration_result[1]

Expand Down
Loading

0 comments on commit e8db6b9

Please sign in to comment.