From 66af6d5397b115bb7db361e8c89b4657b1432afb Mon Sep 17 00:00:00 2001 From: thenav56 Date: Wed, 27 Sep 2023 17:42:57 +0545 Subject: [PATCH] QuestionBank attach in Questionnaire bug fix --- apps/qbank/base_models.py | 2 +- .../0004_alter_qbleafgroup_category_1_and_more.py | 2 +- ...0002_alter_questionleafgroup_category_1_and_more.py | 2 +- apps/questionnaire/serializers.py | 10 ++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/qbank/base_models.py b/apps/qbank/base_models.py index 861ed69..38f744b 100644 --- a/apps/qbank/base_models.py +++ b/apps/qbank/base_models.py @@ -74,7 +74,7 @@ class Category2(models.IntegerChoices): LOCAL_INTEGRATION = 10307, 'Local integration' # -- CASUALTIES # -- -- CONTEXT - INTRODUCTION - CROSS = 10401, 'Dead' + CROSS = 10401, 'Cross' DEAD = 10402, 'Dead' INJURED = 10403, 'Injured' MISSING = 10404, 'Missing' diff --git a/apps/qbank/migrations/0004_alter_qbleafgroup_category_1_and_more.py b/apps/qbank/migrations/0004_alter_qbleafgroup_category_1_and_more.py index baf41cb..3edd30e 100644 --- a/apps/qbank/migrations/0004_alter_qbleafgroup_category_1_and_more.py +++ b/apps/qbank/migrations/0004_alter_qbleafgroup_category_1_and_more.py @@ -18,7 +18,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='qbleafgroup', name='category_2', - field=models.PositiveSmallIntegerField(choices=[(10101, 'Introduction'), (10102, 'Politics'), (10103, 'Economics'), (10104, 'Environment'), (10105, 'Socio-cultural'), (10106, 'Demographics'), (10107, 'Security and stability'), (10201, 'Type and characteristics'), (10202, 'Aggravating factors'), (10203, 'Mitigating factors'), (10204, 'Threats and hazards'), (10301, 'Introduction people arriving'), (10302, 'Introduction people leaving'), (10304, 'Pull factors'), (10305, 'Push factors'), (10306, 'Intentions'), (10307, 'Local integration'), (10401, 'Dead'), (10402, 'Dead'), (10403, 'Injured'), (10404, 'Missing'), (10501, 'Communication sources and means'), (10502, 'Challenges and barriers'), (10503, 'Knowledge and information gaps (population)'), (10504, 'Knowledge and information gaps (humanitarians)'), (10601, 'Introduction humanitarian actors barriers'), (10602, 'Introduction people affected barriers'), (10603, 'Population to relief'), (10604, 'Relief to population'), (10605, 'Physical and security constraints'), (10606, 'People facing humanitarian access constraints/Humanitarian access gaps'), (10701, 'Questionnaire characteristics'), (10702, 'Enumerator characteristics'), (10703, 'Respondent characteristics'), (10704, 'Area characteristics'), (10705, 'Affected group characteristics'), (10901, 'Food'), (10902, 'Wash'), (10903, 'Shelter and domestic items'), (20101, 'Drivers'), (20102, 'Impact on people'), (20103, 'Impact on systems, services and networks'), (20104, 'Number of people affected'), (20201, 'Living standards'), (20202, 'Coping mechanisms'), (20203, 'Physical and mental well being'), (20204, 'Number of people in need'), (20301, 'People at risk'), (20302, 'Number of people at risk'), (20401, 'Priority needs'), (20402, 'Priority interventions'), (20501, 'Government and local authorities'), (20502, 'International organizations'), (20503, 'National and local organizations'), (20504, 'Red cross Red Crescent'), (20505, 'Humanitarian coordination'), (20506, 'People reached and response gaps')]), + field=models.PositiveSmallIntegerField(choices=[(10101, 'Introduction'), (10102, 'Politics'), (10103, 'Economics'), (10104, 'Environment'), (10105, 'Socio-cultural'), (10106, 'Demographics'), (10107, 'Security and stability'), (10201, 'Type and characteristics'), (10202, 'Aggravating factors'), (10203, 'Mitigating factors'), (10204, 'Threats and hazards'), (10301, 'Introduction people arriving'), (10302, 'Introduction people leaving'), (10304, 'Pull factors'), (10305, 'Push factors'), (10306, 'Intentions'), (10307, 'Local integration'), (10401, 'Cross'), (10402, 'Dead'), (10403, 'Injured'), (10404, 'Missing'), (10501, 'Communication sources and means'), (10502, 'Challenges and barriers'), (10503, 'Knowledge and information gaps (population)'), (10504, 'Knowledge and information gaps (humanitarians)'), (10601, 'Introduction humanitarian actors barriers'), (10602, 'Introduction people affected barriers'), (10603, 'Population to relief'), (10604, 'Relief to population'), (10605, 'Physical and security constraints'), (10606, 'People facing humanitarian access constraints/Humanitarian access gaps'), (10701, 'Questionnaire characteristics'), (10702, 'Enumerator characteristics'), (10703, 'Respondent characteristics'), (10704, 'Area characteristics'), (10705, 'Affected group characteristics'), (10901, 'Food'), (10902, 'Wash'), (10903, 'Shelter and domestic items'), (20101, 'Drivers'), (20102, 'Impact on people'), (20103, 'Impact on systems, services and networks'), (20104, 'Number of people affected'), (20201, 'Living standards'), (20202, 'Coping mechanisms'), (20203, 'Physical and mental well being'), (20204, 'Number of people in need'), (20301, 'People at risk'), (20302, 'Number of people at risk'), (20401, 'Priority needs'), (20402, 'Priority interventions'), (20501, 'Government and local authorities'), (20502, 'International organizations'), (20503, 'National and local organizations'), (20504, 'Red cross Red Crescent'), (20505, 'Humanitarian coordination'), (20506, 'People reached and response gaps')]), ), migrations.AlterField( model_name='qbleafgroup', diff --git a/apps/questionnaire/migrations/0002_alter_questionleafgroup_category_1_and_more.py b/apps/questionnaire/migrations/0002_alter_questionleafgroup_category_1_and_more.py index f0d6ece..53fd514 100644 --- a/apps/questionnaire/migrations/0002_alter_questionleafgroup_category_1_and_more.py +++ b/apps/questionnaire/migrations/0002_alter_questionleafgroup_category_1_and_more.py @@ -18,7 +18,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='questionleafgroup', name='category_2', - field=models.PositiveSmallIntegerField(choices=[(10101, 'Introduction'), (10102, 'Politics'), (10103, 'Economics'), (10104, 'Environment'), (10105, 'Socio-cultural'), (10106, 'Demographics'), (10107, 'Security and stability'), (10201, 'Type and characteristics'), (10202, 'Aggravating factors'), (10203, 'Mitigating factors'), (10204, 'Threats and hazards'), (10301, 'Introduction people arriving'), (10302, 'Introduction people leaving'), (10304, 'Pull factors'), (10305, 'Push factors'), (10306, 'Intentions'), (10307, 'Local integration'), (10401, 'Dead'), (10402, 'Dead'), (10403, 'Injured'), (10404, 'Missing'), (10501, 'Communication sources and means'), (10502, 'Challenges and barriers'), (10503, 'Knowledge and information gaps (population)'), (10504, 'Knowledge and information gaps (humanitarians)'), (10601, 'Introduction humanitarian actors barriers'), (10602, 'Introduction people affected barriers'), (10603, 'Population to relief'), (10604, 'Relief to population'), (10605, 'Physical and security constraints'), (10606, 'People facing humanitarian access constraints/Humanitarian access gaps'), (10701, 'Questionnaire characteristics'), (10702, 'Enumerator characteristics'), (10703, 'Respondent characteristics'), (10704, 'Area characteristics'), (10705, 'Affected group characteristics'), (10901, 'Food'), (10902, 'Wash'), (10903, 'Shelter and domestic items'), (20101, 'Drivers'), (20102, 'Impact on people'), (20103, 'Impact on systems, services and networks'), (20104, 'Number of people affected'), (20201, 'Living standards'), (20202, 'Coping mechanisms'), (20203, 'Physical and mental well being'), (20204, 'Number of people in need'), (20301, 'People at risk'), (20302, 'Number of people at risk'), (20401, 'Priority needs'), (20402, 'Priority interventions'), (20501, 'Government and local authorities'), (20502, 'International organizations'), (20503, 'National and local organizations'), (20504, 'Red cross Red Crescent'), (20505, 'Humanitarian coordination'), (20506, 'People reached and response gaps')]), + field=models.PositiveSmallIntegerField(choices=[(10101, 'Introduction'), (10102, 'Politics'), (10103, 'Economics'), (10104, 'Environment'), (10105, 'Socio-cultural'), (10106, 'Demographics'), (10107, 'Security and stability'), (10201, 'Type and characteristics'), (10202, 'Aggravating factors'), (10203, 'Mitigating factors'), (10204, 'Threats and hazards'), (10301, 'Introduction people arriving'), (10302, 'Introduction people leaving'), (10304, 'Pull factors'), (10305, 'Push factors'), (10306, 'Intentions'), (10307, 'Local integration'), (10401, 'Cross'), (10402, 'Dead'), (10403, 'Injured'), (10404, 'Missing'), (10501, 'Communication sources and means'), (10502, 'Challenges and barriers'), (10503, 'Knowledge and information gaps (population)'), (10504, 'Knowledge and information gaps (humanitarians)'), (10601, 'Introduction humanitarian actors barriers'), (10602, 'Introduction people affected barriers'), (10603, 'Population to relief'), (10604, 'Relief to population'), (10605, 'Physical and security constraints'), (10606, 'People facing humanitarian access constraints/Humanitarian access gaps'), (10701, 'Questionnaire characteristics'), (10702, 'Enumerator characteristics'), (10703, 'Respondent characteristics'), (10704, 'Area characteristics'), (10705, 'Affected group characteristics'), (10901, 'Food'), (10902, 'Wash'), (10903, 'Shelter and domestic items'), (20101, 'Drivers'), (20102, 'Impact on people'), (20103, 'Impact on systems, services and networks'), (20104, 'Number of people affected'), (20201, 'Living standards'), (20202, 'Coping mechanisms'), (20203, 'Physical and mental well being'), (20204, 'Number of people in need'), (20301, 'People at risk'), (20302, 'Number of people at risk'), (20401, 'Priority needs'), (20402, 'Priority interventions'), (20501, 'Government and local authorities'), (20502, 'International organizations'), (20503, 'National and local organizations'), (20504, 'Red cross Red Crescent'), (20505, 'Humanitarian coordination'), (20506, 'People reached and response gaps')]), ), migrations.AlterField( model_name='questionleafgroup', diff --git a/apps/questionnaire/serializers.py b/apps/questionnaire/serializers.py index 8d7e8f3..85fc2c7 100644 --- a/apps/questionnaire/serializers.py +++ b/apps/questionnaire/serializers.py @@ -33,10 +33,12 @@ class Meta: instance: Questionnaire def validate(self, data): - qbank = QuestionBank.get_active() - if qbank is None: - raise serializers.ValidationError('No available Question Bank. Please ask admin to add one.') - data['qbank'] = qbank + # For Create. Attach latest QuestionBank + if self.instance is None: + qbank = QuestionBank.get_active() + if qbank is None: + raise serializers.ValidationError('No available Question Bank. Please ask admin to add one.') + data['qbank'] = qbank return data def create(self, data):