-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement editing of questions #5614
Changes from 19 commits
d9f2824
f0cb957
9c8e702
c93f186
f695dd6
066faec
07a11fb
2386f69
4360648
a68adef
dd9d25f
8a2c2bd
4782099
a20b0ab
4668f51
fd91189
2f4f1cc
3050886
6d52d8c
43807b1
7a4ff6f
41798c6
c496793
fbdaa83
732be38
7756f6d
17ca89f
5785784
13254ea
fc4981d
9ef2940
5861a5a
4ccea9c
0c589eb
c0ad966
9896d99
4d3c329
d37ab38
f6f7e09
5722ca1
3b5983f
c4c9b93
98227d0
5abc2c8
387a9cb
7a10a7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,7 +186,7 @@ def get_question_skill_links_of_skill(skill_id): | |
Returns: | ||
list(QuestionSkillLinkModel). The list of question skill link | ||
domain objects that are linked to the skill ID or an empty list | ||
if the skill does not exist. | ||
if the skill does not exist. | ||
""" | ||
|
||
question_skill_link_models = ( | ||
|
@@ -196,6 +196,26 @@ def get_question_skill_links_of_skill(skill_id): | |
return question_skill_link_models | ||
|
||
|
||
def get_question_skill_links_of_question(question_id): | ||
"""Returns a list of QuestionSkillLinkModels of | ||
a particular question ID. | ||
|
||
Args: | ||
question_id: str. ID of the question. | ||
|
||
Returns: | ||
list(QuestionSkillLinkModel). The list of question skill link | ||
domain objects that are linked to the question ID or an empty list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the domain objects for QuestionSkillLink are being returned currently. Can you change the returned object to be a list of QuestionSkillLink domain objects instead of datastore objects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, I think the docstring should also be changed to QuestionSkillLink, instead of QuestionSkillLinkModel? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pending comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
if the question does not exist. | ||
""" | ||
|
||
question_skill_link_models = ( | ||
question_models.QuestionSkillLinkModel.get_models_by_question_id( | ||
question_id) | ||
) | ||
return question_skill_link_models | ||
|
||
|
||
def update_skill_ids_of_questions(curr_skill_id, new_skill_id): | ||
"""Updates the skill ID of QuestionSkillLinkModels to the superseding | ||
skill ID. | ||
|
@@ -316,9 +336,9 @@ def apply_change_list(question_id, change_list): | |
if (change.property_name == | ||
question_domain.QUESTION_PROPERTY_LANGUAGE_CODE): | ||
question.update_language_code(change.new_value) | ||
elif (change.cmd == | ||
elif (change.property_name == | ||
question_domain.QUESTION_PROPERTY_QUESTION_STATE_DATA): | ||
question.update_question_data(change.new_value) | ||
question.update_question_state_data(change.new_value) | ||
|
||
return question | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,22 @@ def get_multi_skill_summaries(skill_ids): | |
return skill_summaries | ||
|
||
|
||
def get_multi_skills(skill_ids): | ||
"""Returns a list of skills matching the skill IDs provided. | ||
|
||
Args: | ||
skill_ids: list(str). List of skill IDs to get skills for. | ||
|
||
Returns: | ||
list(Skill). The list of skills matching the provided IDs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to reflect the implementation just excluding skills that are None. Either throw an exception if a skill is requested that does not exist, or return None in the appropriate position; probably the former is better if you don't expect this to occur in practice. But just silently removing stuff altogether seems like it's not the right thing to do -- you'll end up with the length of the input list not matching the output list which is something the caller won't expect given the function contract. There should also be tests for this error case, it's quite important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by raising Exception |
||
""" | ||
local_skill_models = skill_models.SkillModel.get_multi(skill_ids) | ||
skills = [ | ||
get_skill_from_model(skill_model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if any of the skill_id doesn't exist? In that case, won't a None be returned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
for skill_model in local_skill_models] | ||
return skills | ||
|
||
|
||
def get_skill_summary_from_model(skill_summary_model): | ||
"""Returns a domain object for an Oppia skill summary given a | ||
skill summary model. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,22 @@ def get_models_by_skill_id(cls, skill_id): | |
return QuestionSkillLinkModel.query().filter( | ||
cls.skill_id == skill_id).fetch() | ||
|
||
@classmethod | ||
def get_models_by_question_id(cls, question_id): | ||
"""Returns a list of QuestionSkillLink domains of a particular | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. QuestionSkillLink domains --> QuestionSkillLinkModels, right? |
||
question ID. | ||
|
||
Args: | ||
question_id: str. ID of the question. | ||
|
||
Returns: | ||
list(QuestionSkillLinkModel)|None. The list of question skill link | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto -- question skill link domains --> question skill link models. Domain objects refer to stuff defined in core/domain ("plain old python objects"). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
domains that are linked to the question ID. None if the question | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this correctly differentiate between "question ID doesn't exist" and "there are no question skill link models corresponding to this question ID"? Looking at the implementation I'm not sure it does, we might need to update the docstring to be clearer here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
ID doesn't exist. | ||
""" | ||
return QuestionSkillLinkModel.query().filter( | ||
cls.question_id == question_id).fetch() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
@classmethod | ||
def put_multi_question_skill_links(cls, question_skill_links): | ||
"""Puts multiple question skill links into the datastore. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,3 +146,127 @@ oppia.factory('UndoRedoService', [ | |
return UndoRedoService; | ||
} | ||
]); | ||
|
||
// TODO(tjiang11): Figure out way to create new instance of service without | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just thinking on reading this that a lot of this code seems pretty general. Why can't we reuse the existing UndoRedoService instead of duplicating? I'm concerned that this becomes one of those TODOs that never gets done (e.g. #4968 just appeared in my inbox) so I feel like we should do it properly since we'll need it for other things too? In general code duplication should be avoided as much as possible (and this is really quite a lot of it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deduplicated |
||
// code duplication. | ||
oppia.factory('QuestionUndoRedoService', [ | ||
'$rootScope', 'EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED', | ||
function($rootScope, EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED) { | ||
var QuestionUndoRedoService = {}; | ||
|
||
var _appliedChanges = []; | ||
var _undoneChanges = []; | ||
|
||
var _dispatchMutation = function() { | ||
$rootScope.$broadcast(EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED); | ||
}; | ||
var _applyChange = function(changeObject, domainObject) { | ||
changeObject.applyChange(domainObject); | ||
_dispatchMutation(); | ||
}; | ||
var _reverseChange = function(changeObject, domainObject) { | ||
changeObject.reverseChange(domainObject); | ||
_dispatchMutation(); | ||
}; | ||
|
||
/** | ||
* Pushes a change domain object onto the change stack and applies it to the | ||
* provided domain object. When a new change is applied, all undone changes | ||
* are lost and cannot be redone. This will fire an event as defined by the | ||
* constant EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED. | ||
*/ | ||
QuestionUndoRedoService.applyChange = function(changeObject, domainObject) { | ||
_applyChange(changeObject, domainObject); | ||
_appliedChanges.push(changeObject); | ||
_undoneChanges = []; | ||
}; | ||
|
||
/** | ||
* Undoes the last change to the provided domain object. This function | ||
* returns false if there are no changes to undo, and true otherwise. This | ||
* will fire an event as defined by the constant | ||
* EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED. | ||
*/ | ||
QuestionUndoRedoService.undoChange = function(domainObject) { | ||
if (_appliedChanges.length !== 0) { | ||
var change = _appliedChanges.pop(); | ||
_undoneChanges.push(change); | ||
_reverseChange(change, domainObject); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
/** | ||
* Reverses an undo for the given domain object. This function returns false | ||
* if there are no changes to redo, and true if otherwise. This will fire an | ||
* event as defined by the constant EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED. | ||
*/ | ||
QuestionUndoRedoService.redoChange = function(domainObject) { | ||
if (_undoneChanges.length !== 0) { | ||
var change = _undoneChanges.pop(); | ||
_appliedChanges.push(change); | ||
_applyChange(change, domainObject); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
/** | ||
* Returns the current list of changes applied to the provided domain | ||
* object. This list will not contain undone actions. Changes to the | ||
* returned list will not be reflected in this service. | ||
*/ | ||
QuestionUndoRedoService.getChangeList = function() { | ||
// TODO(bhenning): Consider integrating something like Immutable.js to | ||
// avoid the slice here and ensure the returned object is truly an | ||
// immutable copy. | ||
return _appliedChanges.slice(); | ||
}; | ||
|
||
/** | ||
* Returns a list of commit dict updates representing all chosen changes in | ||
* this service. Changes to the returned list will not affect this service. | ||
* Furthermore, the returned list is ready to be sent to the backend. | ||
*/ | ||
QuestionUndoRedoService.getCommittableChangeList = function() { | ||
var committableChangeList = []; | ||
for (var i = 0; i < _appliedChanges.length; i++) { | ||
committableChangeList[i] = _appliedChanges[i].getBackendChangeObject(); | ||
} | ||
return committableChangeList; | ||
}; | ||
|
||
QuestionUndoRedoService.setChangeList = function(changeList) { | ||
_appliedChanges = angular.copy(changeList); | ||
}; | ||
|
||
/** | ||
* Returns the number of changes that have been applied to the domain | ||
* object. | ||
*/ | ||
QuestionUndoRedoService.getChangeCount = function() { | ||
return _appliedChanges.length; | ||
}; | ||
|
||
/** | ||
* Returns whether this service has any applied changes. | ||
*/ | ||
QuestionUndoRedoService.hasChanges = function() { | ||
return _appliedChanges.length !== 0; | ||
}; | ||
|
||
/** | ||
* Clears the change history. This does not reverse any of the changes | ||
* applied from applyChange() or redoChange(). This will fire an event as | ||
* defined by the constant EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED. | ||
*/ | ||
QuestionUndoRedoService.clearChanges = function() { | ||
_appliedChanges = []; | ||
_undoneChanges = []; | ||
_dispatchMutation(); | ||
}; | ||
|
||
return QuestionUndoRedoService; | ||
} | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added