app/soc/views/helper/surveys.py
changeset 2798 ec1857f0d0c7
parent 2683 8ea17736a10d
child 3069 1b9c554ca96d
equal deleted inserted replaced
2797:236e5b192295 2798:ec1857f0d0c7
    43 
    43 
    44 from soc.logic import dicts
    44 from soc.logic import dicts
    45 from soc.logic.lists import Lists
    45 from soc.logic.lists import Lists
    46 from soc.models.survey import COMMENT_PREFIX
    46 from soc.models.survey import COMMENT_PREFIX
    47 from soc.models.survey import SurveyContent
    47 from soc.models.survey import SurveyContent
       
    48 from soc.views.helper import widgets as custom_widgets
    48 
    49 
    49 
    50 
    50 CHOICE_TYPES = set(('selection', 'pick_multi', 'choice', 'pick_quant'))
    51 CHOICE_TYPES = set(('selection', 'pick_multi', 'choice', 'pick_quant'))
    51 
    52 
    52 # TODO(ajaksu) add this to template
    53 # TODO(ajaksu) add this to template
    94     self.kwargs = kwargs
    95     self.kwargs = kwargs
    95 
    96 
    96     self.survey_content = self.kwargs.pop('survey_content', None)
    97     self.survey_content = self.kwargs.pop('survey_content', None)
    97     self.survey_logic = self.kwargs.pop('survey_logic', None)
    98     self.survey_logic = self.kwargs.pop('survey_logic', None)
    98     self.survey_record = self.kwargs.pop('survey_record', None)
    99     self.survey_record = self.kwargs.pop('survey_record', None)
       
   100     # TODO: This should be removed since readonly is covered by the RecordForm
    99     self.read_only = self.kwargs.pop('read_only', None)
   101     self.read_only = self.kwargs.pop('read_only', None)
   100 
   102 
   101     self.fields_map = dict(
   103     self.fields_map = dict(
   102         long_answer=self.addLongField,
   104         long_answer=self.addLongField,
   103         short_answer=self.addShortField,
   105         short_answer=self.addShortField,
   453   class Meta(object):
   455   class Meta(object):
   454     model = SurveyContent
   456     model = SurveyContent
   455     exclude = ['schema']
   457     exclude = ['schema']
   456 
   458 
   457 
   459 
       
   460 class SurveyRecordForm(SurveyTakeForm):
       
   461   """SurveyContent form for showing record of survey answers.
       
   462   """
       
   463 
       
   464   def addLongField(self, field, value, attrs, schema, **kwargs):
       
   465     """Add plain text long answer fields to this form.
       
   466 
       
   467     params:
       
   468       field: the current field
       
   469       value: the initial value for this field
       
   470       attrs: additional attributes for field
       
   471       schema: schema for survey
       
   472     """
       
   473 
       
   474     question = CharField(widget=custom_widgets.PlainTextWidget, initial=value)
       
   475     self.survey_fields[field] = question
       
   476 
       
   477   def addShortField(self, field, value, attrs, schema, **kwargs):
       
   478     """Add plain text short answer fields to this form.
       
   479 
       
   480     params:
       
   481       field: the current field
       
   482       value: the initial value for this field
       
   483       attrs: additional attributes for field
       
   484       schema: schema for survey
       
   485     """
       
   486 
       
   487     question = CharField(widget=custom_widgets.PlainTextWidget, initial=value)
       
   488     self.survey_fields[field] = question
       
   489 
       
   490   def addCommentField(self, field, comment, attrs, tip):
       
   491     """Add plain text comment field to a question.
       
   492 
       
   493     params:
       
   494       field: the name of the field to add the comment field to
       
   495       comment: the initial value of this field.
       
   496       attrs: the attrs for the widget
       
   497       tip: tooltip text for this field
       
   498     """
       
   499 
       
   500     widget = custom_widgets.PlainTextWidget
       
   501     comment_field = CharField(label='Comment', widget=widget, initial=comment)
       
   502     self.survey_fields[COMMENT_PREFIX + field] = comment_field
       
   503 
       
   504 
   458 class SurveyEditForm(djangoforms.ModelForm):
   505 class SurveyEditForm(djangoforms.ModelForm):
   459   """SurveyContent form for editing a survey.
   506   """SurveyContent form for editing a survey.
   460 
   507 
   461   This class is used to produce survey forms for several circumstances:
   508   This class is used to produce survey forms for several circumstances:
   462     - Admin creating survey from scratch
   509     - Admin creating survey from scratch