Skip to content

Commit

Permalink
Rename exploration.parameters to exploration.param_specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlip committed Aug 31, 2013
1 parent 551fa93 commit 221d409
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 73 deletions.
15 changes: 9 additions & 6 deletions core/controllers/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def get(self, exploration_id):
'title': exploration.title,
'editors': exploration.editor_ids,
'states': state_list,
'parameters': [param.to_dict()
for param in exploration.parameters],
# TODO(sll): Update this name in the frontend to param_specs.
'parameters': [param_spec.to_dict()
for param_spec in exploration.param_specs],
'version': exploration.version,
# Add information about the most recent versions.
'snapshots': exp_services.get_exploration_snapshots_metadata(
Expand Down Expand Up @@ -163,7 +164,8 @@ def put(self, exploration_id):
title = self.payload.get('title')
image_id = self.payload.get('image_id')
editors = self.payload.get('editors')
parameters = self.payload.get('parameters')
# TODO(sll): Update this name in the frontend to param_specs.
param_specs = self.payload.get('parameters')

if is_public:
exploration.is_public = True
Expand All @@ -182,9 +184,10 @@ def put(self, exploration_id):
else:
raise self.UnauthorizedUserException(
'Only the exploration owner can add new collaborators.')
if parameters:
exploration.parameters = [
param_domain.ParamSpec.from_dict(param) for param in parameters
if param_specs:
exploration.param_specs = [
param_domain.ParamSpec.from_dict(param_spec)
for param_spec in param_specs
]

exp_services.save_exploration(self.user_id, exploration)
Expand Down
9 changes: 5 additions & 4 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ def __init__(self, exploration_model):
self.category = exploration_model.category
self.title = exploration_model.title
self.state_ids = exploration_model.state_ids
self.parameters = [param_domain.ParamSpec.from_dict(param_spec_dict)
for param_spec_dict in exploration_model.parameters]
self.param_specs = [
param_domain.ParamSpec.from_dict(param_spec_dict)
for param_spec_dict in exploration_model.param_specs]
self.is_public = exploration_model.is_public
self.image_id = exploration_model.image_id
self.editor_ids = exploration_model.editor_ids
Expand Down Expand Up @@ -339,9 +340,9 @@ def init_state(self):
return self.states[0]

@property
def param_dicts(self):
def param_spec_dicts(self):
"""A list of param specs, represented as JSONifiable Python dicts."""
return [param.to_dict() for param in self.parameters]
return [param_spec.to_dict() for param_spec in self.param_specs]

@property
def is_demo(self):
Expand Down
50 changes: 25 additions & 25 deletions core/domain/exp_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,35 +271,35 @@ def export_to_versionable_dict(exploration):
For states, all properties except 'id' are versioned. State dests are
specified using names and not ids.
"""
# TODO(sll): Make this a part of save_exploration().
params = [{
'name': param.name, 'obj_type': param.obj_type
} for param in exploration.parameters]
# TODO(sll): Make this function a part of save_exploration().
param_specs = [{
'name': param_spec.name, 'obj_type': param_spec.obj_type
} for param_spec in exploration.param_specs]

states_list = [export_state_internals_to_dict(
exploration.id, state_id, human_readable_dests=True)
for state_id in exploration.state_ids]

return {
'parameters': params, 'states': states_list
'param_specs': param_specs, 'states': states_list
}


def export_to_yaml(exploration_id):
"""Returns a YAML version of the exploration."""
exploration = get_exploration_by_id(exploration_id)

params = [{
'name': param.name, 'obj_type': param.obj_type
} for param in exploration.parameters]
param_specs = [{
'name': param_spec.name, 'obj_type': param_spec.obj_type
} for param_spec in exploration.param_specs]

states_list = [export_state_internals_to_dict(
exploration_id, state_id, human_readable_dests=True)
for state_id in exploration.state_ids]

return utils.yaml_from_dict({
'default_skin': exploration.default_skin,
'parameters': params,
'param_specs': param_specs,
'states': states_list
})

Expand Down Expand Up @@ -331,7 +331,7 @@ def _save_exploration_transaction(committer_id, exploration):
'category': exploration.category,
'title': exploration.title,
'state_ids': exploration.state_ids,
'parameters': exploration.param_dicts,
'param_specs': exploration.param_spec_dicts,
'is_public': exploration.is_public,
'image_id': exploration.image_id,
'editor_ids': exploration.editor_ids,
Expand Down Expand Up @@ -447,15 +447,15 @@ def get_param_instance(exploration_id, name, obj_type, values):
"""
exploration = get_exploration_by_id(exploration_id)

for param in exploration.parameters:
if param.name == name:
if obj_type and param.obj_type != obj_type:
for param_spec in exploration.param_specs:
if param_spec.name == name:
if obj_type and param_spec.obj_type != obj_type:
raise ValueError(
'Parameter %s has wrong obj_type: was %s, expected %s'
% (name, obj_type, param.obj_type))
% (name, obj_type, param_spec.obj_type))
else:
return param_domain.Parameter(
param.name, param.obj_type, values)
param_spec.name, param_spec.obj_type, values)

# The parameter was not found, so create a new one.
if obj_type is None:
Expand Down Expand Up @@ -575,9 +575,9 @@ def update_state(committer_id, exploration_id, state_id, new_state_name,
exploration_id, param_change['name'], None,
param_change['values'])

if not any([param.name == param_change['name']
for param in exploration.parameters]):
exploration.parameters.append(
if not any([param_spec.name == param_change['name']
for param_spec in exploration.param_specs]):
exploration.param_specs.append(
param_domain.ParamSpec(param_change['name'], None))

state.param_changes.append(param_instance)
Expand Down Expand Up @@ -755,9 +755,9 @@ def create_from_yaml(

try:
# Make this into an exploration store.
exploration_params = [
param_domain.ParamSpec.from_dict(param_dict)
for param_dict in exploration_dict['parameters']
exploration_param_specs = [
param_domain.ParamSpec.from_dict(param_spec_dict)
for param_spec_dict in exploration_dict['param_specs']
]

for sdict in exploration_dict['states']:
Expand All @@ -777,9 +777,9 @@ def create_from_yaml(
) for pc in sdict['param_changes']]

for pc in state.param_changes:
if not any([param.name == pc.name
for param in exploration_params]):
exploration_params.append(pc)
if not any([param_spec.name == pc.name
for param_spec in exploration_param_specs]):
exploration_param_specs.append(pc)

wdict = sdict['widget']
widget_handlers = [exp_domain.AnswerHandlerInstance.from_dict({
Expand All @@ -801,7 +801,7 @@ def create_from_yaml(
save_state(user_id, exploration_id, state)

exploration = get_exploration_by_id(exploration_id)
exploration.parameters = exploration_params
exploration.param_specs = exploration_param_specs
save_exploration(user_id, exploration)
except Exception:
delete_exploration(user_id, exploration_id, force_deletion=True)
Expand Down
4 changes: 2 additions & 2 deletions core/domain/exp_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_export_to_yaml(self):
self.assertEqual(
yaml_content,
"""default_skin: conversation_v1
parameters: []
param_specs: []
states:
- content: []
name: (untitled state)
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_export_to_versionable_dict(self):
exp_services.add_state(self.owner_id, EXP_ID, 'New state')

expected_dict = {
'parameters': [],
'param_specs': [],
'states': [{
'content': [],
'name': u'(untitled state)',
Expand Down
14 changes: 8 additions & 6 deletions core/storage/exploration/django_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class ExplorationModel(base_models.BaseModel):
# be empty.
state_ids = django_utils.ListField(default=[], blank=True)

def validate_parameters(value):
"""Validator for the parameters property."""
def validate_param_specs(value):
"""Validator for the param_specs property."""
try:
assert isinstance(value, list)
for val in value:
Expand All @@ -82,13 +82,15 @@ def validate_parameters(value):
[prop in val for prop in ['name', 'obj_type']])
except AssertionError:
raise ValidationError(
"The 'parameters' property must be a list of parameter dicts"
"The 'param_specs' property must be a list of param_spec dicts"
)

# The list of parameters associated with this exploration.
parameters = django_utils.JSONField(
# The list of parameter specifications associated with this exploration.
# Each specification is a dict with the keys 'name' and 'obj_type', both of
# whose values are strings.
param_specs = django_utils.JSONField(
blank=True, default=[], primitivelist=True,
validators=[validate_parameters]
validators=[validate_param_specs]
)

# Whether this exploration is publicly viewable.
Expand Down
20 changes: 11 additions & 9 deletions core/storage/exploration/gae_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ class ExplorationModel(base_models.BaseModel):
# The list of state ids this exploration consists of. This list should not
# be empty.
state_ids = ndb.StringProperty(repeated=True)
# The list of parameters associated with this exploration.
parameters = ndb.JsonProperty(repeated=True)
# The list of parameter specifications associated with this exploration.
# Each specification is a dict with the keys 'name' and 'obj_type', both of
# whose values are strings.
param_specs = ndb.JsonProperty(repeated=True)
# Whether this exploration is publicly viewable.
is_public = ndb.BooleanProperty(default=False)
# The id for the image to show as a preview of the exploration.
Expand Down Expand Up @@ -134,15 +136,15 @@ def put(self, committer_id, properties, snapshot=None, commit_message=''):

# Do validation.
try:
assert isinstance(self.parameters, list)
for param in self.parameters:
assert isinstance(param, dict)
assert len(param.keys()) == 2
assert 'name' in param
assert 'obj_type' in param
assert isinstance(self.param_specs, list)
for param_spec in self.param_specs:
assert isinstance(param_spec, dict)
assert len(param_spec.keys()) == 2
assert 'name' in param_spec
assert 'obj_type' in param_spec
except AssertionError:
raise db.BadValueError(
"The 'parameters' property must be a list of parameter dicts"
"The 'param_specs' property must be a list of param_spec dicts"
)

if snapshot and snapshot != feconf.NULL_SNAPSHOT:
Expand Down
10 changes: 5 additions & 5 deletions core/storage/exploration/gae_models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ def test_exploration_class(self):

# The 'parameters' property must be a list of Parameter objects.
with self.assertRaises(db.BadValueError):
exploration.parameters = 'A string'
exploration.param_specs = 'A string'

with self.assertRaises(db.BadValueError):
exploration.parameters = [{
exploration.param_specs = [{
'name': 'has_values', 'obj_type': 'Int', 'values': []
}]
exploration.put('A user id', {})

parameter = {'name': 'theParameter', 'obj_type': 'Int'}
exploration.parameters = [parameter]
exploration.param_specs = [parameter]

# The 'is_public' property must be a boolean.
with self.assertRaises(db.BadValueError):
Expand Down Expand Up @@ -112,9 +112,9 @@ def test_exploration_class(self):
retrieved_state = retrieved_exploration.states[0]
self.assertEqual(retrieved_state.id, state.id)

self.assertEqual(len(retrieved_exploration.parameters), 1)
self.assertEqual(len(retrieved_exploration.param_specs), 1)
self.assertEqual(
retrieved_exploration.parameters[0].name, 'theParameter')
retrieved_exploration.param_specs[0].name, 'theParameter')

self.assertEqual(retrieved_exploration.is_public, True)
self.assertEqual(retrieved_exploration.image_id, 'A string')
Expand Down
12 changes: 6 additions & 6 deletions core/storage/exploration/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ def test_exploration_class(self):

# The 'parameters' property must be a list of parameter dicts.
with self.assertRaises(ValidationError):
exploration.parameters = 'A string'
exploration.param_specs = 'A string'
exploration.put('user_id', {})

with self.assertRaises(ValidationError):
exploration.parameters = [{'name': 'no_obj_type'}]
exploration.param_specs = [{'name': 'no_obj_type'}]
exploration.put('user_id', {})

with self.assertRaises(ValidationError):
exploration.parameters = [{
exploration.param_specs = [{
'name': 'has_values', 'obj_type': 'Int', 'values': [6]
}]
exploration.put('user_id', {})

parameter = {'name': 'theParameter', 'obj_type': 'Int'}
exploration.parameters = [parameter]
exploration.param_specs = [parameter]

# The 'is_public' property must be a boolean.
with self.assertRaises(ValidationError):
Expand All @@ -99,9 +99,9 @@ def test_exploration_class(self):
self.assertEqual(retrieved_exploration.category, 'The category')
self.assertEqual(retrieved_exploration.title, 'New exploration')
self.assertEqual(retrieved_exploration.state_ids, [state.id])
self.assertEqual(len(retrieved_exploration.parameters), 1)
self.assertEqual(len(retrieved_exploration.param_specs), 1)
self.assertEqual(
retrieved_exploration.parameters[0].name, 'theParameter')
retrieved_exploration.param_specs[0].name, 'theParameter')
self.assertEqual(retrieved_exploration.is_public, True)
self.assertEqual(retrieved_exploration.image_id, 'A string')
self.assertEqual(retrieved_exploration.editor_ids, ['A user id'])
2 changes: 1 addition & 1 deletion data/explorations/adventure.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters:
param_specs:
- name: Name
obj_type: UnicodeString
- name: Weapon
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/boot_verbs.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters: []
param_specs: []
states:
- name: Sentence
content:
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/counting.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters:
param_specs:
- name: guess
obj_type: TemplatedString
states:
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/hola.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters: []
param_specs: []
states:
- name: Hola
content:
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/landmarks.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters: []
param_specs: []
states:
- name: Taj Mahal on map
content:
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/pitch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ states:
noteToGuess: '{{noteStart}}'
sticky: True
widget_id: MusicStaff
parameters:
param_specs:
- name: noteStart
obj_type: UnicodeString
2 changes: 1 addition & 1 deletion data/explorations/root_linear_coefficient_theorem.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters: []
param_specs: []
states:
- content:
- type: text
Expand Down
2 changes: 1 addition & 1 deletion data/explorations/welcome.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_skin: conversation_v1
parameters: []
param_specs: []
states:
- content:
- type: text
Expand Down
Loading

0 comments on commit 221d409

Please sign in to comment.