Skip to content

Commit

Permalink
Add id for all nested objects for update mutation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rup-Narayan-Rajbanshi committed Aug 3, 2023
1 parent 7a3a913 commit f5df4f6
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 77 deletions.
4 changes: 2 additions & 2 deletions apps/assessment_registry/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ScoreRating,
ScoreAnalyticalDensity,
Question,
SummaryFocusSubSectorIssue,
SummarySubDimmensionIssue,
)

AssessmentRegistryCrisisTypeEnum = convert_enum_to_graphene_enum(
Expand Down Expand Up @@ -133,7 +133,7 @@
(ScoreAnalyticalDensity.sector, AssessmentRegistrySectorTypeEnum),
(ScoreAnalyticalDensity.analysis_level_covered, AssessmentRegistryAnalysisLevelTypeEnum),
(ScoreAnalyticalDensity.figure_provided, AssessmentRegistryAnalysisFigureTypeEnum),
(SummaryFocusSubSectorIssue.focus, AssessmentRegistryFocusTypeEnum),
(SummarySubDimmensionIssue.focus, AssessmentRegistryFocusTypeEnum),
(SummaryIssue.sub_pillar, AssessmentRegistrySummarySubPillarTypeEnum),
(SummaryIssue.sub_dimmension, AssessmentRegistrySummarySubDimmensionTypeEnum),
)
Expand Down
12 changes: 6 additions & 6 deletions apps/assessment_registry/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
SummaryIssue,
Summary,
SummaryFocus,
SummarySubSectorIssue,
SummaryFocusSubSectorIssue,
SummarySubPillarIssue,
SummarySubDimmensionIssue,
)


Expand All @@ -29,19 +29,19 @@ class Meta:
model = Summary


class SummarySubSectorIssueFactory(DjangoModelFactory):
class SummarySubPillarIssueFactory(DjangoModelFactory):
class Meta:
model = SummarySubSectorIssue
model = SummarySubPillarIssue


class SummaryFocusFactory(DjangoModelFactory):
class Meta:
model = SummaryFocus


class SummaryFocusSubSectorIssueFactory(DjangoModelFactory):
class SummarySubDimmensionIssueFactory(DjangoModelFactory):
class Meta:
model = SummaryFocusSubSectorIssue
model = SummarySubDimmensionIssue


class QuestionFactory(DjangoModelFactory):
Expand Down
44 changes: 44 additions & 0 deletions apps/assessment_registry/migrations/0017_auto_20230803_1253.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 3.2.17 on 2023-08-03 12:53

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('assessment_registry', '0016_alter_assessmentregistry_protection_info_mgmts'),
]

operations = [
migrations.CreateModel(
name='SummarySubDimmensionIssue',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('modified_at', models.DateTimeField(auto_now=True)),
('client_id', models.CharField(blank=True, default=None, max_length=128, null=True, unique=True)),
('focus', models.IntegerField(choices=[(0, 'Food Security'), (1, 'Heath'), (2, 'Shelter'), (3, 'Wash'), (4, 'Protection'), (5, 'Nutrition'), (6, 'Livelihood'), (7, 'Education'), (8, 'Logistics'), (9, 'Inter/Cross Sector')])),
('text', models.TextField(blank=True)),
('order', models.IntegerField(blank=True, null=True)),
('lead_preview_text_ref', models.JSONField(blank=True, default=None, null=True)),
('assessment_registry', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='summary_focus_subsector_issue_ary', to='assessment_registry.assessmentregistry')),
('created_by', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='summarysubdimmensionissue_created', to=settings.AUTH_USER_MODEL)),
('modified_by', models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='summarysubdimmensionissue_modified', to=settings.AUTH_USER_MODEL)),
('summary_issue', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='summary_focus_subsector_issue', to='assessment_registry.summaryissue')),
],
options={
'ordering': ['-created_at'],
'abstract': False,
},
),
migrations.RemoveField(
model_name='scoreanalyticaldensity',
name='figure_provided',
),
migrations.DeleteModel(
name='SummaryFocusSubSectorIssue',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.17 on 2023-08-03 12:58

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('assessment_registry', '0017_auto_20230803_1253'),
]

operations = [
migrations.AddField(
model_name='scoreanalyticaldensity',
name='figure_provided',
field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(choices=[(0, 'Total population in the assessed areas'), (1, 'Total population exposed to the shock/event'), (2, 'Total populaiton affected/living in the affected area'), (3, 'Total population facing humanitarian access constraints'), (4, 'Total populaiton in need'), (5, 'Total population in critical need'), (6, 'Total population in severe need'), (7, 'Total population in moderate need'), (9, 'Total population at risk/vulnerable'), (10, 'Total population reached by assistance')]), default=list, size=None),
),
]
2 changes: 1 addition & 1 deletion apps/assessment_registry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class SubDimmension(models.IntegerChoices):
full_label = models.CharField(max_length=220, blank=True)


class SummaryFocusSubSectorIssue(UserResource):
class SummarySubDimmensionIssue(UserResource):
assessment_registry = models.ForeignKey(
AssessmentRegistry,
on_delete=models.CASCADE,
Expand Down
6 changes: 3 additions & 3 deletions apps/assessment_registry/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SummarySubPillarIssue,
SummaryIssue,
SummaryFocus,
SummaryFocusSubSectorIssue,
SummarySubDimmensionIssue,
ScoreRating,
ScoreAnalyticalDensity,
Question,
Expand Down Expand Up @@ -324,7 +324,7 @@ class SummaryFocusSubDimmensionIssueType(DjangoObjectType, UserResourceMixin):
focus_display = graphene.String(required=False)

class Meta:
model = SummaryFocusSubSectorIssue
model = SummarySubDimmensionIssue


class AssessmentRegistryType(
Expand Down Expand Up @@ -419,7 +419,7 @@ def resolve_summary_dimmension_meta(root, info, **kwargs):

@staticmethod
def resolve_summary_sub_dimmension_issue(root, info, **kwargs):
return SummaryFocusSubSectorIssue.objects.filter(assessment_registry=root)
return SummarySubDimmensionIssue.objects.filter(assessment_registry=root)


class AssessmentRegistryListType(CustomDjangoListObjectType):
Expand Down
46 changes: 32 additions & 14 deletions apps/assessment_registry/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers

from user_resource.serializers import UserResourceSerializer
from deep.serializers import ProjectPropertySerializerMixin, TempClientIdMixin
from deep.serializers import ProjectPropertySerializerMixin, TempClientIdMixin, IntegerIDField

from .models import (
AssessmentRegistry,
Expand All @@ -11,26 +11,30 @@
Summary,
SummarySubPillarIssue,
SummaryFocus,
SummaryFocusSubSectorIssue,
SummarySubDimmensionIssue,
ScoreRating,
ScoreAnalyticalDensity,
Answer,
)


class MethodologyAttributeSerializer(TempClientIdMixin, serializers.ModelSerializer):
id = IntegerIDField(required=False)

class Meta:
model = MethodologyAttribute
fields = (
"client_id", "data_collection_technique", "sampling_approach", "sampling_size",
"id", "client_id", "data_collection_technique", "sampling_approach", "sampling_size",
"proximity", "unit_of_analysis", "unit_of_reporting",
)


class AdditionalDocumentSerializer(TempClientIdMixin, UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = AdditionalDocument
fields = ("client_id", "document_type", "file", "external_link",)
fields = ("id", "client_id", "document_type", "file", "external_link",)


class IssueSerializer(UserResourceSerializer):
Expand All @@ -55,54 +59,68 @@ def validate(self, data):


class SummarySubPillarIssueSerializer(UserResourceSerializer, TempClientIdMixin):
id = IntegerIDField(required=False)

class Meta:
model = SummarySubPillarIssue
fields = ("summary_issue", "text", "order", "lead_preview_text_ref")
fields = ("id", "summary_issue", "text", "order", "lead_preview_text_ref")


class SummaryMetaSerializer(UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = Summary
fields = (
"total_people_assessed", "total_dead", "total_injured", "total_missing",
"id", "total_people_assessed", "total_dead", "total_injured", "total_missing",
"total_people_facing_hum_access_cons", "percentage_of_people_facing_hum_access_cons",
)


class SummaryFocusMetaSerializer(UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = SummaryFocus
fields = (
"percentage_of_people_affected", "total_people_affected", "percentage_of_moderate",
"id", "percentage_of_people_affected", "total_people_affected", "percentage_of_moderate",
"percentage_of_severe", "percentage_of_critical", "percentage_in_need", "total_moderate",
"total_severe", "total_critical", "total_in_need", "total_pop_assessed", "total_not_affected",
"total_affected", "total_people_in_need", "total_people_moderately_in_need",
"total_people_severly_in_need", "total_people_critically_in_need",
)


class SummaryFocusIssueSerializer(UserResourceSerializer):
class SummarySubDimmensionSerializer(UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = SummaryFocusSubSectorIssue
fields = ("summary_issue", "focus", "text", "order", "lead_preview_text_ref",)
model = SummarySubDimmensionIssue
fields = ("id", "summary_issue", "focus", "text", "order", "lead_preview_text_ref",)


class ScoreRatingSerializer(UserResourceSerializer, TempClientIdMixin):
id = IntegerIDField(required=False)

class Meta:
model = ScoreRating
fields = ("client_id", "score_type", "rating", "reason",)
fields = ("id", "client_id", "score_type", "rating", "reason",)


class ScoreAnalyticalDensitySerializer(UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = ScoreAnalyticalDensity
fields = ("client_id", "sector", "analysis_level_covered", "figure_provided",)
fields = ("id", "client_id", "sector", "analysis_level_covered", "figure_provided",)


class CNAAnswerSerializer(TempClientIdMixin, UserResourceSerializer):
id = IntegerIDField(required=False)

class Meta:
model = Answer
fields = ('client_id', 'question', 'answer')
fields = ("id", 'client_id', 'question', 'answer')


class AssessmentRegistrySerializer(UserResourceSerializer, ProjectPropertySerializerMixin):
Expand Down Expand Up @@ -131,7 +149,7 @@ class AssessmentRegistrySerializer(UserResourceSerializer, ProjectPropertySerial
summary_dimmension_meta = SummaryFocusMetaSerializer(
source='summary_focus', many=True, required=False
)
summary_sub_dimmension_issue = SummaryFocusIssueSerializer(
summary_sub_dimmension_issue = SummarySubDimmensionSerializer(
source="summary_focus_subsector_issue_ary", many=True, required=False
)

Expand Down
Loading

0 comments on commit f5df4f6

Please sign in to comment.