cityofaustin / knackpy

A Python client for interacting with Knack applications
https://cityofaustin.github.io/knackpy/docs/user-guide/
Other
39 stars 18 forks source link

Use Knack's default formatting for equation fields #110

Closed johnclary closed 2 years ago

johnclary commented 2 years ago

Fixes #109.

Consider this record, in which field_1 is a date equation which renders days. field_2 is a numeric equation which renders a decimal result as an integer:

record = {
  # date equation field
  "field_1": 11,  # days
  "field_1_raw": 923880,  # seconds
  # numeric equation field
  "field_2": 53,
  "field_2_raw": 52.5
}

According to previous behavior, formatting this record would look like this:

formatted_record = record.format(keys=False)

# formatted record
{
  "field_1": 923880,
  "field_2":  52.5
}

This is because we use knackpy's default formatter for the equation field type, which simply returns the record's "raw" value. That's not ideal, because the user presumably expects the formatted value (i.e., the value Knack renders in the UI).

In these cases, we can override Knackpy's default formatting behavior by adjusting the field settings, here.

FIELD_SETTINGS = {
   # ...
    "equation": {"use_knack_format": True}
}

Here's where use_knack_format is applied in the Record class.

This is reasonable expected behavior from the knackpy API—so lets do it. This is definitely a breaking change. Bumped to v1.1.0.

johnclary commented 2 years ago

This has been deployed to the knackpy-dev package

johnclary commented 2 years ago

Working on adding a test real quick...

johnclary commented 2 years ago

I added a test and am merging. The developer docs for the test suite are pretty good, btw.

chiaberry commented 2 years ago

I saw that this check failed: https://github.com/cityofaustin/knackpy/runs/6031309455?check_suite_focus=true

Does it need to be retriggered in some way?

johnclary commented 2 years ago

thanks @chiaberry — a faulty CI that tried to republish v.1.1.0 to PyPI.

I updated the Github action to only publish the dev package to PyPI on push. That means that any branch merged to dev should include a version bump, but PRs against dev won't push. I think that's the best way.

I pushed that action change to dev. I'm going to push a version bump to the dev branch to v1.1.1, which should publish a new version of knackpy-dev and bring everything back in sync.

johnclary commented 2 years ago

Success.