Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning message citizenship #677

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions programs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class WarningMessageAdmin(ModelAdmin):
filter_horizontal = (
"programs",
"counties",
"legal_statuses",
)

def get_str(self, obj):
Expand Down
18 changes: 18 additions & 0 deletions programs/migrations/0100_warningmessage_legal_statuses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.15 on 2024-12-19 22:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("programs", "0099_merge_20241108_1521"),
]

operations = [
migrations.AddField(
model_name="warningmessage",
name="legal_statuses",
field=models.ManyToManyField(blank=True, related_name="warning_messages", to="programs.legalstatus"),
),
]
1 change: 1 addition & 0 deletions programs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ class WarningMessage(models.Model):
external_name = models.CharField(max_length=120, blank=True, null=True, unique=True)
calculator = models.CharField(max_length=120, blank=False, null=False)
counties = models.ManyToManyField(County, related_name="warning_messages", blank=True)
legal_statuses = models.ManyToManyField(LegalStatus, related_name="warning_messages", blank=True)

message = models.ForeignKey(
Translation, related_name="warning_messages", blank=False, null=False, on_delete=models.PROTECT
Expand Down
19 changes: 16 additions & 3 deletions screener/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, timedelta, date
from datetime import datetime, timedelta
from programs.models import WarningMessage
from screener.models import Screen, HouseholdMember, IncomeStream, Expense, Message, Insurance, WhiteLabel
from authentication.serializers import UserOffersSerializer
from rest_framework import serializers
from translations.serializers import TranslationSerializer
from translations.serializers import ModelTranslationSerializer, TranslationSerializer
from validations.serializers import ValidationSerializer


Expand Down Expand Up @@ -257,6 +258,18 @@ class NavigatorSerializer(serializers.Serializer):
languages = serializers.ListField()


class WarningMessageSerializer(serializers.ModelSerializer):
message = ModelTranslationSerializer()
legal_statuses = serializers.SerializerMethodField()

class Meta:
model = WarningMessage
fields = ("message", "legal_statuses")

def get_legal_statuses(self, obj: WarningMessage):
return [m.status for m in obj.legal_statuses.all()]


class EligibilitySerializer(serializers.Serializer):
description_short = TranslationSerializer()
name = TranslationSerializer()
Expand All @@ -281,7 +294,7 @@ class EligibilitySerializer(serializers.Serializer):
documents = TranslationSerializer(many=True)
multiple_tax_units = serializers.BooleanField()
estimated_value_override = TranslationSerializer()
warning_messages = TranslationSerializer(many=True)
warning_messages = WarningMessageSerializer(many=True)

class Meta:
fields = "__all__"
Expand Down
6 changes: 4 additions & 2 deletions screener/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
EligibilitySerializer,
MessageSerializer,
ResultsSerializer,
WarningMessageSerializer,
)
from programs.programs.policyengine.policy_engine import calc_pe_eligibility
from programs.util import DependencyError, Dependencies
Expand Down Expand Up @@ -214,6 +215,7 @@ def eligibility_results(screen: Screen, batch=False):
*translations_prefetch_name("documents__", Document.objects.translated_fields),
"warning_messages",
"warning_messages__counties",
"warning_messages__legal_statuses",
*translations_prefetch_name("warning_messages__", WarningMessage.objects.translated_fields),
"translation_overrides",
"translation_overrides__counties",
Expand Down Expand Up @@ -340,7 +342,7 @@ def sort_first(program):
)

if warning_calculator.calc():
warnings.append(warning)
warnings.append(WarningMessageSerializer(warning).data)

if not skip and program.active:
legal_status = [status.status for status in program.legal_status_required.all()]
Expand Down Expand Up @@ -386,7 +388,7 @@ def sort_first(program):
"new": new,
"low_confidence": program.low_confidence,
"documents": [serialized_document(document) for document in program.documents.all()],
"warning_messages": [default_message(w.message) for w in warnings],
"warning_messages": warnings,
}
)

Expand Down
Loading