Esempio n. 1
0
    def _validate_dynamic_option(self, question, document, option, user):
        data_source = get_data_sources(dic=True)[question.data_source]
        data_source_object = data_source()

        valid_label = data_source_object.validate_answer_value(
            option, document, question, user)
        if valid_label is False:
            raise CustomValidationError(
                f'Invalid value "{option}". Not a valid option.',
                slugs=[question.slug])

        DynamicOption.objects.get_or_create(
            document=document,
            question=question,
            slug=option,
            defaults={
                "label": valid_label,
                "created_by_user": user.username,
                "created_by_group": user.group,
            },
        )
Esempio n. 2
0
 def _validate_data_source(data_source):
     data_sources = get_data_sources(dic=True)
     if data_source not in data_sources:
         raise exceptions.ValidationError(
             f'Invalid data_source: "{data_source}"')