[IMP] survey: descriptive text

bzr revid: chm@openerp.com-20130306081222-022psknm3tdthlgn
This commit is contained in:
Christophe Matthieu
2013-03-06 09:12:22 +01:00
parent db86fd55ff
commit b401d634c3
4 changed files with 69 additions and 59 deletions
+7
View File
@@ -67,4 +67,11 @@
border-width: 1px 1px 0 0;
text-shadow: none;
text-decoration: none !important;
}
.openerp .oe_survey_answer label {
max-width: 260px;
white-space: normal !important;
font-weight: bold;
padding-right: 8px;
}
+16 -13
View File
@@ -347,22 +347,25 @@ class survey_question(osv.osv):
'sequence': fields.integer('Sequence'),
'tot_resp': fields.function(_calc_response, string="Total Answer"),
'survey': fields.related('page_id', 'survey_id', type='many2one', relation='survey', string='Survey'),
'descriptive_text': fields.text('Descriptive Text', translate=True),
'descriptive_text': fields.html('Descriptive Text', translate=True),
'column_heading_ids': fields.one2many('survey.question.column.heading', 'question_id', ' Column heading'),
'type': fields.selection([('multiple_choice_only_one_ans', 'Multiple Choice (Only One Answer)'),
('multiple_choice_multiple_ans', 'Multiple Choice (Multiple Answer)'),
('matrix_of_choices_only_one_ans', 'Matrix of Choices (Only One Answers Per Row)'),
('matrix_of_choices_only_multi_ans', 'Matrix of Choices (Multiple Answers Per Row)'),
('rating_scale', 'Rating Scale'), ('single_textbox', 'Single Textbox'),
('multiple_textboxes', 'Multiple Textboxes'),
('multiple_textboxes_diff_type', 'Multiple Textboxes With Different Type'),
('comment', 'Comment/Essay Box'),
('numerical_textboxes', 'Numerical Textboxes'), ('date', 'Date'),
('date_and_time', 'Date and Time'), ('descriptive_text', 'Descriptive Text'),
('table', 'Table'),
('multiple_choice_multiple_ans', 'Multiple Choice (Multiple Answer)'),
('matrix_of_choices_only_one_ans', 'Matrix of Choices (Only One Answers Per Row)'),
('matrix_of_choices_only_multi_ans', 'Matrix of Choices (Multiple Answers Per Row)'),
('rating_scale', 'Rating Scale'),
('single_textbox', 'Single Textbox'),
('multiple_textboxes', 'Multiple Textboxes'),
('multiple_textboxes_diff_type', 'Multiple Textboxes With Different Type'),
('comment', 'Comment/Essay Box'),
('numerical_textboxes', 'Numerical Textboxes'),
('date', 'Date'),
('date_and_time', 'Date and Time'),
('descriptive_text', 'Descriptive Text'),
('table', 'Table'),
], 'Question Type', required=1, ),
'is_comment_require': fields.boolean('Add Comment Field'),
'comment_label': fields.char('Field Label', size=255, translate=True),
'comment_label': fields.char('Field Label', translate=True),
'comment_field_type': fields.selection([('char', 'Single Line Of Text'), ('text', 'Paragraph of Text')], 'Comment Field Type'),
'comment_valid_type': fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''),
('must_be_specific_length', 'Must Be Specific Length'),
@@ -402,7 +405,7 @@ class survey_question(osv.osv):
'in_visible_menu_choice': fields.boolean('Is Menu Choice Invisible?'),
'in_visible_answer_type': fields.boolean('Is Answer Type Invisible?'),
'comment_column': fields.boolean('Add comment column in matrix'),
'column_name': fields.char('Column Name', size=256, translate=True),
'column_name': fields.char('Column Name', translate=True),
'no_of_rows': fields.integer('No of Rows'),
}
_defaults = {
+1 -5
View File
@@ -255,7 +255,6 @@
<field name="arch" type="xml">
<form string="Survey Pages">
<field name="title" colspan="4"/>
<field name="sequence"/>
<separator string="Description" colspan="4"/>
<field name="note" colspan="4" nolabel="1"/>
<group colspan="4">
@@ -276,6 +275,7 @@
<field name="arch" type="xml">
<form string="Survey Question">
<field name="question" colspan="4"/>
<field name="descriptive_text" colspan="4"/>
<field name="type" on_change="on_change_type(type)"/>
<field name="in_visible_rating_weight" invisible="1"/>
<field name="in_visible_menu_choice" invisible="1"/>
@@ -384,9 +384,6 @@
</group>
</group>
</group>
<group string="Descriptive Text" attrs="{'invisible':[('type','not in',['descriptive_text'])]}">
<field name="descriptive_text" colspan="4" nolabel="1"/>
</group>
</group>
</form>
</field>
@@ -461,7 +458,6 @@
<field name="arch" type="xml">
<form string="Survey Answer">
<field name="answer" colspan="4"/>
<field name="sequence"/>
<field name="in_visible_answer_type" invisible="1"/>
<group colspan="4" attrs="{'invisible':[('in_visible_answer_type','=',True)]}">
<field name="type" colspan="2"/>
+45 -41
View File
@@ -19,6 +19,7 @@
#
##############################################################################
import lxml
from lxml import etree
from openerp import tools
@@ -67,14 +68,14 @@ class survey_question_wiz(osv.osv_memory):
for ans in que_rec.answer_choice_ids:
selection.append((tools.ustr(ans.id), ans.answer))
xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'})
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_selection"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_selection"})
fields[tools.ustr(que.id) + "_selection"] = {'type': 'selection', 'selection': selection, 'string': "Answer"}
def _view_field_multiple_choice_multiple_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
# TODO convert selection field into radio input
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'boolean', 'string': ans.answer}
def _view_field_matrix_of_choices_only_multi_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
@@ -87,7 +88,7 @@ class survey_question_wiz(osv.osv_memory):
for row in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) + ': -', 'align': '0.0'})
for col in que_col_head.browse(cr, SUPERUSER_ID, [head.id for head in que_rec.column_heading_ids], context=context):
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel': "1"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel': "1"})
fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type': 'boolean', 'string': col.title}
def _view_field_multiple_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
@@ -101,59 +102,59 @@ class survey_question_wiz(osv.osv_memory):
elif que_rec.validation_type in ['must_be_date']:
type = "date"
for ans in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string': ans.answer}
def _view_field_numerical_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type': 'integer', 'string': ans.answer}
def _view_field_date(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'date', 'string': ans.answer}
def _view_field_date_and_time(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in que_rec.answer_choice_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'datetime', 'string': ans.answer}
def _view_field_descriptive_text(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
if que_rec.descriptive_text:
for que_test in que_rec.descriptive_text.split('\n'):
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align': "0.0"})
html = lxml.html.fromstring('<div class="oe_survey_descriptive_text">%s</div>' % que_rec.descriptive_text)
xml_group.insert(0, html)
def _view_field_single_textbox(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_single", 'nolabel': "1", 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_single", 'nolabel': "1", 'colspan': "4"})
fields[tools.ustr(que.id) + "_single"] = {'type': 'char', 'size': 255, 'string': "single_textbox", 'views': {}}
def _view_field_comment(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_comment", 'nolabel': "1", 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_comment", 'nolabel': "1", 'colspan': "4"})
fields[tools.ustr(que.id) + "_comment"] = {'type': 'text', 'string': "Comment/Eassy Box", 'views': {}}
def _view_field_table(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'})
for col in que_rec.column_heading_ids:
etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title), 'colspan': '1'})
etree.SubElement(xml_group, 'label', {'string': tools.ustr(col.title)})
for row in range(0, que_rec.no_of_rows):
for col in que_rec.column_heading_ids:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row), 'nolabel': "1"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row), 'nolabel': "1"})
fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row)] = {'type': 'char', 'size': 255, 'views': {}}
def _view_field_multiple_textboxes_diff_type(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in que_rec.answer_choice_ids:
if ans.type == "email":
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'size': 255, 'string': ans.answer}
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'widget': 'email', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'string': ans.answer}
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'widget': 'email', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
else:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
if ans.type == "char":
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'size': 255, 'string': ans.answer}
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'char', 'string': ans.answer}
elif ans.type in ['integer', 'float', 'date', 'datetime']:
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string': ans.answer}
else:
@@ -165,26 +166,29 @@ class survey_question_wiz(osv.osv_memory):
fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'selection', 'selection': selection, 'string': ans.answer}
def _view_field_matrix_of_choices_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
if que_rec.comment_column:
col = "4"
colspan = "4"
else:
col = "2"
colspan = "2"
xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)})
col = que_rec.comment_column and "3" or "2"
xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': "4"})
first = True
for row in que_rec.answer_choice_ids:
name_select = tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)
etree.SubElement(xml_group, 'newline')
etree.SubElement(xml_group, 'label', {'for': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id), 'string': to_xml(tools.ustr(row.answer))})
etree.SubElement(xml_group, 'field', {'widget': 'radio', 'horizontal': '1', 'no_radiolabel': not first and '1' or '0', 'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id), 'nolabel': "1"})
first = False
etree.SubElement(xml_group, 'label', {'for': name_select, 'string': tools.ustr(row.answer), 'class': 'oe_survey_matrix_of_choices_row'})
etree.SubElement(xml_group, 'field', {'widget': 'radio', 'horizontal': '1', 'no_radiolabel': not first and '1' or '0', 'modifiers': readonly, 'name': name_select, 'nolabel': "1"})
selection = []
for col in que_rec.column_heading_ids:
selection.append((str(col.id), col.title))
fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type': 'selection', 'selection': selection, 'string': "Answer"}
if que_rec.comment_column:
fields[tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"] = {'type': 'char', 'size': 255, 'string': tools.ustr(que_rec.column_name), 'views': {}}
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"})
name_comment = tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"
if first:
div_group = etree.SubElement(xml_group, 'div', {'class': 'oe_survey_matrix_of_choices_comment'})
etree.SubElement(div_group, 'label', {'string': tools.ustr(row.answer)})
etree.SubElement(div_group, 'newline')
etree.SubElement(div_group, 'field', {'modifiers': readonly, 'name': name_comment, 'nolabel': "1"})
else:
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': name_comment, 'nolabel': "1"})
fields[name_comment] = {'type': 'char', 'string': tools.ustr(que_rec.column_name), 'views': {}}
fields[name_select] = {'type': 'selection', 'selection': selection, 'string': "Answer"}
first = False
def _view_field_rating_scale(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec)
@@ -192,13 +196,13 @@ class survey_question_wiz(osv.osv_memory):
def _view_field_postprocessing(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None):
# after matrix of choices
if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char', 'text'] and que_rec.make_comment_field:
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_otherfield", 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_otherfield", 'colspan': "4"})
fields[tools.ustr(que.id) + "_otherfield"] = {'type': 'boolean', 'string': que_rec.comment_label, 'views': {}}
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"})
fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views': {}}
else:
etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)), 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly and '{"readonly": 1}' or '{}', 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"})
etree.SubElement(xml_group, 'field', {'modifiers': readonly, 'name': tools.ustr(que.id) + "_other", 'nolabel': "1", 'colspan': "4"})
fields[tools.ustr(que.id) + "_other"] = {'type': que_rec.comment_field_type, 'string': '', 'views': {}}
def _survey_complete(self, cr, uid, survey_id, context):
@@ -398,7 +402,7 @@ class survey_question_wiz(osv.osv_memory):
# survey in progress (not complete)
if flag:
pag_rec = page_obj.browse(cr, SUPERUSER_ID, p_id, context=context)
xml_form = etree.Element('form', {'version': "7.0", 'string': tools.ustr(pag_rec and pag_rec.title or survey_browse.title)})
xml_form = etree.Element('form', {'version': "7.0", 'class': 'oe_survey_answer', 'string': tools.ustr(pag_rec and pag_rec.title or survey_browse.title)})
xml_form = etree.SubElement(xml_form, 'sheet')
if edit_mode:
@@ -428,25 +432,25 @@ class survey_question_wiz(osv.osv_memory):
que_rec = que_obj.browse(cr, SUPERUSER_ID, que.id, context=context)
separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question)
star = que_rec.is_require_answer and '*' or ''
etree.SubElement(xml_form, 'separator', {'string': star + to_xml(separator_string)})
if edit_mode:
etree.SubElement(xml_form, 'separator', {'string': star + to_xml(separator_string)})
xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'})
context.update({'question_id': tools.ustr(que.id), 'page_number': sur_name_rec.page_no, 'transfer': sur_name_read.transfer, 'page_id': p_id})
etree.SubElement(xml_group1, 'button', {'string': '', 'icon': "gtk-edit", 'type': 'object', 'name': "action_edit_question", 'context': tools.ustr(context)})
etree.SubElement(xml_group1, 'button', {'string': '', 'icon': "gtk-delete", 'type': 'object', 'name': "action_delete_question", 'context': tools.ustr(context)})
else:
etree.SubElement(xml_form, 'newline')
etree.SubElement(xml_form, 'separator', {'string': star + to_xml(separator_string)})
xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'})
if que_rec.type not in ['descriptive_text']:
self._view_field_descriptive_text(cr, uid, xml_group, fields, '{"readonly": 1}', que, que_rec, context=context)
# rendering different views
getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, response_info['readonly'], que, que_rec, context=context)
readonly = response_info['readonly'] and '{"readonly": 1}' or '{}'
getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, readonly, que, que_rec, context=context)
if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'rating_scale'] and que_rec.is_comment_require:
self._view_field_postprocessing(cr, uid, xml_group, fields, response_info['readonly'], que, que_rec, context=context)
xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width': "100%"})
xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'width': "100%"})
if pre_button:
etree.SubElement(xml_footer, 'label', {'string': ""})