Skip to content
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

Allow the Value() class to take a dynamic string directly and set it on the form output? #29

Open
krowvin opened this issue May 30, 2024 · 1 comment

Comments

@krowvin
Copy link
Collaborator

krowvin commented May 30, 2024

You are not able to use variables without setting the variable type to Value().

If for example a user wanted to dynamically color a cell they would need to be able to set "red" or "green" to the variables in the form.

One way around this that @DanielTOsborne showed me was to use .picture = "mystring" - and this works but in my opinion it is not intuitive.

myVar = Value("mystring")

and

myVar = "mystring"

I would recommend something like this, but I can see how the latter would be difficult given when the locals() are loaded in (before the form).

What ended up working per Daniels suggestion was

myVar = Value()
myVar.picture = "mystring"

Use Case

#FORM
<style>
.red {
    background: red;
 }
</style>
<span class="%projectStatus"></span>
#ENDFORM
#DEF
projectStatus = Value()
projectStatus.picture = "red"
#ENDDEF
@DanielTOsborne
Copy link
Collaborator

I'm worried about unintended side affects if we did something like this automatically.

However, what might be the better option is to allow any python type to be referenced in the FORM section.
This could be done by checking the type (or look for pop attribute) at report.py#L76, and if it's not Value, then just call str (as if it were just a scalar).

This would make it more intuitive to use, and eliminate a potential source of confusion with Value's behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants