From 50b18813c4ead11777f53b426bc2b4a77fa4c0cc Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 27 Sep 2023 15:51:38 +0545 Subject: [PATCH] Add multiple choice for QberMeta in Questionnaire --- apps/questionnaire/enums.py | 6 ++-- ...e_questionnaire_priority_level_and_more.py | 33 +++++++++++++++++++ apps/questionnaire/models.py | 22 +++++++++++++ apps/questionnaire/serializers.py | 6 ++-- apps/questionnaire/types.py | 13 ++++---- schema.graphql | 24 +++++++------- 6 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 apps/questionnaire/migrations/0003_remove_questionnaire_priority_level_and_more.py diff --git a/apps/questionnaire/enums.py b/apps/questionnaire/enums.py index 18e32d6..11bd924 100644 --- a/apps/questionnaire/enums.py +++ b/apps/questionnaire/enums.py @@ -26,9 +26,9 @@ get_enum_name_from_django_field(field): enum for field, enum in ( # Questionnaire - (Questionnaire.priority_level, QberPriorityLevelTypeEnum), - (Questionnaire.enumerator_skill, QberEnumeratorSkillTypeEnum), - (Questionnaire.data_collection_method, QberDataCollectionMethodTypeEnum), + (Questionnaire.priority_levels, QberPriorityLevelTypeEnum), + (Questionnaire.enumerator_skills, QberEnumeratorSkillTypeEnum), + (Questionnaire.data_collection_methods, QberDataCollectionMethodTypeEnum), # Question (Question.type, QuestionTypeEnum), (Question.priority_level, QberPriorityLevelTypeEnum), diff --git a/apps/questionnaire/migrations/0003_remove_questionnaire_priority_level_and_more.py b/apps/questionnaire/migrations/0003_remove_questionnaire_priority_level_and_more.py new file mode 100644 index 0000000..0f2f2b2 --- /dev/null +++ b/apps/questionnaire/migrations/0003_remove_questionnaire_priority_level_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.5 on 2023-09-27 10:05 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('questionnaire', '0002_alter_questionleafgroup_category_1_and_more'), + ] + + operations = [ + migrations.RemoveField( + model_name='questionnaire', + name='priority_level', + ), + migrations.AddField( + model_name='questionnaire', + name='data_collection_methods', + field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'Direct observation'), (2, 'Focus group'), (3, '1-on-1 interviews'), (4, 'Open-ended survey'), (5, 'Closed-ended survey'), (6, 'Key Informant Interview'), (7, 'Automatic')]), blank=True, default=list, size=None), + ), + migrations.AddField( + model_name='questionnaire', + name='enumerator_skills', + field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'Basic'), (2, 'Intermediate'), (3, 'Advanced')]), blank=True, default=list, size=None), + ), + migrations.AddField( + model_name='questionnaire', + name='priority_levels', + field=django.contrib.postgres.fields.ArrayField(base_field=models.PositiveSmallIntegerField(choices=[(1, 'High'), (2, 'Medium'), (3, 'Low')]), blank=True, default=list, size=None), + ), + ] diff --git a/apps/questionnaire/models.py b/apps/questionnaire/models.py index 6625488..7214186 100644 --- a/apps/questionnaire/models.py +++ b/apps/questionnaire/models.py @@ -1,5 +1,6 @@ import typing from django.db import models +from django.contrib.postgres.fields import ArrayField from utils.common import get_queryset_for_model from apps.user.models import User @@ -33,6 +34,27 @@ class Questionnaire(QberMetaData, UserResource): related_name='+', ) + # QberMetaData + priority_level = None + enumerator_skills = None + data_collection_methods = None + # -- Multiple + priority_levels = ArrayField( + models.PositiveSmallIntegerField(choices=QberMetaData.PriorityLevel.choices), + blank=True, + default=list, + ) + enumerator_skills = ArrayField( + models.PositiveSmallIntegerField(choices=QberMetaData.EnumeratorSkill.choices), + blank=True, + default=list, + ) + data_collection_methods = ArrayField( + models.PositiveSmallIntegerField(choices=QberMetaData.DataCollectionMethod.choices), + blank=True, + default=list, + ) + project_id: int qbank_id: int question_set: models.QuerySet['Question'] diff --git a/apps/questionnaire/serializers.py b/apps/questionnaire/serializers.py index 7d556e4..8d7e8f3 100644 --- a/apps/questionnaire/serializers.py +++ b/apps/questionnaire/serializers.py @@ -24,9 +24,9 @@ class Meta: fields = ( 'title', # Qber Metadata - 'priority_level', - 'enumerator_skill', - 'data_collection_method', + 'priority_levels', + 'enumerator_skills', + 'data_collection_methods', 'required_duration', ) diff --git a/apps/questionnaire/types.py b/apps/questionnaire/types.py index 682e51f..deb2b00 100644 --- a/apps/questionnaire/types.py +++ b/apps/questionnaire/types.py @@ -71,12 +71,13 @@ class QuestionnaireType(UserResourceTypeMixin): id: strawberry.ID title: strawberry.auto # Qber Metadata - priority_level = enum_field(Questionnaire.priority_level) - priority_level_display = enum_display_field(Questionnaire.priority_level) - enumerator_skill = enum_field(Questionnaire.enumerator_skill) - enumerator_skill_display = enum_display_field(Questionnaire.enumerator_skill) - data_collection_method = enum_field(Questionnaire.data_collection_method) - data_collection_method_display = enum_display_field(Questionnaire.data_collection_method) + priority_levels = enum_field(Questionnaire.priority_levels) + priority_levels_display = enum_display_field(Questionnaire.priority_levels) + enumerator_skills = enum_field(Questionnaire.enumerator_skills) + enumerator_skills_display = enum_display_field(Questionnaire.enumerator_skills) + data_collection_methods = enum_field(Questionnaire.data_collection_methods) + data_collection_methods_display = enum_display_field(Questionnaire.data_collection_methods) + required_duration: strawberry.auto @staticmethod diff --git a/schema.graphql b/schema.graphql index 007ea8b..f0811e0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -986,9 +986,9 @@ input QuestionUpdateInput { input QuestionnaireCreateInput { title: String! - priorityLevel: QberMetaDataPriorityLevelTypeEnum - enumeratorSkill: QberEnumeratorSkillTypeEnum - dataCollectionMethod: QberDataCollectionMethodTypeEnum + priorityLevels: [QberMetaDataPriorityLevelTypeEnum!] + enumeratorSkills: [QberEnumeratorSkillTypeEnum!] + dataCollectionMethods: [QberDataCollectionMethodTypeEnum!] requiredDuration: Int } @@ -1062,14 +1062,14 @@ type QuestionnaireType { requiredDuration: Int choiceCollections: [QuestionChoiceCollectionType!]! createdBy: UserType! - dataCollectionMethod: QberDataCollectionMethodTypeEnum - dataCollectionMethodDisplay: String - enumeratorSkill: QberEnumeratorSkillTypeEnum - enumeratorSkillDisplay: String + dataCollectionMethods: [QberDataCollectionMethodTypeEnum!]! + dataCollectionMethodsDisplay: [String!]! + enumeratorSkills: [QberEnumeratorSkillTypeEnum!]! + enumeratorSkillsDisplay: [String!]! leafGroups: [QuestionLeafGroupType!]! modifiedBy: UserType! - priorityLevel: QberMetaDataPriorityLevelTypeEnum - priorityLevelDisplay: String + priorityLevels: [QberMetaDataPriorityLevelTypeEnum!]! + priorityLevelsDisplay: [String!]! projectId: ID! qbank: QuestionBankType! totalQuestions: QuestionCount! @@ -1090,9 +1090,9 @@ type QuestionnaireTypeMutationResponseType { input QuestionnaireUpdateInput { title: String - priorityLevel: QberMetaDataPriorityLevelTypeEnum - enumeratorSkill: QberEnumeratorSkillTypeEnum - dataCollectionMethod: QberDataCollectionMethodTypeEnum + priorityLevels: [QberMetaDataPriorityLevelTypeEnum!] + enumeratorSkills: [QberEnumeratorSkillTypeEnum!] + dataCollectionMethods: [QberDataCollectionMethodTypeEnum!] requiredDuration: Int }