示例#1
0
文件: state.py 项目: trammell/met
    def annotated_answers(self, scenario_id):
        """
        Returns a list of dicts reflecting the correct learner state for
        scenario_id.
        """
        scenario = Scenario.get_by_key_name(scenario_id)
        is_completed = self.is_completed(scenario_id)
        learner_answers = self.learner_answers(scenario_id)

        def annotate(answer):
            """Convert the Answer object into a marked-up dict"""
            a = answer.as_dict()
            # if this scenario has been completed, we want the correct answer
            # to be highlighted
            if is_completed or a['name'] in learner_answers:
                a['disabled'] = True
                if answer.is_correct:
                    a['class'] = "answer correct"
                else:
                    a['class'] = "answer incorrect"
            else:
                a['disabled'] = False
                a['class'] = "answer"
            return a

        return [annotate(answer) for answer in scenario.answer_set]
示例#2
0
文件: test.py 项目: trammell/met
# terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Mpls-ethics is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mpls-ethics.  If not, see <http://www.gnu.org/licenses/>.

from met.model import Scenario
from pprint import pprint

pprint([x for x in  Scenario.all()])
s = Scenario.all()[0]
pprint(s.__dict__)
pprint(dir(s))
pprint(s.fields())

# try get_by_key_name
s = Scenario.get_by_key_name('coi1')
pprint(s.__dict__)

# how does it fail?
s = Scenario.get_by_key_name('coi99')
pprint(s.__dict__)

# test the answer_set attribute
s = Scenario.get_by_key_name('coi1')
示例#3
0
文件: state.py 项目: trammell/met
 def annotate_scenario(self, scenario_id):
     scenario = Scenario.get_by_key_name(scenario_id).as_dict()
     scenario['answers'] = self.annotated_answers(scenario_id)
     scenario['is_completed'] = self.is_completed(scenario_id)
     return scenario