From 20e77fd5c391d38a44ae83f445833008e8e4fa68 Mon Sep 17 00:00:00 2001 From: George Helman Date: Sun, 28 Jul 2024 02:21:15 -0400 Subject: [PATCH] Change petition titles to new AOC format --- dear_petition/petition/constants.py | 7 +++++++ dear_petition/petition/tests/test_utils.py | 10 ++++++++++ dear_petition/petition/utils.py | 11 ++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/dear_petition/petition/constants.py b/dear_petition/petition/constants.py index 698fc521..e56411f2 100644 --- a/dear_petition/petition/constants.py +++ b/dear_petition/petition/constants.py @@ -78,6 +78,13 @@ ADULT_FELONIES, ADULT_MISDEMEANORS, ) +STATUTES = { + DISMISSED: "146(a)", + NOT_GUILTY: "146(a2)", + UNDERAGED_CONVICTIONS: "145.8A", + ADULT_FELONIES: "145.5F", + ADULT_MISDEMEANORS: "145.5M", +} SEVERITIES = Choices( ("TRAFFIC", "Traffic"), diff --git a/dear_petition/petition/tests/test_utils.py b/dear_petition/petition/tests/test_utils.py index f9cac2f9..8589c01a 100644 --- a/dear_petition/petition/tests/test_utils.py +++ b/dear_petition/petition/tests/test_utils.py @@ -1,4 +1,5 @@ import pytz +import pytest from django.utils.timezone import make_aware, utc from datetime import datetime, date @@ -6,6 +7,8 @@ from ..constants import DATETIME_FORMAT +pytestmark = pytest.mark.django_db + def test_dt_obj_to_date(settings): """Should receive only datetime objects to be converted into dates @@ -114,3 +117,10 @@ def test_get_truncation_point_of_short_text_by_pixel_size(): text = "Lorem ipsum" truncation_point = pu.get_truncation_point_of_text_by_pixel_size(text, 20000) assert truncation_point == len(text) + + +def test_get_petition_filename(petition): + case_number = "12345" + date = "2020-01-01" + petitioner_name = "Test" + assert pu.get_petition_filename(petitioner_name, petition, 'pdf') == '07-28-2024 DURHAM DC 146(a) Test.pdf' \ No newline at end of file diff --git a/dear_petition/petition/utils.py b/dear_petition/petition/utils.py index 8dec4625..6bbfa111 100644 --- a/dear_petition/petition/utils.py +++ b/dear_petition/petition/utils.py @@ -6,7 +6,7 @@ from django.utils import timezone from django.db.models import IntegerField, Case, When, Value from django.db.models.functions import Cast, Substr, Concat -from .constants import DATE_FORMAT +from .constants import DATE_FORMAT, STATUTES from PIL import ImageFont import dateutil.parser @@ -84,12 +84,9 @@ def remove_prefix(text, prefix): def get_petition_filename(petitioner_name, petition, extension, addendum_document=None): - form_type = ( - f"{petition.form_type} {addendum_document.form_type}" - if addendum_document is not None - else petition.form_type - ) - return f"{petitioner_name} - {form_type} - {petition.jurisdiction} {petition.county}.{extension}" + date_generated = petition.created.date().strftime("%m-%d-%Y") + statute = STATUTES.get(petition.form_type) + return f"{date_generated} {petition.county} {petition.jurisdiction}C {statute} {petitioner_name}.{extension}" def split_first_and_last_name(name):