Skip to content

Commit 948d500

Browse files
committed
Refactor code for improved readability and consistency in models and services
1 parent 6312621 commit 948d500

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

policylens/apps/claims/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __str__(self) -> str:
9696
return f"Claim:{self.pk} {self.status}"
9797

9898

99-
def claim_document_upload_to(instance: "ClaimDocument", filename: str) -> str:
99+
def claim_document_upload_to(instance: ClaimDocument, filename: str) -> str:
100100
"""Return a deterministic upload path for claim documents."""
101101
# Avoid embedding the original filename in the directory structure.
102102
return f"claim_docs/claim_{instance.claim_id}/{filename}"

policylens/apps/claims/services.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class DomainRuleViolation(Exception):
3030
"""
3131

3232

33-
def append_audit_event(*, claim: Claim, event_type: str, actor: str, payload: dict[str, Any]) -> AuditEvent:
33+
def append_audit_event(
34+
*, claim: Claim, event_type: str, actor: str, payload: dict[str, Any]
35+
) -> AuditEvent:
3436
"""Append an audit event for a claim."""
3537
return AuditEvent.objects.create(
3638
claim=claim,
@@ -75,7 +77,9 @@ def create_claim(
7577
def _assert_claim_not_decided(*, claim: Claim) -> None:
7678
"""Prevent mutations that should not happen after a final decision."""
7779
if claim.status == Claim.Status.DECIDED:
78-
raise DomainRuleViolation("Claim is already decided. No further workflow actions are allowed.")
80+
raise DomainRuleViolation(
81+
"Claim is already decided. No further workflow actions are allowed."
82+
)
7983

8084

8185
@transaction.atomic
@@ -120,7 +124,11 @@ def add_note(*, claim: Claim, body: str, actor: str) -> InternalNote:
120124
if not body or not body.strip():
121125
raise DomainRuleViolation("Note body is required.")
122126

123-
note = InternalNote.objects.create(claim=claim, body=body.strip(), created_by=actor)
127+
note = InternalNote.objects.create(
128+
claim=claim,
129+
body=body.strip(),
130+
created_by=actor,
131+
)
124132

125133
append_audit_event(
126134
claim=claim,

policylens/config/settings.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@
2525

2626
SECRET_KEY = env("DJANGO_SECRET_KEY")
2727
if not SECRET_KEY:
28-
raise RuntimeError(
29-
"DJANGO_SECRET_KEY is required. Set it in .env "
30-
"or environment variables."
31-
)
28+
raise RuntimeError("DJANGO_SECRET_KEY is required. Set it in .env or environment variables.")
3229

3330
DEBUG = env("DJANGO_DEBUG")
3431

35-
ALLOWED_HOSTS = [h.strip()
36-
for h in env("DJANGO_ALLOWED_HOSTS").split(",") if h.strip()]
32+
ALLOWED_HOSTS = [h.strip() for h in env("DJANGO_ALLOWED_HOSTS").split(",") if h.strip()]
3733

3834
INSTALLED_APPS = [
3935
"django.contrib.admin",
@@ -86,30 +82,10 @@
8682
DATABASES["default"]["CONN_MAX_AGE"] = 60
8783

8884
AUTH_PASSWORD_VALIDATORS = [
89-
{
90-
"NAME": (
91-
"django.contrib.auth.password_validation."
92-
"UserAttributeSimilarityValidator"
93-
),
94-
},
95-
{
96-
"NAME": (
97-
"django.contrib.auth.password_validation."
98-
"MinimumLengthValidator"
99-
),
100-
},
101-
{
102-
"NAME": (
103-
"django.contrib.auth.password_validation."
104-
"CommonPasswordValidator"
105-
),
106-
},
107-
{
108-
"NAME": (
109-
"django.contrib.auth.password_validation."
110-
"NumericPasswordValidator"
111-
),
112-
},
85+
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
86+
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
87+
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
88+
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
11389
]
11490

11591
LANGUAGE_CODE = "en-gb"

0 commit comments

Comments
 (0)