def get_question_row(formset, total): question_name = formset.field_list[0]['input']['name'] field_name = common.get_name(question_name) question = ' '.join(formset.question.splitlines()) partial_question = [ 'Q', 'M', field_name, 1, question, formset.help_text, 'en', '', common.get_mandatory(formset), '', ] full_row = partial_question + common.get_missing(partial_question, total) # TODO: find out a way to express the limit as words too: if formset.limits and len(formset.limits) == 2: min_a, max_a = formset.limits column_definition = ( ('min_answers', min_a), ('max_answers', max_a), ) full_row = common.update_row(full_row, column_definition) full_row.append(formset.get_dependencies()) return full_row
def get_text_row(formset, total): field_name = u'a%s' % formset.field['id'] partial_row = [ 'Q', 'X', field_name, 1, formset.field['text'], # Text content '', # Help text 'en', '', '', ] full_row = partial_row + common.get_missing(partial_row, total) common.update_row(full_row, ( ('other', 'N'), ('same_default', '1'), ('statistics_showgraph', '1'), ('time_limit_action', '1'), )) # Add row metadata: full_row.append(formset.get_dependencies()) return [full_row]
def add_dependencies(row_list): """Adds any dependency between the given rows using the metadata.""" get_condition = partial(get_field_condition, row_list=row_list) for i, row in enumerate(row_list): if not has_metadata(row): # Row has no dependencies. Ignore. continue metadata = row[-1] # `triggers` are the fields that activate this field: if 'triggers' in metadata and metadata['triggers']: conditions = set([get_condition(t) for t in metadata['triggers']]) conditions = filter(None, conditions) if conditions: conditions = sorted(conditions) conditions_str = ' OR '.join(conditions) if conditions_str in CONDITION_REPLACEMENTS: new_str = CONDITION_REPLACEMENTS[conditions_str] logger.debug( 'Replacing `%s` with `%s`', conditions_str, new_str) conditions_str = new_str common.update_row(row, ( ('relevance', conditions_str), )) return row_list
def get_question_row(formset, total): field_name = common.get_matrix_value(formset.matrix_id) partial_question = [ 'Q', ';', field_name, 1, formset.question, formset.help_text, 'en', '', common.get_mandatory(formset), '', ] full_question = partial_question + common.get_missing(partial_question, total) custom_fields = ( ('same_default', 1), ) full_question = common.update_row(full_question, custom_fields) return full_question
def prepare_inputtext_row(formset, total): field_name = common.get_name(formset.field['name']) partial_row = [ 'Q', 'T', field_name, 1, formset.question, formset.help_text, 'en', '', common.get_mandatory(formset), ] full_row = partial_row + common.get_missing(partial_row, total) if formset.limits: column_definition = ( ('maximum_chars', formset.limits[-1]), ) else: column_definition = () full_row = common.update_row(full_row, column_definition) # Add row metadata: full_row.append(formset.get_dependencies()) return [full_row]