Skip to content

Commit

Permalink
checking errors with Jeremy
Browse files Browse the repository at this point in the history
  • Loading branch information
Mudiwa Matanda authored and Mudiwa Matanda committed Feb 6, 2024
1 parent 30c219b commit a56210f
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,7 @@ def clean(self, value):
errors["example_values"] = ValidationError(
"Example values cannot contain commas"
)
if num_vars_in_msg > 0:
num_example_values = len(example_values)
if num_vars_in_msg != num_example_values:
errors["example_values"] = ValidationError(
f"The number of example values provided ({num_example_values}) "
f"does not match the number of variables used in the template ({num_vars_in_msg})",
)


if (result["image"] or result["document"] or result["media"]) and len(
result["message"]
Expand Down Expand Up @@ -903,14 +897,38 @@ def clean(self):
0: StreamBlockValidationError(
{
"message": ValidationError(
f'Variables must be sequential, starting with "{{1}}". Your first variable was "{actual_digit_variables}"'
f'Variables must be sequential, starting with "{{1}}". You have "{actual_digit_variables}"'
)
}
)
}
)
)

example_values = self.whatsapp_body.raw_data[0]["value"].get(
"example_values", []
)
example_values = [v["value"] for v in example_values]

if len(vars_in_msg) > 0:
num_example_values = len(example_values)
if len(vars_in_msg) != num_example_values:
errors.setdefault("whatsapp_body", []).append(
StreamBlockValidationError(
{
0: StreamBlockValidationError(
{
"example_values": ValidationError(
f"The number of example values provided ({num_example_values}) "
f"does not match the number of variables used in the template ({vars_in_msg})",
)
}
)
}
)
)


if errors:
raise ValidationError(errors)

Expand Down

0 comments on commit a56210f

Please sign in to comment.