def _table_headers(questions): """ Return the header labels for a set of questions as a list of strings. This will create separate columns for each multiple-choice possiblity and freeform options, to avoid mixing data types and make charting easier. """ ql = list(questions) ql.sort(lambda x, y: numal_sort(x.number, y.number)) columns = [] for q in ql: if q.type == 'choice-yesnocomment': columns.extend([q.number, q.number + "-freeform"]) elif q.type == 'choice-freeform': columns.extend([q.number, q.number + "-freeform"]) elif q.type.startswith('choice-multiple'): cl = [c.value for c in q.choice_set.all()] cl.sort(numal_sort) columns.extend([q.number + '-' + value for value in cl]) if q.type == 'choice-multiple-freeform': columns.append(q.number + '-freeform') else: columns.append(q.number) return columns
def _table_headers(questions): """ Return the header labels for a set of questions as a list of strings. This will create separate columns for each multiple-choice possiblity and freeform options, to avoid mixing data types and make charting easier. """ ql = list(questions) ql.sort(lambda x, y: numal_sort(x.number, y.number)) columns = [] for q in ql: if q.type == 'choice-yesnocomment': columns.extend([q.number, q.number + "-freeform"]) elif q.type == 'choice-freeform': columns.extend([q.number, q.number + "-freeform"]) elif q.type.startswith('choice-multiple'): cl = [c.value for c in q.choice_set.all()] cl.sort(numal_sort) columns.extend([q.number + '-' + value for value in cl]) if q.type == 'choice-multiple-freeform': columns.append(q.number + '-freeform') else: columns.append(q.number) return columns