def _choice_by_type_or_id(obj): if IChoice.providedBy(obj): return obj.cluster #Assume cluster id as argument if obj and isinstance(obj, string_types): return obj raise TypeError("%r was not a Choice instance or a cluster id of a question" % obj)
def test_func(self): root = self.fixture() section = self.survey_fixture(root) request = testing.DummyRequest() request.locale_name = 'sv' init_request_methods(request) request.root = root q1 = root['questions']['q1'] q2 = root['questions']['q2'] q3 = root['questions']['q3'] section.responses['part_uid'] = {q1.cluster: 'a', q2.cluster: 'c'} res1 = self._fut(request, section, q1, 'part_uid', lang = 'sv') self.assertEqual(res1.cluster, 'a') self.failUnless(IChoice.providedBy(res1)) res2 = self._fut(request, section, q2, 'part_uid') self.assertEqual(res2.cluster, 'c') res3 = self._fut(request, section, q3, 'part_uid', lang = 'sv', default = 'fail') self.assertEqual(res3, 'fail')
def get_choices(self, lang): results = [] for obj in self.values(): if IChoice.providedBy(obj) and obj.language == lang: results.append(obj) return results