Skip to content

Commit

Permalink
Add new fields and supporting files in dref application
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed Jan 8, 2025
1 parent 77d0b87 commit 924a7be
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.17 on 2025-01-03 04:42
# Generated by Django 4.2.16 on 2025-01-08 06:35

import django.db.models.deletion
from django.db import migrations, models
Expand All @@ -12,11 +12,56 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AddField(
model_name="dref",
name="contingency_plans_supporting_document",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="contingency_plans_supporting_document",
to="dref.dreffile",
verbose_name="Contingency Plans Supporting Document",
),
),
migrations.AddField(
model_name="dref",
name="hazard_date_and_location",
field=models.TextField(
blank=True,
help_text="When and where is the hazard expected to happen?",
max_length=255,
null=True,
verbose_name="Hazard Date and Location",
),
),
migrations.AddField(
model_name="dref",
name="hazard_vulnerabilities_and_risks",
field=models.TextField(
blank=True,
help_text="Explain the underlying vulnerabilities and risks the hazard poses for at-risk communities?",
null=True,
verbose_name="Hazard Vulnerabilities and Risks",
),
),
migrations.AddField(
model_name="dref",
name="indirect_cost",
field=models.IntegerField(blank=True, null=True, verbose_name="Indirect Cost"),
),
migrations.AddField(
model_name="dref",
name="scenario_analysis_supporting_document",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="scenario_supporting_document",
to="dref.dreffile",
verbose_name="Scenario Analysis Supporting Document",
),
),
migrations.AddField(
model_name="dref",
name="sub_total",
Expand Down Expand Up @@ -52,6 +97,16 @@ class Migration(migrations.Migration):
name="total",
field=models.IntegerField(blank=True, null=True, verbose_name="Total"),
),
migrations.AddField(
model_name="drefoperationalupdate",
name="addressed_humanitarian_impacts",
field=models.TextField(
blank=True,
help_text=" Which of the expected severe humanitarian impacts of the hazard are your actions addressing?",
null=True,
verbose_name="Addressed Humanitarian Impacts",
),
),
migrations.AddField(
model_name="drefoperationalupdate",
name="indirect_cost",
Expand Down Expand Up @@ -82,7 +137,7 @@ class Migration(migrations.Migration):
choices=[(1, "Early Actions"), (2, "Early Response")], verbose_name="dref proposed action"
),
),
("budget", models.PositiveIntegerField(blank=True, null=True, verbose_name="Early Action budgets")),
("budget", models.PositiveIntegerField(blank=True, null=True, verbose_name=" Purpose Action budgets")),
(
"activities",
models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to="deployments.sector"),
Expand Down
33 changes: 0 additions & 33 deletions dref/migrations/0077_alter_dref_proposed_action_and_more.py

This file was deleted.

28 changes: 0 additions & 28 deletions dref/migrations/0078_alter_dref_proposed_action_and_more.py

This file was deleted.

28 changes: 0 additions & 28 deletions dref/migrations/0079_dref_hazard_date_and_location_and_more.py

This file was deleted.

21 changes: 20 additions & 1 deletion dref/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,35 @@ class Status(models.IntegerChoices):
surge_deployment = models.IntegerField(verbose_name=_("Surge Deployment"), null=True, blank=True)
indirect_cost = models.IntegerField(verbose_name=_("Indirect Cost"), null=True, blank=True)
total = models.IntegerField(verbose_name=_("Total"), null=True, blank=True)
hazard_date_and_location = models.CharField(
hazard_date_and_location = models.TextField(
verbose_name=_("Hazard Date and Location"),
max_length=255,
help_text=_("When and where is the hazard expected to happen?"),
null=True,
blank=True,
)
hazard_vulnerabilities_and_risks = models.TextField(
verbose_name=_("Hazard Vulnerabilities and Risks"),
help_text=_("Explain the underlying vulnerabilities and risks the hazard poses for at-risk communities?"),
null=True,
blank=True,
)
scenario_analysis_supporting_document = models.ForeignKey(
"DrefFile",
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name=_("Scenario Analysis Supporting Document"),
related_name="scenario_supporting_document",
)
contingency_plans_supporting_document = models.ForeignKey(
"DrefFile",
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name=_("Contingency Plans Supporting Document"),
related_name="contingency_plans_supporting_document",
)

class Meta:
verbose_name = _("dref")
Expand Down Expand Up @@ -1062,6 +1080,7 @@ class DrefOperationalUpdate(models.Model):
total = models.IntegerField(verbose_name=_("Total"), null=True, blank=True)
addressed_humanitarian_impacts = models.TextField(
verbose_name=_("Addressed Humanitarian Impacts"),
help_text=_(" Which of the expected severe humanitarian impacts of the hazard are your actions addressing?"),
null=True,
blank=True,
)
Expand Down
88 changes: 42 additions & 46 deletions dref/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,29 @@ class DrefSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSerializer):
modified_at = serializers.DateTimeField(required=False)
dref_access_user_list = serializers.SerializerMethodField()
source_information = SourceInformationSerializer(many=True, required=False)
proposed_action = ProposedActionSerializer(many=True, required=False)
sub_total = serializers.IntegerField(required=False)
surge_deployment = serializers.IntegerField(required=False)
indirect_cost = serializers.IntegerField(required=False)
total = serializers.IntegerField(required=False)
hazard_date_and_location = serializers.CharField(required=False)
hazard_vulnerabilities_and_risks = serializers.CharField(required=False)
scenario_analysis_supporting_document_details = DrefFileSerializer(
source="scenario_analysis_supporting_document", read_only=True, required=False, allow_null=True
)
contingency_plans_supporting_document_details = DrefFileSerializer(
source="contingency_plans_supporting_document", read_only=True, required=False, allow_null=True
)

proposed_action = ProposedActionSerializer(many=True, required=True)
sub_total = serializers.IntegerField(required=True)
surge_deployment = serializers.IntegerField(required=True)
indirect_cost = serializers.IntegerField(required=True)
total = serializers.IntegerField(required=True)

class Meta:
model = Dref
read_only_fields = ("modified_by", "created_by", "budget_file_preview")
exclude = ("cover_image", "event_map", "images", "users", "anticipatory_actions", "event_text")
read_only_fields = (
"modified_by",
"created_by",
"budget_file_preview",
"anticipatory_actions",
"event_text",
)
exclude = ("cover_image", "event_map", "images", "users")

def get_dref_access_user_list(self, obj) -> List[int]:
dref_users_list = get_dref_users()
Expand Down Expand Up @@ -441,6 +452,11 @@ def validate(self, data):
raise serializers.ValidationError(
gettext("Operation timeframe can't be greater than %s for assessment_report" % self.MAX_OPERATION_TIMEFRAME)
)

proposed_actions = data.get("proposed_action", None)
proposed_budget = sum([proposed_actions["budget"] for proposed_actions in proposed_actions])
if proposed_budget != data.get("sub_total"):
raise serializers.ValidationError("Sub-total should be equal to proposed budget")
return data

def validate_images(self, images):
Expand Down Expand Up @@ -608,17 +624,21 @@ class DrefOperationalUpdateSerializer(NestedUpdateMixin, NestedCreateMixin, Mode
created_by_details = UserNameSerializer(source="created_by", read_only=True)
users_details = UserNameSerializer(source="users", many=True, read_only=True)
source_information = SourceInformationSerializer(many=True, required=False)
proposed_action = ProposedActionSerializer(many=True, required=False)
sub_total = serializers.IntegerField(required=False)
surge_deployment = serializers.IntegerField(required=False)
indirect_cost = serializers.IntegerField(required=False)
total = serializers.IntegerField(required=False)
addressed_humanitarian_impacts = serializers.CharField(required=False)

class Meta:
model = DrefOperationalUpdate
read_only_fields = ("operational_update_number", "modified_by", "created_by")
exclude = ("images", "photos", "event_map", "cover_image", "users", "anticipatory_actions", "event_text")
read_only_fields = (
"operational_update_number",
"modified_by",
"created_by",
)
exclude = (
"images",
"photos",
"event_map",
"cover_image",
"users",
)

def validate(self, data):
dref = data.get("dref")
Expand All @@ -641,14 +661,6 @@ def validate(self, data):

return data

def validate_sub_total(self, sub_total):
instance = self.get_initial()
proposed_actions = instance.get("proposed_action", None)
proposed_budget = sum([proposed_actions["budget"] for proposed_actions in proposed_actions])
if proposed_budget != sub_total:
raise serializers.ValidationError("Sub-total should be equal to proposed budget")
return sub_total

def validate_appeal_code(self, appeal_code):
if appeal_code and appeal_code != self.instance.appeal_code:
raise serializers.ValidationError("Can't edit MDR Code")
Expand Down Expand Up @@ -779,7 +791,6 @@ def create(self, validated_data):
operational_update.users.add(*dref.users.all())
operational_update.risk_security.add(*dref.risk_security.all())
operational_update.source_information.add(*dref.source_information.all())
operational_update.proposed_action.add(*dref.proposed_action.all())
else:
# get the latest dref operational update
validated_data["title"] = dref_operational_update.title
Expand Down Expand Up @@ -895,7 +906,6 @@ def create(self, validated_data):
operational_update.users.add(*dref_operational_update.users.all())
operational_update.risk_security.add(*dref_operational_update.risk_security.all())
operational_update.source_information.add(*dref_operational_update.source_information.all())
operational_update.proposed_action.add(*dref.proposed_action.all())
return operational_update

def update(self, instance, validated_data):
Expand Down Expand Up @@ -935,23 +945,19 @@ class DrefFinalReportSerializer(NestedUpdateMixin, NestedCreateMixin, ModelSeria
disaster_type_details = DisasterTypeSerializer(source="disaster_type", read_only=True)
source_information = SourceInformationSerializer(many=True, required=False)

proposed_action = ProposedActionSerializer(many=True, required=False)
sub_total = serializers.IntegerField(required=False)
surge_deployment = serializers.IntegerField(required=False)
indirect_cost = serializers.IntegerField(required=False)
total = serializers.IntegerField(required=False)

class Meta:
model = DrefFinalReport
read_only_fields = ("modified_by", "created_by", "financial_report_preview", "anticipatory_actions", "event_text")
read_only_fields = (
"modified_by",
"created_by",
"financial_report_preview",
)
exclude = (
"images",
"photos",
"event_map",
"cover_image",
"users",
"event_text",
"anticipatory_actions",
)

def validate(self, data):
Expand Down Expand Up @@ -984,14 +990,6 @@ def validate_financial_report_preview(self, financial_report_preview):
validate_file_type(financial_report_preview)
return financial_report_preview

def validate_sub_total(self, sub_total):
instance = self.get_initial()
proposed_actions = instance.get("proposed_action", None)
proposed_budget = sum([proposed_actions["budget"] for proposed_actions in proposed_actions])
if proposed_budget != sub_total:
raise serializers.ValidationError("Sub-total should be equal to proposed budget")
return sub_total

def create(self, validated_data):
# here check if there is operational update for corresponding dref
# if yes copy from the latest operational update
Expand Down Expand Up @@ -1103,7 +1101,6 @@ def create(self, validated_data):
dref_final_report.risk_security.add(*dref_operational_update.risk_security.all())
dref_final_report.users.add(*dref_operational_update.users.all())
dref_final_report.source_information.add(*dref_operational_update.source_information.all())
dref_final_report.proposed_action.add(*dref.proposed_action.all())
else:
validated_data["title"] = dref.title
validated_data["title_prefix"] = dref.title_prefix
Expand Down Expand Up @@ -1200,7 +1197,6 @@ def create(self, validated_data):
dref_final_report.users.add(*dref.users.all())
dref_final_report.national_society_actions.add(*dref.national_society_actions.all())
dref_final_report.source_information.add(*dref.source_information.all())
dref_final_report.proposed_action.add(*dref.proposed_action.all())
# also update is_final_report_created for dref
dref.is_final_report_created = True
dref.save(update_fields=["is_final_report_created"])
Expand Down

0 comments on commit 924a7be

Please sign in to comment.