def get_answer_row(field, total): # Multiple select fields use the same field name to send # different values. Unfortunately lime survey doesn't support # this type of format. Checkboxes fields are represented as a # list of fields with different names and a `Y` value is sent # when the field is checked. # Since the `id` and `value` field name are the same a # workaround is to send a special `value` that will be reversed # as the field ID to extract the original `name` and the value # can be attached . e.g # value='6251626' compressed to `v1626` # `v1626` references field ID `6251626` and the field contains # `name` and `value` to be sent back. row_value = common.get_value(field['input']['value']) partial_row = [ 'SQ', 0, row_value, '', field['label'], '', 'en', '', '', '', ] full_row = partial_row + common.get_missing(partial_row, total) metadata = { 'field_id': field['input'].get('id'), } full_row.append(metadata) return full_row
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_page_row(page, total, formset_list): page_row = [ 'G', '', page['title'], 1, get_page_text(formset_list), '', 'en', ] return page_row + common.get_missing(page_row, total)
def get_settings_rows(form_tree, total): """Creates LimeSurvey settings rows.""" custom_settings = get_custom_settings(form_tree) settings_rows = [] for row in constants.GLOBAL_SETTINGS: missing = common.get_missing(row, total) full_row = list(row) + missing # Update any custom setting value: row_id = full_row[2] if row_id in custom_settings: full_row[4] = custom_settings[row_id] settings_rows.append(full_row) return settings_rows
def get_subquestion_rows(formset, total): subquestion_rows = [] for name, question_list in formset.field_list: subquestion_id = get_subquestion_id(question_list) partial_row = [ 'SQ', 0, subquestion_id, '', name, '', 'en', ] full_row = partial_row + common.get_missing(partial_row, total) subquestion_rows.append(full_row) return subquestion_rows
def get_answer_rows(formset, total): answer_set = get_answers_set(formset) answer_rows = [] for i, (name, label) in enumerate(answer_set, start=1): partial_row = [ 'SQ', 1, name, i, label, '', 'en', '' ] full_row = partial_row + common.get_missing(partial_row, total) answer_rows.append(full_row) return answer_rows
def get_question_row(formset, total): field_name = common.get_matrix_value(formset.matrix_id) partial_question = [ 'Q', 'F ', field_name, 1, formset.question, '', 'en', '', common.get_mandatory(formset), '', ] full_question = partial_question + common.get_missing(partial_question, total) full_question.append(formset.get_dependencies()) return full_question
def get_local_settings_rows(total, form_tree): """Generates locale specific settings.""" language = form_tree.language.lower() dynamic_settings = extract_locale_settings(form_tree.tree) setting_list = get_settings_for_locale(language) settings_rows = [] for row in setting_list: # Add missing columns to the settings: full_row = list(row) + common.get_missing(row, total) name = full_row[2] # Update language: full_row[6] = language # Update setting value, if specified: if name in dynamic_settings: full_row[4] = dynamic_settings[name] # Add row to the final list of settings: settings_rows.append(full_row) return settings_rows
def get_question_row(formset, total): field_name = common.get_name(formset.field_list[0]['input']['name']) partial_question = [ 'Q', 'L', field_name, 1, formset.question, formset.help_text, 'en', '', common.get_mandatory(formset), '', ] full_row = partial_question + common.get_missing(partial_question, total) # Add metadata: full_row.append(formset.get_dependencies()) return full_row
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 get_answer_row(field, total): row_value = common.get_value(field['input']['value']) partial_row = [ 'A', 0, row_value, '', field['label'], '', 'en', '', '', '', ] full_row = partial_row + common.get_missing(partial_row, total) # Add row metadata: metadata = { 'field_id': field['input'].get('id'), } full_row.append(metadata) 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 get_answer_rows(formset, total): answer_set, answer_metadata = get_answers_set(formset) answer_rows = [] for i, bundle in enumerate(answer_set, start=1): name, label = bundle partial_row = [ 'A', 0, name, i, label, '', 'en', '', '', '', ] full_row = partial_row + common.get_missing(partial_row, total) metadata = { 'field_id': answer_metadata[bundle], } full_row.append(metadata) answer_rows.append(full_row) return answer_rows
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]