Skip to content

Commit

Permalink
Merge pull request #2399 from IFRCGo/project/dref-imminent
Browse files Browse the repository at this point in the history
Project: New Dref Imminent workflow
  • Loading branch information
szabozoltan69 authored Feb 5, 2025
2 parents c650ac7 + 19a8263 commit cf0a4f7
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 5 deletions.
7 changes: 7 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,8 @@ class HistoricalDisasterSerializer(serializers.Serializer):

class ExportSerializer(serializers.ModelSerializer):
status_display = serializers.CharField(source="get_status_display", read_only=True)
# NOTE: is_pga is used to determine if the export contains PGA or not
is_pga = serializers.BooleanField(default=False, required=False, write_only=True)

class Meta:
model = Export
Expand Down Expand Up @@ -2431,6 +2433,11 @@ def create(self, validated_data):
validated_data["url"] = f"https://{settings.FRONTEND_URL}/countries/{country_id}/{export_type}/{export_id}/export/"
else:
validated_data["url"] = f"https://{settings.FRONTEND_URL}/{export_type}/{export_id}/export/"

# Adding is_pga to the url
is_pga = validated_data.pop("is_pga")
if is_pga:
validated_data["url"] += "?is_pga=true"
validated_data["requested_by"] = user
export = super().create(validated_data)
if export.url:
Expand Down
7 changes: 7 additions & 0 deletions dref/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
IdentifiedNeed,
NationalSocietyAction,
PlannedIntervention,
ProposedAction,
RiskSecurity,
SourceInformation,
)
Expand Down Expand Up @@ -86,6 +87,7 @@ class DrefAdmin(CompareVersionAdmin, TranslationAdmin, admin.ModelAdmin):
"needs_identified",
"planned_interventions",
"risk_security",
"proposed_action",
)

def get_queryset(self, request):
Expand Down Expand Up @@ -216,3 +218,8 @@ def get_queryset(self, request):
"dref__needs_identified",
)
)


@admin.register(ProposedAction)
class ProposedActionAdmin(ReadOnlyMixin, admin.ModelAdmin):
search_fields = ["action"]
1 change: 1 addition & 0 deletions dref/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
"dref_onset_type": models.Dref.OnsetType,
"dref_disaster_category": models.Dref.DisasterCategory,
"dref_status": models.Dref.Status,
"proposed_action": models.ProposedAction.Action,
}
109 changes: 109 additions & 0 deletions dref/migrations/0076_dref_addressed_humanitarian_impacts_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Generated by Django 4.2.16 on 2025-01-22 06:19

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


class Migration(migrations.Migration):

dependencies = [
("deployments", "0090_sectortag_title_ar_sectortag_title_en_and_more"),
("dref", "0075_alter_dref_budget_file_preview_alter_dreffile_file_and_more"),
]

operations = [
migrations.AddField(
model_name="dref",
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="dref",
name="contingency_plans_supporting_document",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="dref_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.PositiveIntegerField(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="dref_scenario_supporting_document",
to="dref.dreffile",
verbose_name="Scenario Analysis Supporting Document",
),
),
migrations.AddField(
model_name="dref",
name="sub_total",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="Sub total"),
),
migrations.AddField(
model_name="dref",
name="surge_deployment_cost",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="Surge Deployment Cost"),
),
migrations.AddField(
model_name="dref",
name="total",
field=models.PositiveIntegerField(blank=True, null=True, verbose_name="Total"),
),
migrations.CreateModel(
name="ProposedAction",
fields=[
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
(
"proposed_type",
models.PositiveIntegerField(
choices=[(1, "Early Actions"), (2, "Early Response")], verbose_name="dref proposed action"
),
),
("budget", models.PositiveIntegerField(blank=True, null=True, verbose_name="Purpose Action Budgets")),
("activity", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="deployments.sector")),
],
),
migrations.AddField(
model_name="dref",
name="proposed_action",
field=models.ManyToManyField(blank=True, to="dref.proposedaction", verbose_name="Proposed Action"),
),
]
57 changes: 57 additions & 0 deletions dref/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pdf2image import convert_from_bytes

from api.models import Country, DisasterType, District, FieldReport
from deployments.models import Sector
from main.fields import SecureFileField


Expand Down Expand Up @@ -210,6 +211,22 @@ class SourceInformation(models.Model):
source_link = models.CharField(verbose_name=_("Source Link"), null=True, blank=True, max_length=255)


class ProposedAction(models.Model):
class Action(models.IntegerChoices):
EARLY_ACTION = 1, _("Early Actions")
EARLY_RESPONSE = 2, _("Early Response")

proposed_type = models.PositiveIntegerField(
choices=Action.choices,
verbose_name=_("dref proposed action"),
)
activity = models.ForeignKey(Sector, on_delete=models.CASCADE)
budget = models.PositiveIntegerField(verbose_name=_("Purpose Action Budgets"), blank=True, null=True)

def __str__(self) -> str:
return f"{self.get_proposed_type_display()}-{self.budget}"


@reversion.register()
class Dref(models.Model):
class DrefType(models.IntegerChoices):
Expand Down Expand Up @@ -589,6 +606,46 @@ class Status(models.IntegerChoices):
__budget_file_id = None
is_active = models.BooleanField(verbose_name=_("Is Active"), null=True, blank=True)
source_information = models.ManyToManyField(SourceInformation, blank=True, verbose_name=_("Source Information"))
proposed_action = models.ManyToManyField(ProposedAction, verbose_name=_("Proposed Action"), blank=True)
sub_total = models.PositiveIntegerField(verbose_name=_("Sub total"), blank=True, null=True)
surge_deployment_cost = models.PositiveIntegerField(verbose_name=_("Surge Deployment Cost"), null=True, blank=True)
indirect_cost = models.PositiveIntegerField(verbose_name=_("Indirect Cost"), null=True, blank=True)
total = models.PositiveIntegerField(verbose_name=_("Total"), null=True, blank=True)
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="dref_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="dref_contingency_plans_supporting_document",
)
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,
)

class Meta:
verbose_name = _("dref")
Expand Down
Loading

0 comments on commit cf0a4f7

Please sign in to comment.