Skip to content

Accept TutorCruncher Stars fields on the enquiry form - #564

Closed
tejas7777 wants to merge 2 commits into
masterfrom
stars-enquiry-field
Closed

tejas7777 wants to merge 2 commits into
masterfrom
stars-enquiry-field

Conversation

@tejas7777

@tejas7777 tejas7777 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • Enquiry form: a Stars custom field (TutorCruncher OPTIONS type decimal) is sent to the widget as field type integer, a whole-number input. TutorCruncher's own forms take whole stars too.
  • Enquiry POST: a Stars value is checked with pydantic.condecimal, using the field's min_value, max_value, max_digits and decimal_places from the OPTIONS response. A value out of range or with too many decimal places returns 400 invalid attribute data, so it is never queued for TutorCruncher to refuse later.
  • A valid value is sent to TutorCruncher as a float. submit_enquiry posts with plain json.dumps, which can't encode a Decimal.
  • Enquiry POST: "" for an optional field (a box typed in, then cleared) counts as not filled in. Text, and a dropdown with an empty option, still send "".

Why

FIELD_TYPE_LOOKUP and FIELD_VALIDATION_LOOKUP have no decimal. A Client Stars field with "Enquiry Form" ticked raises KeyError: 'decimal' on GET (_convert_field) and POST, so that branch's whole enquiry form fails. TutorCruncher's setup page allows such a field. Today no branch has one.

A Stars box typed in, then cleared, sent "" and failed the whole enquiry with "value is not a valid decimal".

How it was tested

  • New tests in test_enquiries.py:
    • GET converts a Stars field to type integer and keeps min_value / max_value.
    • POST '4' is submitted to TutorCruncher as 4.0.
    • POST 6 and POST '4.555' each return 400 with the pydantic error, and nothing is sent to TutorCruncher.
    • POST "" is submitted with no Stars value.
  • The new stars variant of the fake enquiry options copies TutorCruncher's real OPTIONS entry for a Stars field.
  • test_enquiries.py: 24 passed. flake8 and make format are clean.
  • Merges cleanly with Stars custom fields on the enquiry form #563. The empty-value validator is the same in both, byte for byte, so either can merge first.

Independent of TutorCruncher2 and of #563. Deploy any time.

🤖 Generated with Claude Code

TutorCruncher reports a Stars custom field as type "decimal", which the
enquiry form's type lookups didn't have, so a Stars field on the enquiry
form raised KeyError on GET and POST. Show it as a whole-number input and
check the value against the field's min, max and decimal places before
queueing, then send it to TutorCruncher as a float.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tcsocket/app/views/enquiry.py 91.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

The enquiry form sends "" for a box typed in then cleared. For an
optional field this now counts as not filled in, instead of failing the
whole enquiry with "value is not a valid decimal". Text and a dropdown
with an empty option still send "".

The same validator is in the Link PR (#563), byte for byte, so the two
merge cleanly in either order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tejas7777 added a commit that referenced this pull request Oct 16, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@tejas7777

Copy link
Copy Markdown
Contributor Author

Moved into #563.

@tejas7777 tejas7777 closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant