80 """ |
80 """ |
81 |
81 |
82 def __init__(self, *args, **kwargs): |
82 def __init__(self, *args, **kwargs): |
83 """Store special kwargs as attributes. |
83 """Store special kwargs as attributes. |
84 |
84 |
|
85 params: |
85 survey_content: a SuveryContent entity. |
86 survey_content: a SuveryContent entity. |
86 survey_logic: instance of SurveyLogic. |
87 survey_logic: instance of SurveyLogic. |
87 survey_record: a SurveyRecord entity. |
88 survey_record: a SurveyRecord entity. |
88 read_only: controls whether the survey taking UI allows data entry. |
89 read_only: controls whether the survey taking UI allows data entry. |
89 """ |
90 """ |
317 schema: schema for survey |
318 schema: schema for survey |
318 req: required bool |
319 req: required bool |
319 label: label for field |
320 label: label for field |
320 tip: tooltip text for field |
321 tip: tooltip text for field |
321 comment: initial comment value for field |
322 comment: initial comment value for field |
322 |
|
323 """ |
323 """ |
324 |
324 |
325 widget = PickManyCheckbox(attrs) |
325 widget = PickManyCheckbox(attrs) |
326 |
326 |
327 # TODO(ajaksu) need to allow checking checkboxes by default |
327 # TODO(ajaksu) need to allow checking checkboxes by default |
350 schema: schema for survey |
350 schema: schema for survey |
351 req: required bool |
351 req: required bool |
352 label: label for field |
352 label: label for field |
353 tip: tooltip text for field |
353 tip: tooltip text for field |
354 comment: initial comment value for field |
354 comment: initial comment value for field |
355 |
|
356 """ |
355 """ |
357 |
356 |
358 widget = PickQuantRadio(attrs) |
357 widget = PickQuantRadio(attrs) |
359 |
358 |
360 if self.survey_record: |
359 if self.survey_record: |
370 choices=tuple(these_choices), widget=widget, |
369 choices=tuple(these_choices), widget=widget, |
371 initial=value) |
370 initial=value) |
372 self.survey_fields[field] = question |
371 self.survey_fields[field] = question |
373 |
372 |
374 def addCommentField(self, field, comment, attrs, tip): |
373 def addCommentField(self, field, comment, attrs, tip): |
|
374 """Add comment field to a question. |
|
375 |
|
376 params: |
|
377 field: the name of the field to add the comment field to |
|
378 comment: the initial value of this field. |
|
379 attrs: the attrs for the widget |
|
380 tip: tooltip text for this field |
|
381 """ |
375 widget = widgets.Textarea(attrs=attrs) |
382 widget = widgets.Textarea(attrs=attrs) |
376 comment_field = CharField(help_text=tip, required=False, label='Comments', |
383 comment_field = CharField(help_text=tip, required=False, label='Comments', |
377 widget=widget, initial=comment) |
384 widget=widget, initial=comment) |
378 self.survey_fields[COMMENT_PREFIX + field] = comment_field |
385 self.survey_fields[COMMENT_PREFIX + field] = comment_field |
379 |
386 |
380 |
387 |
381 class Meta(object): |
388 class Meta(object): |
382 model = SurveyContent |
389 model = SurveyContent |
395 """ |
402 """ |
396 |
403 |
397 def __init__(self, *args, **kwargs): |
404 def __init__(self, *args, **kwargs): |
398 """Store special kwargs as attributes. |
405 """Store special kwargs as attributes. |
399 |
406 |
|
407 params: |
400 survey_content: a SurveyContent entity. |
408 survey_content: a SurveyContent entity. |
401 survey_logic: an instance of SurveyLogic. |
409 survey_logic: an instance of SurveyLogic. |
402 """ |
410 """ |
403 |
411 |
404 self.kwargs = kwargs |
412 self.kwargs = kwargs |
437 |
445 |
438 tip = 'Please provide an answer to this question.' |
446 tip = 'Please provide an answer to this question.' |
439 kwargs = schema.getEditFieldArgs(field, value, tip, label) |
447 kwargs = schema.getEditFieldArgs(field, value, tip, label) |
440 |
448 |
441 kwargs['widget'] = schema.getEditWidget(field, extra_attrs) |
449 kwargs['widget'] = schema.getEditWidget(field, extra_attrs) |
442 |
|
443 |
450 |
444 # add new field |
451 # add new field |
445 self.survey_fields[field] = schema.getEditField(field)(**kwargs) |
452 self.survey_fields[field] = schema.getEditField(field)(**kwargs) |
446 |
453 |
447 # TODO(ajaksu): find a new way to keep fields in order |
454 # TODO(ajaksu): find a new way to keep fields in order |
610 self.kind = kind |
617 self.kind = kind |
611 self.render_as = render |
618 self.render_as = render |
612 self.is_required = is_required |
619 self.is_required = is_required |
613 self.has_comment = has_comment |
620 self.has_comment = has_comment |
614 |
621 |
615 |
|
616 def render(self, name, value, attrs=None, choices=()): |
622 def render(self, name, value, attrs=None, choices=()): |
617 """Render UCE widget. |
623 """Render UCE widget. |
618 |
624 |
619 Option reordering, editing, addition and deletion are added here. |
625 Option reordering, editing, addition and deletion are added here. |
620 """ |
626 """ |
689 """Initialize widget and store editing mode. |
695 """Initialize widget and store editing mode. |
690 |
696 |
691 params: |
697 params: |
692 is_required: bool, controls selection in the 'required' extra field |
698 is_required: bool, controls selection in the 'required' extra field |
693 has_comments: bool, controls selection in the 'has_comment' extra field |
699 has_comments: bool, controls selection in the 'has_comment' extra field |
694 editing: bool, controls rendering as plain textarea or with extra fields |
|
695 """ |
700 """ |
696 |
701 |
697 self.is_required = is_required |
702 self.is_required = is_required |
698 self.has_comment = has_comment |
703 self.has_comment = has_comment |
699 |
704 |
727 """Initialize widget and store editing mode. |
732 """Initialize widget and store editing mode. |
728 |
733 |
729 params: |
734 params: |
730 is_required: bool, controls selection in the 'required' extra field |
735 is_required: bool, controls selection in the 'required' extra field |
731 has_comments: bool, controls selection in the 'has_comment' extra field |
736 has_comments: bool, controls selection in the 'has_comment' extra field |
732 editing: bool, controls rendering as plain text input or with extra fields |
|
733 """ |
737 """ |
734 |
738 |
735 self.is_required = is_required |
739 self.is_required = is_required |
736 self.has_comment = has_comment |
740 self.has_comment = has_comment |
737 |
741 |