Skip to content
New issue

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

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

Already on GitHub? # to your account

Conditional questions #161

Closed
yajo opened this issue Mar 13, 2020 · 3 comments · Fixed by #260
Closed

Conditional questions #161

yajo opened this issue Mar 13, 2020 · 3 comments · Fixed by #260
Milestone

Comments

@yajo
Copy link
Member

yajo commented Mar 13, 2020

I guess this issue depends on #90 and it would let us declare questions to be conditional:

using_smtp:
  type: bool
  default: no

smtp_host:
  type: str
  when: '[[ using_smtp ]]'
@pawamoy
Copy link
Contributor

pawamoy commented Apr 20, 2020

If the conditions are only based on boolean values, do we really need #90, i.e. templating? The when is a special key, its value could simply be the name of the boolean field to check.

Besides, when rendering [[ using_smtp ]], you'd get a string (rendering a template always gives a string), so we would need to cast "True" or "False" back to a boolean? What if the user writes something a bit more complex and we cannot cast it back?

So instead, I suggest

using_smtp:
  type: bool
  default: no

smtp_host:
  type: str
  when: using_smtp

It would be easier to implement as a first step, and still allow to enhance the behavior later with templating if needed. WDYT 🙂 ?

@yajo
Copy link
Member Author

yajo commented Apr 22, 2020

Well, that's half true.

Recent Jinja versions have the NativeEnvironment, which returns the native object type if possible: https://jinja.palletsprojects.com/en/2.11.x/nativetypes/

If we do this initial step and leave the fully templated when for a future improvement, when it comes it wouldn't be easy to be made backwards-compatible with this one, because with when: using_smtp you assume "using_smtp" is the name of a bool answer, but with that future system it would be just a "using_smtp" string, and the bool answer would be detected with when: "[[ using_smtp ]]".

Since #90 is in the roadmap too, I still think we should still implement #90 before. After it's done, this issue would be simpler and we'd still have full templating possibilities with not much more effort.

@pawamoy
Copy link
Contributor

pawamoy commented Apr 22, 2020

Didn't know about this NativeEnvironment, nice!

Then this totally makes sense as it will be possible to have conditionals like "[[ using_smtp or using_imap ]]", which would be much more powerful.

@yajo yajo modified the milestones: v5.0.0, v6.0.0 Aug 13, 2020
@yajo yajo linked a pull request Oct 12, 2020 that will close this issue
6 tasks
@yajo yajo closed this as completed in #260 Oct 12, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants