def constructForm(self): """Constructs the form based on the schema stored in the survey content """ # insert dynamic survey fields if self.survey: survey_schema = surveys.SurveySchema(self.survey) for field in survey_schema: self.constructField(field)
def __init__(self, instance=None): """Constructor to initialize the model instance. The readonly template will be rendered for the data in this model instance. """ self.instance = instance self.schema = None if self.instance: self.schema = surveys.SurveySchema(self.instance.survey)
def fields(): schema = surveys.SurveySchema(survey) if survey else None if schema: for question in schema: label = question.getLabel() property_name = question.getPropertyName() value = getattr(survey_response, property_name, NOT_ANSWERED_VALUE) if isinstance(value, list): value = ', '.join(value) yield label, value
def addColumnsForSurvey(list_config, survey): """Adds text columns corresponding to questions in the specified survey to the specified list configuration. Args: list_config: lists.ListConfiguration object. survey: Survey entity for which columns are to be added. """ schema = surveys.SurveySchema(survey) for field in schema: label = field.getLabel() field_id = field.getFieldName() list_config.addPlainTextColumn(field_id, label, _field_or_empty(field_id), hidden=True)
def getSurveyResponseProperties(self): """Returns answers to the survey questions that were submitted in this form. Returns: A dict mapping question identifiers to corresponding responses. """ # list of field IDs that belong to the organization application field_ids = [field.field_id for field in surveys.SurveySchema(self.survey)] properties = {} for field_id, value in self.cleaned_data.iteritems(): if field_id in field_ids: properties[field_id] = value # add possible value of 'other' option other_option_field_id = OTHER_OPTION_FIELD_ID % field_id if other_option_field_id in self.cleaned_data: properties[other_option_field_id] = self.cleaned_data[ other_option_field_id] return properties
def __init__(self, data, survey, record_model, idx=0, description=''): """Creates a new SurveyRecordList template. Args: data: The RequestData object to use. survey: The Survey to show the records for record_model: The Model class of the Record entities. idx: The index of the list to use. description: The (optional) description of the list. """ super(SurveyRecordList, self).__init__(data) self.survey = survey self.record_model = record_model self.idx = idx self.description = description # Create the configuration based on the schema of the survey list_config = lists.ListConfiguration() schema = surveys.SurveySchema(survey) for field in schema: label = field.getLabel() field_id = field.getFieldName() list_config.addPlainTextColumn(field_id, label, field_or_empty(field_id), hidden=True) list_config.addSimpleColumn('created', 'Created On', column_type=lists.DATE) list_config.addSimpleColumn('modified', 'Last Modified On', column_type=lists.DATE) self.list_config = list_config