-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
caluma/caluma_form/structure.py
Outdated
if self._main_form is None: | ||
if hasattr(self.document.family, "work_item") and hasattr( | ||
self.document.family.work_item.case.family, "document" | ||
): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 done
There was a problem hiding this 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
caluma/caluma_form/structure.py
Outdated
@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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.
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