def get_assignment_value_js(self): value_tree = self.result_tree[parse_tree['CHILDREN_TREES']][ self.value_index] prod_name = value_tree[parse_tree['PROD_NAME']] production = Survey.string_to_class(prod_name)(value_tree) return production.generate_js()
def get_assignment_value_js(self): value_tree = self.result_tree[ parse_tree['CHILDREN_TREES']][self.value_index] prod_name = value_tree[parse_tree['PROD_NAME']] production = Survey.string_to_class(prod_name)(value_tree) return production.generate_js()
def post(self, request, *args, **kwargs): result = {} if request.is_ajax(): if request.POST['type'] == self.GENERATE_TYPE: Survey.text = ' ' + request.POST['input'] + ' ' error, survey = Survey.generate() result['survey'] = survey result['error'] = error elif request.POST['type'] == self.SAVE_TYPE: provider = DatabaseProvider() result['success'] = provider.save( request.POST['new'] == '1', request.POST['name'], request.POST['user'], request.POST['code'], request.POST['js']) elif request.POST['type'] == self.SEARCH_TYPE: provider = DatabaseProvider() result['results'] = ';'.join( provider.search(request.POST['text'], request.POST['username'])) elif request.POST['type'] == self.OPEN_TYPE: provider = DatabaseProvider() result['survey'] = provider.find( request.POST['name']) return HttpResponse(json.dumps(result), content_type="application/json")
def post(self, request, *args, **kwargs): result = {} if request.is_ajax(): if request.POST['type'] == self.GENERATE_TYPE: Survey.text = ' ' + request.POST['input'] + ' ' error, survey = Survey.generate() result['survey'] = survey result['error'] = error elif request.POST['type'] == self.SAVE_TYPE: provider = DatabaseProvider() result['success'] = provider.save(request.POST['new'] == '1', request.POST['name'], request.POST['user'], request.POST['code'], request.POST['js']) elif request.POST['type'] == self.SEARCH_TYPE: provider = DatabaseProvider() result['results'] = ';'.join( provider.search(request.POST['text'], request.POST['username'])) elif request.POST['type'] == self.OPEN_TYPE: provider = DatabaseProvider() result['survey'] = provider.find(request.POST['name']) return HttpResponse(json.dumps(result), content_type="application/json")
def generate_js(self): string_tree = self.result_tree[parse_tree['CHILDREN_TREES']][0] self.result_tree[parse_tree['CHILDREN_TREES']].pop(0) widget_subclass = Survey.string_tree_to_class( string_tree, self.get_class_name()) return widget_subclass( self.result_tree, additional_js_args=self.js_args_list).generate_js()
def generate_js(self): string_tree = self.result_tree[parse_tree['CHILDREN_TREES']][0] self.result_tree[parse_tree['CHILDREN_TREES']].pop(0) widget_subclass = Survey.string_tree_to_class(string_tree, self.get_class_name()) return widget_subclass( self.result_tree, additional_js_args=self.js_args_list).generate_js()
def get_widget_value_js(self): children_trees = self.result_tree[parse_tree['CHILDREN_TREES']] value_tree = children_trees[self.value_index] var_tree = children_trees[self.var_index] var_id = Value(var_tree).generate_simple_js() widget = Survey.string_to_class('widget')( value_tree, additional_js_args=['resultVarName: "' + var_id + '"']) return widget.generate_js()
def generate_simple_js(self): js_parts = [] for production in self.result_tree[parse_tree['CHILDREN_TREES']]: prod_class = Survey.string_to_class( production[parse_tree['PROD_NAME']]) js_parts.append(prod_class(production).generate_simple_js()) has_else = len(js_parts) == 3 return '((' + js_parts[0] + ')?(' + js_parts[1] + '):(' +\ (js_parts[2] if has_else else '""') + '))'
def generate_simple_js(self): text = [] for production in self.result_tree[parse_tree['CHILDREN_TREES']]: prod_class = Survey.string_to_class( production[parse_tree['PROD_NAME']]) prod_js = prod_class(production).generate_simple_js() if production[parse_tree['PROD_NAME']] == 'innerString': prod_js = '"' + prod_js + '"' text.append(prod_js) return ' + '.join(text)
def generate_js(self): value_type = self.value_tree[parse_tree['PROD_NAME']] if (self.data and not value_type in self.type_synonims[self.data['type']]): raise Exception('Argument ' + self.name + ' should be one of types: ' + str(self.type_synonims[self.data['type']]) + ' not ' + value_type) value = Survey.string_to_class(value_type)(self.value_tree, self.data) js = value.generate_js() return ((self.name + ': ') if len(self.name) else '') + js
def generate_js(self): condition = '' conditions = [] js = [] for component in self.result_tree[parse_tree['CHILDREN_TREES']]: if component[parse_tree['PROD_NAME']] == 'condition': condition = Condition(component).generate_js() else: if condition == '': condition = "function() { return true }" js.append( "{condition: function() { return " + condition + "()" + (" && " + " && ".join(conditions) if len(conditions) > 0 else "") + " }, body: function() { " + Survey.generate_productions_js( component[parse_tree['CHILDREN_TREES']]) + "}}") conditions.append("!(" + condition + "())") condition = '' return (Survey.survey_var + ".addWidgetConditional([" + ",".join(js) + "]);\n")
def generate_js(self): condition = '' conditions = [] js = [] for component in self.result_tree[parse_tree['CHILDREN_TREES']]: if component[parse_tree['PROD_NAME']] == 'condition': condition = Condition( component).generate_js() else: if condition == '': condition = "function() { return true }" js.append("{condition: function() { return " + condition + "()" + ( " && " + " && ".join(conditions) if len(conditions) > 0 else "") + " }, body: function() { " + Survey.generate_productions_js( component[parse_tree['CHILDREN_TREES']]) + "}}") conditions.append("!(" + condition + "())") condition = '' return (Survey.survey_var + ".addWidgetConditional([" + ",".join(js) + "]);\n")
from iss.surveys.parser import Parser from iss.surveys.survey import Survey from iss.surveys.pythonTests import test_cases errors = 0 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) #unbuffered stdout for i in range(0, len(test_cases)): try: Survey.text = test_cases[i] success, result_trees, next_character = Parser.parse(Survey.text) if not success or next_character != len(Survey.text): raise Exception("Parsing error") Survey.generate_js(result_trees) print('.', end='') except Exception: errors += 1 if len(sys.argv) == 1 or (not sys.argv[1] in ['-v', '--verbose']): print('x', end='') continue wrong_test_num = "\nTest %s error:\n" % i error_details = "Survey text:\n%s\n" % test_cases[i] print(wrong_test_num + error_details) raise