Skip to content

feat(jexl): add main_case_form to info object #2204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024
Merged

feat(jexl): add main_case_form to info object #2204

merged 1 commit into from
Apr 25, 2024

Conversation

czosel
Copy link
Contributor

@czosel czosel commented Apr 24, 2024

This is convenient when you'd like to write a JEXL expression in a task form attached to some work item, that depends on the case's main documents' form.

Related PR in ember-caluma: projectcaluma/ember-caluma#2703

Once we merge this, we should spend a minute to update the caluma docs: https://caluma.gitbook.io/caluma-docs/forms/validation#variables-available-for-evaluation

if self._main_form is None:
if hasattr(self.document.family, "work_item") and hasattr(
self.document.family.work_item.case.family, "document"
):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's probably a cleaner way to do this in python?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's operator.attrgetter, but it doesn't make things much shorter.

Since the default/fallback is to just have *no value", you could just as well fetch the whole attribute chain and just try/except around it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

Copy link
Contributor

@winged winged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, just some minor issues found

Comment on lines 149 to 158
@property
def main_form(self):
if self._main_form is None:
if hasattr(self.document.family, "work_item") and hasattr(
self.document.family.work_item.case.family, "document"
):
self._main_form = (
self.document.family.work_item.case.family.document.form.slug
)
return self._main_form
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things: One, naming: I think it might be confusing, as the "main form" could also be the the main form of the current document, for example if you're in a row-doc or similar. Suggestion: "main_case_form" or something similar maybe?

Second: If for some reason the inner if does not find the main form, it will not cache the result in self._main_form and try to do the whole resolution-chain again, possibly triggering quite a few DB queries. I'd suggest caching that case as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the naming and caching 👍

Copy link
Contributor

@winged winged left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@winged winged enabled auto-merge April 25, 2024 09:16
@czosel czosel changed the title feat(jexl): add main_form to info object feat(jexl): add main_case_form to info object Apr 25, 2024
This is convenient when you'd like to write a JEXL expression in a task
form attached to some work item, that depends on the main case's form.
@winged winged merged commit 5d9dc6d into main Apr 25, 2024
24 checks passed
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.

2 participants